[Blends-commit] [SCM] website branch, master, updated. 4160989ebf2c9235f345663ea4e97875ebc1fb23

Ole Streicher olebole at debian.org
Tue Mar 8 16:58:20 UTC 2016


The following commit has been merged in the master branch:
commit 4160989ebf2c9235f345663ea4e97875ebc1fb23
Author: Ole Streicher <olebole at debian.org>
Date:   Tue Mar 8 17:57:41 2016 +0100

    Fixed some indentation bugs, and more PEP8 for bugs.py

diff --git a/webtools/bugs.py b/webtools/bugs.py
index 7089a2a..7ee9167 100755
--- a/webtools/bugs.py
+++ b/webtools/bugs.py
@@ -2,15 +2,6 @@
 # Copyright 2013: Andreas Tille <tille at debian.org>
 # License: GPL
 
-#PORT=5441
-UDDPORT=5452
-PORT=UDDPORT
-DEFAULTPORT=5432
-
-SLOWQUERYREPORTLIMIT=30
-
-debug=0
-
 import codecs
 from sys import argv, stderr, exit
 import os
@@ -28,35 +19,49 @@ from genshi import Markup
 from genshi.template.eval import UndefinedError
 
 from blendstasktools import ReadConfig, RowDictionaries, CheckOrCreateOutputDir, SetFilePermissions
-from blendsmarkdown  import MarkupString
+from blendsmarkdown import MarkupString
+
+# PORT = 5441
+UDDPORT = 5452
+PORT = UDDPORT
+DEFAULTPORT = 5432
+
+SLOWQUERYREPORTLIMIT = 30
+
+debug = 0
 
 ###########################################################################################
 # Define several prepared statements to query UDD
 try:
-    conn = psycopg2.connect(host="localhost",port=PORT,user="guest",database="udd")
+    conn = psycopg2.connect(host="localhost", port=PORT,
+                            user="guest", database="udd")
 except psycopg2.OperationalError, err:
     try:
         conn = psycopg2.connect("service=udd")
-  except psycopg2.OperationalError, err:
-    # logger not known at this state: logger.warning
-    stderr.write("Service=udd seems not to be installed on this host.\tMessage: %s" % (str(err)))
+    except psycopg2.OperationalError, err:
+        # logger not known at this state: logger.warning
+        stderr.write("Service=udd seems not to be installed on this host.\tMessage: %s" % (str(err)))
     try:
-        conn = psycopg2.connect(host="localhost",port=DEFAULTPORT,user="guest",database="udd")
+        conn = psycopg2.connect(host="localhost", port=DEFAULTPORT, user="guest",
+                                database="udd")
     except psycopg2.OperationalError:
-        # Hmmm, I observed a really strange behaviour on one of my machines where connecting to
-        # localhost does not work but 127.0.0.1 works fine.  No idea why ... but this should
-        # do the trick for the moment
-        conn = psycopg2.connect(host="127.0.0.1",port=DEFAULTPORT,user="guest",database="udd")
+        # Hmmm, I observed a really strange behaviour on one of my
+        # machines where connecting to localhost does not work but
+        # 127.0.0.1 works fine.  No idea why ... but this should do
+        # the trick for the moment
+        conn = psycopg2.connect(host="127.0.0.1", port=DEFAULTPORT, user="guest",
+                                database="udd")
 
 curs = conn.cursor()
 # uddlog = open('logs/uddquery.log', 'w')
 
+
 def _execute_udd_query(query):
     try:
         t = time.time()
         curs.execute(query)
         elapsed_time = time.time() - t
-        if elapsed_time > SLOWQUERYREPORTLIMIT: # report what query took longer than SLOWQUERYREPORTLIMIT seconds
+        if elapsed_time > SLOWQUERYREPORTLIMIT:  # report what query took longer than SLOWQUERYREPORTLIMIT seconds
             print("Time: %s\nQuery: %s" % (str(elapsed_time), query))
     except psycopg2.ProgrammingError, err:
         stderr.write("Problem with query\n%s\n%s\n" % (query, str(err)))
@@ -124,7 +129,7 @@ def main():
         ORDER BY source, bu.id;
     """
     _execute_udd_query(query)
-    
+
     # What tasks are involved
     query = """PREPARE query_get_tasks (text) AS
       SELECT task, title, description, long_description FROM blends_tasks WHERE blend = $1 ORDER BY task;
@@ -138,24 +143,25 @@ def main():
     # So we build the weighted sums of bugs and define limits for the status
     # The weights below are used for suggested packages.  In case a package has
     # a stronger dependency (Depends, Recommends) the weight is multiplied by 3
-    WEIGHT = { 'critical'  : 10,
-               'grave'     : 10,
-               'serious'   : 10,
-               'important' :  5,
-               'normal'    :  3,
-               'minor'     :  1,
-               'wishlist'  :  0
+    WEIGHT = {
+        'critical'  : 10,
+        'grave'     : 10,
+        'serious'   : 10,
+        'important' : 5,
+        'normal'    : 3,
+        'minor'     : 1,
+        'wishlist'  : 0
     }
-    BAD          = 100 # if weighted bug sum >= BAD, the meta package is in a bad shape
-    # Dependent packages might have 3 or more 5 RC bugs
-    PASS         =  70 # this deserves a look - potentially two RC bugs in dependent packages
-SATISFACTORY =  50 # consider looking at this
-GOOD         =  30 # at least no RC bug in a dependent package
-VERYGOOD     =  10 # nothing burning
-EXCELLENT    =   5 # There is no real need to look at this meta package
+    BAD          = 100  # if weighted bug sum >= BAD, the meta package is in a bad shape
+                        # Dependent packages might have 3 or more 5 RC bugs
+    PASS         = 70  # this deserves a look - potentially two RC bugs in dependent packages
+    SATISFACTORY = 50  # consider looking at this
+    GOOD         = 30  # at least no RC bug in a dependent package
+    VERYGOOD     = 10  # nothing burning
+    EXCELLENT    = 5   # There is no real need to look at this meta package
 
     # initialise bugs_data dictionary for all tasks
-    _execute_udd_query( "EXECUTE query_get_tasks('%s')" % blendname)
+    _execute_udd_query("EXECUTE query_get_tasks('%s')" % blendname)
     bugs_data = {}
     if curs.rowcount > 0:
         for t in RowDictionaries(curs):
@@ -168,11 +174,11 @@ EXCELLENT    =   5 # There is no real need to look at this meta package
             bugs_data[task]['ndonebugs']        = 0
             bugs_data[task]['weighttask']       = 0
             for status in STATES:
-                bugs_data[task][status + '_l']     = [] # enable sorting
+                bugs_data[task][status + '_l']     = []  # enable sorting
                 bugs_data[task][status]            = {}
                 bugs_data[task][status]['sources'] = []
                 if status != 'done':
-                    bugs_data[task][status]['severitysummary'] = '' # string listing number of bugs in different severity / dependency classes
+                    bugs_data[task][status]['severitysummary'] = ''  # string listing number of bugs in different severity / dependency classes
                     bugs_data[task][status]['severities'] = {}
                     for s in SEVERITIES:
                         bugs_data[task][status]['severities'][s] = 0
@@ -181,7 +187,7 @@ EXCELLENT    =   5 # There is no real need to look at this meta package
         exit(1)
 
     # Fetch bugs of all Blends dependencies and store them in a dictionary
-    _execute_udd_query( "EXECUTE query_bugs('%s')" % blendname)
+    _execute_udd_query("EXECUTE query_bugs('%s')" % blendname)
     bugs = {}
     if curs.rowcount > 0:
         for bug in RowDictionaries(curs):
@@ -190,11 +196,11 @@ EXCELLENT    =   5 # There is no real need to look at this meta package
                 bugs[bug['source']]['severities'] = {}
                 for s in SEVERITIES:
                     bugs[bug['source']]['severities'][s] = 0
-                    bugs[bug['source']]['nopenbugs'] = 0
-                    bugs[bug['source']]['ndonebugs'] = 0
-                    bugs[bug['source']]['open'] = []
-                    bugs[bug['source']]['done'] = []
-                    b = {}
+                bugs[bug['source']]['nopenbugs'] = 0
+                bugs[bug['source']]['ndonebugs'] = 0
+                bugs[bug['source']]['open'] = []
+                bugs[bug['source']]['done'] = []
+            b = {}
             for k in bug.keys():
                 if k in ('source', 'status') :
                     continue
@@ -221,7 +227,7 @@ EXCELLENT    =   5 # There is no real need to look at this meta package
         exit(1)
 
     # Merge metadata of packages and bugs together in bugs_data dictionary, also do statistics about bugs
-    _execute_udd_query( "EXECUTE query_bug_packages('%s')" % blendname)
+    _execute_udd_query("EXECUTE query_bug_packages('%s')" % blendname)
     if curs.rowcount > 0:
         for pkg in RowDictionaries(curs):
             task = pkg['task']
@@ -233,37 +239,37 @@ EXCELLENT    =   5 # There is no real need to look at this meta package
             sources['maintainer_email'] = _url
             sources['maintainer_name']  = _name
             sources['maintainer']  = MarkupString('<a href="mailto:%s">%s</a>' % (_url, _name), pkg['source'], 'maintainer')
-                if pkg['status'] == 'depends':
-                    sources['bugs'] = bugs[pkg['source']]['open']
-                    bugs_data[task][pkg['status']+'_l'].append(pkg['source'])
-                    for s in SEVERITIES:
-                        bugs_data[task][pkg['status']]['severities'][s] += bugs[pkg['source']]['severities'][s]
-                        bugs_data[task]['weighttask'] += 3 * WEIGHT[s] * bugs[pkg['source']]['severities'][s]
-                elif pkg['status'] == 'suggests':
-                    sources['bugs'] = bugs[pkg['source']]['open']
-                    bugs_data[task][pkg['status']+'_l'].append(pkg['source'])
-                    for s in SEVERITIES:
-                        bugs_data[task][pkg['status']]['severities'][s] += bugs[pkg['source']]['severities'][s]
-                        bugs_data[task]['weighttask'] += 1 * WEIGHT[s] * bugs[pkg['source']]['severities'][s]
-                else:
-                    stderr.write("%s: Wrong status %s in task %s for source %s\n"
-                                 % (blendname, pkg['status'], task, pkg['source']))
-                    exit(1)
-                    bugs_data[task][pkg['status']]['sources'].append(sources)
-                    bugs_data[task]['nopenbugs'] += bugs[pkg['source']]['nopenbugs']
-                    bugs_data[task]['ndonebugs'] += bugs[pkg['source']]['ndonebugs']
-                if bugs[pkg['source']]['done']:
-                    sources = {}
-                    sources['source']      = pkg['source']
-                    sources['homepage']    = pkg['homepage']
-                    sources['vcs_browser'] = pkg['vcs_browser']
-                    (_name, _url) = email.Utils.parseaddr(pkg['maintainer'])
-                    sources['maintainer_email'] = _url
-                    sources['maintainer_name']  = _name
-                    sources['maintainer']  = MarkupString('<a href="mailto:%s">%s</a>' % (_url, _name), pkg['source'], 'maintainer')
-                    sources['bugs']        = bugs[pkg['source']]['done']
-                    bugs_data[task]['done_l'].append(pkg['source'])
-                    bugs_data[task]['done']['sources'].append(sources)
+            if pkg['status'] == 'depends':
+                sources['bugs'] = bugs[pkg['source']]['open']
+                bugs_data[task][pkg['status'] + '_l'].append(pkg['source'])
+                for s in SEVERITIES:
+                    bugs_data[task][pkg['status']]['severities'][s] += bugs[pkg['source']]['severities'][s]
+                    bugs_data[task]['weighttask'] += 3 * WEIGHT[s] * bugs[pkg['source']]['severities'][s]
+            elif pkg['status'] == 'suggests':
+                sources['bugs'] = bugs[pkg['source']]['open']
+                bugs_data[task][pkg['status'] + '_l'].append(pkg['source'])
+                for s in SEVERITIES:
+                    bugs_data[task][pkg['status']]['severities'][s] += bugs[pkg['source']]['severities'][s]
+                    bugs_data[task]['weighttask'] += 1 * WEIGHT[s] * bugs[pkg['source']]['severities'][s]
+            else:
+                stderr.write("%s: Wrong status %s in task %s for source %s\n"
+                             % (blendname, pkg['status'], task, pkg['source']))
+                exit(1)
+            bugs_data[task][pkg['status']]['sources'].append(sources)
+            bugs_data[task]['nopenbugs'] += bugs[pkg['source']]['nopenbugs']
+            bugs_data[task]['ndonebugs'] += bugs[pkg['source']]['ndonebugs']
+            if bugs[pkg['source']]['done']:
+                sources = {}
+                sources['source']      = pkg['source']
+                sources['homepage']    = pkg['homepage']
+                sources['vcs_browser'] = pkg['vcs_browser']
+                (_name, _url) = email.Utils.parseaddr(pkg['maintainer'])
+                sources['maintainer_email'] = _url
+                sources['maintainer_name']  = _name
+                sources['maintainer']  = MarkupString('<a href="mailto:%s">%s</a>' % (_url, _name), pkg['source'], 'maintainer')
+                sources['bugs']        = bugs[pkg['source']]['done']
+                bugs_data[task]['done_l'].append(pkg['source'])
+                bugs_data[task]['done']['sources'].append(sources)
     else:
         stderr.write("No information about buggy packages received for Blend %s\n" % blendname)
         exit(1)
@@ -272,22 +278,22 @@ EXCELLENT    =   5 # There is no real need to look at this meta package
     current_dir  = os.path.dirname(__file__)
     # locale_dir   = os.path.join(current_dir, 'locale')
     template_dir = os.path.join(current_dir, 'templates')
-    
+
     # initialize gensi
     loader = TemplateLoader([template_dir], auto_reload=True,
                             default_encoding="utf-8")
-    
-    outputdir = CheckOrCreateOutputDir(config['outputdir'],'bugs') # FIXME: as long as we are not finished use different dir
-    if outputdir == None:
+
+    outputdir = CheckOrCreateOutputDir(config['outputdir'], 'bugs')  # FIXME: as long as we are not finished use different dir
+    if outputdir is None:
         exit(-1)
-        
+
     t = datetime.now()
-    
+
     # Initialize i18n
     domain = 'blends-webtools'
     gettext.install(domain)
 
-    data={}
+    data = {}
     data['projectname'] = blendname
     data['bugs_data']   = bugs_data
     if config.get('advertising') is not None:
@@ -303,8 +309,8 @@ EXCELLENT    =   5 # There is no real need to look at this meta package
     data['summary']           = _('Summary')
     data['idxsummary']        = _("""A %sDebian Pure Blend%s is a Debian internal project which assembles
 a set of packages that might help users to solve certain tasks of their work.  The list on
-the right shows the tasks of %s.""" ) \
-% ('<a href="http://blends.alioth.debian.org/blends/">', '</a>', data['projectname'])
+the right shows the tasks of %s.""") \
+        % ('<a href="http://blends.alioth.debian.org/blends/">', '</a>', data['projectname'])
     data['idxsummary']        = Markup(data['idxsummary'])
 
     t = datetime.now()
@@ -321,8 +327,8 @@ the right shows the tasks of %s.""" ) \
     data['bugssummary']       = _("""A %sDebian Pure Blend%s is a Debian internal project which assembles
     a set of packages that might help users to solve certain tasks of their work.  This page should be helpful
     to track down the bugs of packages that are interesting for the %s project to enable developers a quick
-    overview about possible problems.""" ) \
-    % ('<a href="http://blends.alioth.debian.org/blends/">', '</a>', data['projectname'])
+    overview about possible problems.""") \
+        % ('<a href="http://blends.alioth.debian.org/blends/">', '</a>', data['projectname'])
     data['bugssummary']        = Markup(data['bugssummary'])
     data['gtstrBugsPage']     = _("Bugs page")
     data['gtstrListOfBugspages'] = _("This is a list of metapackages.  The links are leading to the respective bugs page.")
@@ -335,15 +341,16 @@ the right shows the tasks of %s.""" ) \
     sum is compared to some boundaries to find a verbal form.  The actual numbers need some adjustment
     to make real sense - this evaluation method is in testing phase.""")
     data['weightdetails']     = _("The severities of bugs are weighted as follows")
-    
-    data['assessments']     = [ (EXCELLENT,    'excellent'),
-                                (VERYGOOD,     'verygood'),
-                                (GOOD,         'good'),
-                                (SATISFACTORY, 'satisfactory'),
-                                (PASS,         'pass'),
-                                (BAD,          'bad')
+
+    data['assessments'] = [
+        (EXCELLENT,    'excellent'),
+        (VERYGOOD,     'verygood'),
+        (GOOD,         'good'),
+        (SATISFACTORY, 'satisfactory'),
+        (PASS,         'pass'),
+        (BAD,          'bad')
     ]
-    
+
     for task in bugs_data:
         if bugs_data[task]['weighttask'] < data['assessments'][0][0]:
             bugs_data[task]['weightedsev']   = _('Task is in excellent shape')
@@ -363,39 +370,39 @@ the right shows the tasks of %s.""" ) \
         else:
             bugs_data[task]['weightedsev']   = _('Immediately looking into bugs of the dependencies of this task is advised')
             bugs_data[task]['weightedclass'] = data['assessments'][5][1]
-            bugs_data[task]['weightedsev']   +=  ' (%i)' % bugs_data[task]['weighttask']
+            bugs_data[task]['weightedsev']   += ' (%i)' % bugs_data[task]['weighttask']
 
     # Debuging output in JSON file
     if debug > 0:
-        with open(blendname+'_bugs.json', 'w') as f:
-          if debug > 1:
-            for task in bugs_data:
-                f.write("*** %s ***\n" % task)
-                for status in STATES:
-                    if status in bugs_data[task]:
-                        f.write("%s\n" % status)
-                        f.write(json.dumps(bugs_data[task][status]))
-                        f.write("\n\n")
-                        f.write(json.dumps(bugs_data))
-                        SetFilePermissions(blendname+'_bugs.json')
+        with open(blendname + '_bugs.json', 'w') as f:
+            if debug > 1:
+                for task in bugs_data:
+                    f.write("*** %s ***\n" % task)
+                    for status in STATES:
+                        if status in bugs_data[task]:
+                            f.write("%s\n" % status)
+                            f.write(json.dumps(bugs_data[task][status]))
+                            f.write("\n\n")
+            f.write(json.dumps(bugs_data))
+        SetFilePermissions(blendname + '_bugs.json')
 
     nbugs           = {}
     ndone           = {}
     buglist         = {}
-    weightedsev     = {} # verbal interpretation of weighted bugs
-    weightedclass   = {} # CSS class according bug weight
-    weighttask      = {} # weighted severity as number per task
-    
+    weightedsev     = {}  # verbal interpretation of weighted bugs
+    weightedclass   = {}  # CSS class according bug weight
+    weighttask      = {}  # weighted severity as number per task
+
     wsev = 0  # sumarise weighted severities
     for task in bugs_data:
         for status in STATES:
             if status != 'done':
                 komma  = ''
                 for s in SEVERITIES:
-                     if bugs_data[task][status]['severities'][s] != 0:
-                         bugs_data[task][status]['severitysummary'] += '%s %i %s' % (komma, bugs_data[task][status]['severities'][s], s)
-                         komma = ','
-        if   wsev < data['assessments'][0][0]:
+                    if bugs_data[task][status]['severities'][s] != 0:
+                        bugs_data[task][status]['severitysummary'] += '%s %i %s' % (komma, bugs_data[task][status]['severities'][s], s)
+                        komma = ','
+        if wsev < data['assessments'][0][0]:
             weightedsev[task]   = _('Metapackage is in excellent shape')
             weightedclass[task] = data['assessments'][0][1]
         elif wsev < data['assessments'][1][0]:
@@ -413,27 +420,31 @@ the right shows the tasks of %s.""" ) \
         else:
             weightedsev[task]   = _('Immediately looking into bugs of the dependencies of this metapackage is advised')
             weightedclass[task] = data['assessments'][5][1]
-            weightedsev[task] += ' (%i)' % wsev
-            weighttask[task]   = wsev
-            
-    data['headings'] = {'dependent' : _('Open bugs in dependent packages'),
-                        'suggested' : _('Open bugs in suggested packages'),
-                        'done'      : _('Done bugs')
+        weightedsev[task] += ' (%i)' % wsev
+        weighttask[task]   = wsev
+
+    data['headings'] = {
+        'dependent' : _('Open bugs in dependent packages'),
+        'suggested' : _('Open bugs in suggested packages'),
+        'done'      : _('Done bugs')
     }
-    data['nobugs']   = {'dependent' : _('No open bugs in dependent packages'),
-                        'suggested' : _('No open bugs in suggested packages'),
-                        'done'      : _('No done bugs')
+    data['nobugs']   = {
+        'dependent' : _('No open bugs in dependent packages'),
+        'suggested' : _('No open bugs in suggested packages'),
+        'done'      : _('No done bugs')
     }
-    data['cssclass'] = {'dependent' : 'bugsdependent',
-                        'suggested' : 'bugssuggested',
-                        'done'      : 'bugsdone'
+    data['cssclass'] = {
+        'dependent' : 'bugsdependent',
+        'suggested' : 'bugssuggested',
+        'done'      : 'bugsdone'
     }
     # FIXME: just always use 'depends' or 'dependent' etc.  This translation is just to be able to compare with old output
-    data['category'] = {'depends'   : 'dependent',
-                        'suggests'  : 'suggested',
-                        'done'      : 'done'
+    data['category'] = {
+        'depends'   : 'dependent',
+        'suggests'  : 'suggested',
+        'done'      : 'done'
     }
-    
+
     data['nbugs']           = nbugs
     data['ndone']           = ndone
     data['weight']          = WEIGHT
@@ -442,29 +453,29 @@ the right shows the tasks of %s.""" ) \
     data['nohomepage']      = _('Homepage not available')
     data['novcsbrowser']    = _('Not maintained in Vcs')
     data['vcslocation']     = _('Vcs')
-    
+
     data['weighttask']      = weighttask
     data['weightedclass']   = weightedclass
 
     for key in ('css', 'homepage', 'projecturl', 'projectname', 'logourl', 'ubuntuhome', 'projectubuntu'):
         data[key] = config[key]
-        
+
     for task in bugs_data:
         data['task']            = task
-        #data['buglist']         = buglist[task]
-        #data['weightedsev']     = weightedsev[task]
-        #data['severitystat']    = severitystat[task]
-        
+        # data['buglist']         = buglist[task]
+        # data['weightedsev']     = weightedsev[task]
+        # data['severitystat']    = severitystat[task]
+
         template = loader.load('bugs.xhtml')
         with codecs.open(outputdir + '/' + task + '.html', 'w', 'utf-8') as f:
             f.write(template.generate(**data).render('xhtml'))
-            SetFilePermissions(outputdir + '/' + task + '.html')
-            
+        SetFilePermissions(outputdir + '/' + task + '.html')
+
     template = loader.load('bugs_idx.xhtml')
     outputfile = outputdir + '/index.html'
     with codecs.open(outputfile, 'w', 'utf-8') as f:
         f.write(template.generate(**data).render('xhtml'))
-        SetFilePermissions(outputfile)
+    SetFilePermissions(outputfile)
 
 if __name__ == '__main__':
     main()

-- 
Static and dynamic websites for Debian Pure Blends



More information about the Blends-commit mailing list