"Fossies" - the Fresh Open Source Software Archive

Member "roundup-2.0.0/share/roundup/templates/responsive/detectors/patches.py" (26 Aug 2019, 1523 Bytes) of package /linux/www/roundup-2.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "patches.py": 1.6.1_vs_2.0.0.

    1 # Auditor for patch files
    2 # Patches should be declared as text/plain (also .py files),
    3 # independent of what the browser says, and
    4 # the "patch" keyword should get set automatically.
    5 
    6 import posixpath
    7 
    8 patchtypes = ('.diff', '.patch')
    9 sourcetypes = ('.diff', '.patch', '.py')
   10 
   11 def ispatch(file, types):
   12     return posixpath.splitext(file)[1] in types
   13 
   14 def patches_text_plain(db, cl, nodeid, newvalues):
   15     if ispatch(newvalues['name'], sourcetypes):
   16         newvalues['type'] = 'text/plain'
   17 
   18 def patches_keyword(db, cl, nodeid, newvalues):
   19     # Check whether there are any new files
   20     newfiles = set(newvalues.get('files',()))
   21     if nodeid:
   22         newfiles -= set(db.bug.get(nodeid, 'files'))
   23     # Check whether any of these is a patch
   24     newpatch = False
   25     for fileid in newfiles:
   26         if ispatch(db.file.get(fileid, 'name'), patchtypes):
   27             newpatch = True
   28             break
   29     if newpatch:
   30         # Add the patch keyword if its not already there
   31         patchid = db.keyword.lookup("patch")
   32         oldkeywords = []
   33         if nodeid:
   34             oldkeywords = db.bug.get(nodeid, 'keywords')
   35             if patchid in oldkeywords:
   36                 # This is already marked as a patch
   37                 return
   38         if 'keywords' not in newvalues:
   39             newvalues['keywords'] = oldkeywords
   40         newvalues['keywords'].append(patchid)
   41 
   42 def init(db): pass
   43 #    db.file.audit('create', patches_text_plain)
   44 #    db.bug.audit('create', patches_keyword)
   45 #    db.bug.audit('set', patches_keyword)