[Blends-commit] r2312 - blends/trunk/webtools

Debian Pure Blends Subversion Commit noreply at alioth.debian.org
Tue Aug 3 19:35:27 UTC 2010


Author: tille
Date: Tue Aug  3 19:35:26 2010
New Revision: 2312
URL: http://svn.debian.org/viewsvn/blends?rev=2312&view=rev

Log:
Use Python logging instead of just printing to stderr/stdout to enable better control of other scripts about output


Modified:
   blends/trunk/webtools/blendstasktools.py
   blends/trunk/webtools/new_upstream

Modified: blends/trunk/webtools/blendstasktools.py
URL: http://svn.debian.org/viewsvn/blends/blends/trunk/webtools/blendstasktools.py?rev=2312&view=diff&r1=2312&r2=2311&p1=blends/trunk/webtools/blendstasktools.py&p2=blends/trunk/webtools/blendstasktools.py
==============================================================================
--- blends/trunk/webtools/blendstasktools.py	(original)
+++ blends/trunk/webtools/blendstasktools.py	Tue Aug  3 19:35:26 2010
@@ -38,6 +38,11 @@
 from debian_bundle import deb822
 from blendsunicode import to_unicode
 
+import logging
+import logging.handlers
+logger = logging.getLogger('blends')
+logger.setLevel(logging.INFO)
+
 # Seems to have problems on 17.04.2009
 # BASEURL  = 'http://ftp.debian.org/debian'
 BASEURL  = 'http://ftp.de.debian.org/debian'
@@ -212,9 +217,9 @@
             if pkgstat in pkgstatus.keys():
                 use_dependencystatus.append(pkgstat)
             else:
-                print >>stderr, "Unknown dependencystatus %s" % pkgstat
+                logger.error("Unknown dependencystatus %s" % pkgstat)
         if use_dependencystatus == []:
-            print >>stderr, "No valid dependencystatus in", dependencystatus
+            logger.error("No valid dependencystatus in", dependencystatus)
     return use_dependencystatus
 
 ###########################################################################################
@@ -222,7 +227,7 @@
 try:
     conn = psycopg2.connect(host="localhost",port=PORT,user="guest",database="udd")
 except psycopg2.OperationalError:
-    # print "PostgreSQL does not seem to run on port %i .. trying default port %i." % (PORT, DEFAULTPORT)
+    logger.debug("PostgreSQL does not seem to run on port %i .. trying default port %i." % (PORT, DEFAULTPORT))
     try:
         conn = psycopg2.connect(host="localhost",port=DEFAULTPORT,user="guest",database="udd")
     except psycopg2.OperationalError:
@@ -366,7 +371,7 @@
         # if config file can not be found in local dir, try /etc/blends/webconf as fallback
         conffile_default = '/etc/blends/webconf/' + blendname + '.conf'
         if not os.access(conffile_default, os.R_OK):
-            print >>stderr, "Unable to open config file %s or %s." % (conffile, conffile_default)
+            logger.error("Unable to open config file %s or %s." % (conffile, conffile_default))
             exit(-1)
         conffile = conffile_default
     f = open(conffile, 'r')
@@ -423,7 +428,7 @@
             try:
 		os.makedirs(tasksdir)
             except:
-		print >> stderr, "Unable to create data directory", tasksdir
+		logger.error("Unable to create data directory", tasksdir)
         # Checkout/Update tasks from SVN
         svncommand = "svn %%s %s/%s/%s %s >> /dev/null" % (SVNHOST, data['vcsdir'], dir, tasksdir)
         if os.path.isdir(tasksdir+'/.svn'):
@@ -432,11 +437,11 @@
             os.system("mkdir -p %s" % (tasksdir))
             svncommand = svncommand % 'co'
         if os.system(svncommand):
-    	    print >>stderr, "SVN command %s failed" % (svncommand)
+    	    logger.error("SVN command %s failed" % (svncommand))
     	    if os.path.isdir(tasksdir+'/.svn'):
-    		print >>stderr, "Trying old files in %s ..." % tasksdir
+    		logger.error("Trying old files in %s ..." % tasksdir)
     	    else:
-    		print >>stderr, "There are no old files in %s -> giving up" % tasksdir
+    		logger.error("There are no old files in %s -> giving up" % tasksdir)
     		exit(-1)
     return data['datadir'] + '/tasks'
 
@@ -477,14 +482,14 @@
         # Seems that vcs_browser = vcs_url in Mercurial
         return vcs_url
     elif vcs_type.lower().startswith('bzr') or vcs_type.lower().startswith('cvs'):
-        print >>stderr, "No idea how to guess vcs_browser for %s URLS" % vcs_type
+        logger.warning("No idea how to guess vcs_browser for %s URLS" % vcs_type)
         return
     else:
-        print >>stderr, "Unknown VCS for ", vcs_url
+        logger.warning("Unknown VCS for " + vcs_url)
         return HOMEPAGENONE
 
     if ret_url == vcs_url:
-        print >>stderr, "Unable to obtain Vcs-Browser from", vcs_url
+        logger.warning("Unable to obtain Vcs-Browser from " + vcs_url)
         return HOMEPAGENONE
     return ret_url
 
@@ -573,7 +578,7 @@
             self.desc['en']['long']  = Markup(render_longdesc(row['long_description'].splitlines()))
             (_name, _url) = email.Utils.parseaddr(row['maintainer'])
             self.responsible = '<a href="mailto:%s">%s</a>' % (_url, to_unicode(_name))
-            print "The package %s is not yet in Debian but it is just in the new queue. (Task %s)" % (self.pkg, self.taskname)
+            logger.info("The package %s is not yet in Debian but it is just in the new queue. (Task %s)" % (self.pkg, self.taskname))
 
             return
         # = the package exists in UDD table packages
@@ -707,7 +712,7 @@
                     try:
                         self.properties['vcs-browser'] = BrowserFromVcsURL(self.properties['vcs-type'], self.properties['vcs-url'])
                     except KeyError, err:
-                        print >>stderr, "Vcs Property missing in Database:", self.properties, err
+                        logger.warning("Vcs Property missing in Database:", self.properties, err)
                 if not self.properties.has_key('vcs-type') or not self.properties['vcs-type']:
                     if self.properties.has_key('vcs-browser') and self.properties['vcs-browser'] != HOMEPAGENONE:
                         self.properties['vcs-type']    = VcsTypeFromBrowserURL(self.properties['vcs-browser'])
@@ -718,7 +723,7 @@
             # and bugs should be rendered in the same job - so we need the differentiation anyway
             self.src = self.properties['source']
         else:
-            print >>stderr, "Failed to obtain source for package", self.pkg
+            logger.error("Failed to obtain source for package", self.pkg)
             return
 
         query = "EXECUTE query_get_latest_uploader ('%s')" % (self.src)
@@ -727,7 +732,7 @@
             changed = to_unicode(curs.fetchone()[0])
 	except TypeError, err:
             changed = None
-            print "Query '%s' does not result in a valid changed entry (%s)" % (query, err)
+            logger.info("Query '%s' does not result in a valid changed entry (%s)" % (query, err))
         if changed:
             if not changed.startswith(self.properties['maintainer']):
                 (_name, _url) = email.Utils.parseaddr(changed)
@@ -803,6 +808,13 @@
 
     def __init__(self, blendname):
 
+        os.system("mkdir -p logs")
+        LOG_FILENAME = 'logs/'+blendname+'.log'
+        handler = logging.handlers.RotatingFileHandler(filename=LOG_FILENAME,mode='w')
+        formatter = logging.Formatter("%(levelname)s - %(filename)s (%(lineno)d): %(message)s")
+        handler.setFormatter(formatter)
+        logger.addHandler(handler)
+
         # This Instance of the Available class contains all
         # information about packages that are avialable in Debian
         # See below for more information about Available class
@@ -840,7 +852,7 @@
         elif os.access(os.getcwd() + '/blend-get-names', os.X_OK):
             blend_get_names = os.getcwd() + '/blend-get-names'
         else:
-            print >>stderr, "Please either install package Blends-dev or install a copy of devtools/blend-get-names in your working directory"
+            logger.critical("Please either install package Blends-dev or install a copy of devtools/blend-get-names in your working directory")
             exit(-1)
 
         # The prefix is used to build the meta package name that belongs to the task
@@ -979,7 +991,7 @@
 		try:
 			os.system("mkdir -p %s" % outputdir)
 		except:
-			print >>stderr, "Unable to create output dir " + outputdir
+			logger.error("Unable to create output dir " + outputdir)
 			return None
         return outputdir
 
@@ -993,7 +1005,7 @@
             for dependency in tdeps.dependencies.keys():
                 for dep in tdeps.dependencies[dependency]:
                     if dep.properties['Enhances'] != {}:
-                        # print "Package %s is enhanced by:" % dep.pkg
+                        logger.debug("Package %s is enhanced by:" % dep.pkg)
                         for enh in dep.properties['Enhances'].keys():
                             # seek for Enhances on same page
                             found = 0
@@ -1016,7 +1028,7 @@
                                                 break
                                     if found == 1:
                                         break
-                            # print " %s -> %s" % (enh, dep.properties['Enhances'][enh])
+                            logger.debug(" %s -> %s" % (enh, dep.properties['Enhances'][enh]))
 
     def __str__(self):
         ret = "Blendname: "       + self.blendname  + ", " \
@@ -1056,7 +1068,7 @@
         if os.path.isfile(self.taskfile):
             self.task = task
         else:
-            print >>stderr, "No such task file %s." % self.taskfile
+            logger.error("No such task file %s." % self.taskfile)
             return None
 
         # Dictionary with satus of dependencies as key and list of DependantPackage
@@ -1151,8 +1163,8 @@
                                 self.metapkg.desc[lang]['short'] = MarkupString(to_unicode(short), \
                                                   self.metapkg.PrintedName, 'taskShortDesc - ' + lang)
                             except UnicodeEncodeError, err:
-                                print >> stderr, "===> UnicodeDecodeError in metapackage %s (lang='%s'): '%s'; ErrTxt: %s" % \
-                                    (self.metapkg.pkg, lang, row['description'], err)
+                                logger.error("===> UnicodeDecodeError in metapackage %s (lang='%s'): '%s'; ErrTxt: %s" % \
+                                    (self.metapkg.pkg, lang, row['description'], err))
                                 short = to_unicode(row['description'],'latin1')
                                 self.metapkg.desc[lang]['short'] = MarkupString(short, \
                                                   self.metapkg.PrintedName, 'taskShortDesc - ' + lang)
@@ -1160,8 +1172,8 @@
                             try:
                                 self.metapkg.desc[lang]['long'] = Markup(render_longdesc(to_unicode(row['long_description']).splitlines()))
                             except UnicodeDecodeError, err:
-                                print >> stderr, "===> UnicodeDecodeError in metapackage long %s (lang='%s'): '%s'; ErrTxt: %s" % \
-                                    (self.metapkg.pkg, lang, row['long_description'], err)
+                                logger.error("===> UnicodeDecodeError in metapackage long %s (lang='%s'): '%s'; ErrTxt: %s" % \
+                                    (self.metapkg.pkg, lang, row['long_description'], err))
                                 self.metapkg.desc[lang]['long'] = 'UnicodeDecodeError'
 
                     continue
@@ -1176,7 +1188,7 @@
                     responsible = stanza['responsible'].strip()
             	    if not dep:
             		# Make sure there is really enough information to deal with provided by the package
-            		print >>stderr, "Missing package information for field %s = %s" % (key, responsible)
+            		logger.error("Missing package information for field %s = %s" % (key, responsible))
             		continue
                     if dep.responsible != None:
                         # we are dealing with an official package that has a real maintainer who
@@ -1224,8 +1236,8 @@
                             dep.pkg            = dep_in_line
                         else:
                             dep.pkg            = dep_in_line.lower()
-                            print >> stderr, "Package names may not contain upper case letters, so %s is an invalid package name which is turned into %s" \
-                                % (dep_in_line, dep.pkg)
+                            logger.warning("Package names may not contain upper case letters, so %s is an invalid package name which is turned into %s" \
+                                % (dep_in_line, dep.pkg))
 
                         dep._QueryUDD4Package(source)
 
@@ -1259,8 +1271,8 @@
                         else:
                             fields_obsolete.append(key)
                     else:
-                        print >>stderr, "Dep not initiated before Homepage %s -> something is wrong." \
-                              % stanza['homepage']
+                        logger.error("Dep not initiated before Homepage %s -> something is wrong." \
+                              % stanza['homepage'])
                 elif key == 'Vcs-Svn' or key == 'vcs-svn': # strangely enough on alioth the later
                                                            # spelling seems to be needed - no idea why
                     if dep != None:
@@ -1274,10 +1286,10 @@
                             try:
                                 dep.properties['vcs-browser'] = BrowserFromVcsURL(dep.properties['vcs-type'], dep.properties['vcs-url'])
                             except KeyError, err:
-                                print >>stderr, "Vcs Property missing in packages file:", dep.properties, err
+                                logger.error("Vcs Property missing in packages file:", dep.properties, err)
                     else:
-                        print >>stderr, "Dep not initiated before Vcs-Svn %s -> something is wrong." \
-                              % stanza['vcs-svn']
+                        logger.error("Dep not initiated before Vcs-Svn %s -> something is wrong." \
+                              % stanza['vcs-svn'])
                     if dep.pkgstatus == 'unknown':
                         dep.pkgstatus = 'pkgvcs'
                 elif key == 'Vcs-Git' or key == 'vcs-git': # strangely enough on alioth the later
@@ -1292,8 +1304,8 @@
                         if dep.properties['vcs-browser'] == HOMEPAGENONE:
                             dep.properties['vcs-browser'] = BrowserFromVcsURL(dep.properties['vcs-type'], dep.properties['vcs-url'])
                     else:
-                        print >>stderr, "Dep not initiated before Vcs-Git %s -> something is wrong." \
-                              % stanza['vcs-git']
+                        logger.error("Dep not initiated before Vcs-Git %s -> something is wrong." \
+                              % stanza['vcs-git'])
                 elif key == 'Vcs-Browser' or key == 'vcs-browser': # strangely enough on alioth the later
                                                            # spelling seems to be needed - no idea why
                     if dep != None:
@@ -1314,34 +1326,34 @@
                         if not dep.properties.has_key('vcs-url'):
                             dep.properties['vcs-url'] = dep.properties['vcs-browser']
                     else:
-                        print >>stderr, "Dep not initiated before Vcs-Browser %s -> something is wrong." \
-                              % stanza['vcs-browser']
+                        logger.error("Dep not initiated before Vcs-Browser %s -> something is wrong." \
+                              % stanza['vcs-browser'])
                     if dep.pkgstatus == 'unknown':
                         dep.pkgstatus = 'pkgvcs'
                 elif key == 'section':
                     if dep != None:
                         dep.properties[key.lower()]  = stanza[key.lower()]
                     else:
-                        print >>stderr, "Dep not initiated before %s %s -> something is wrong." \
-                              % (key, stanza[key.lower()])
+                        logger.error("Dep not initiated before %s %s -> something is wrong." \
+                              % (key, stanza[key.lower()]))
                 elif key == 'License':
                     if dep != None:
                         dep.properties[key.lower()]  = stanza[key.lower()]
                     else:
-                        print >>stderr, "Dep not initiated before %s %s -> something is wrong." \
-                              % (key, stanza[key.lower()])
+                        logger.error("Dep not initiated before %s %s -> something is wrong." \
+                              % (key, stanza[key.lower()]))
                 elif key == 'Language':
                     if dep != None:
                         dep.properties[key.lower()]  = stanza[key.lower()]
                     else:
-                        print >>stderr, "Dep not initiated before %s %s -> something is wrong." \
-                              % (key, stanza[key.lower()])
+                        logger.error("Dep not initiated before %s %s -> something is wrong." \
+                              % (key, stanza[key.lower()]))
                 elif key == 'Registration':
                     if dep != None:
                         dep.properties[key.lower()]  = stanza[key.lower()]
                     else:
-                        print >>stderr, "Dep not initiated before %s %s -> something is wrong." \
-                              % (key, stanza[key.lower()])
+                        logger.error("Dep not initiated before %s %s -> something is wrong." \
+                              % (key, stanza[key.lower()]))
                 elif key.startswith('Published-'):
                     if dep != None:
                         if not dep.properties.has_key('published'):
@@ -1349,14 +1361,14 @@
                         ptype = key.replace('Published-','').lower()
                         dep.properties['published'][ptype] = to_unicode(stanza[key.lower()])
                     else:
-                        print >>stderr, "Dep not initiated before %s %s -> something is wrong." \
-                              % (key, stanza[key.lower()])
+                        logger.error("Dep not initiated before %s %s -> something is wrong." \
+                              % (key, stanza[key.lower()]))
                 elif key == 'WNPP':
                     if dep != None:
                         # it makes sense to assume that a package where WNPP was recently closed
                         # shows up in unstable first
                         if dep.component != None:
-                            print "Hint: WNPP for package %s just closed - extra information can be removed from task file." % (dep.pkg)
+                            logger.info("WNPP for package %s just closed - extra information can be removed from task file %s." % (dep.pkg, dep.taskname))
                         else:
                     	    wnpp = stanza['wnpp'].strip()
                             # in case somebody prepended a '#' sign before the bug number
@@ -1365,20 +1377,20 @@
                     	    if re.compile("^\d+$").search(wnpp):
                         	dep.properties['wnpp'] = wnpp
                     else:
-                        print >>stderr, "Dep not initiated before WNPP %s -> something is wrong." \
-                              % stanza['wnpp']
+                        logger.error("Dep not initiated before WNPP %s -> something is wrong." \
+                              % stanza['wnpp'])
                 elif key.lower() == 'pkg-url':
                     if dep != None:
                         if dep.properties['pkg-url'] == HOMEPAGENONE: # only if no official package is just available
                             # Escape '&' in URLs with %26 (Trick stolen by pasting the URL into a search engine ;-))
                             dep.properties['pkg-url'] = stanza['pkg-url'].replace("&", "%26")
                     else:
-                        print >>stderr, "Dep not initiated before Pkg-URL %s -> something is wrong." \
-                              % stanza['pkg-url']
+                        logger.error("Dep not initiated before Pkg-URL %s -> something is wrong." \
+                              % stanza['pkg-url'])
                 elif key == 'Pkg-Description':
                     if dep == None:
-                        print >>stderr, "Dep not initiated before Pkg-Description %s -> something is wrong." \
-                              % stanza['pkg-description'].splitlines()[0]
+                        logger.error("Dep not initiated before Pkg-Description %s -> something is wrong." \
+                              % stanza['pkg-description'].splitlines()[0])
                     else:
                         # Only update use description from task file if not known from official package
                         if dep.desc['en'] == {}:
@@ -1404,9 +1416,9 @@
                         # Also ignore keys starting with X[A-Z]-
                         if not re.compile("^X[A-Z]*-").search(key):
                             try:
-                                print "Unknown key '%s': %s in task %s" % (key, stanza[key], self.task)
+                                logger.warning("Unknown key '%s': %s in file %s" % (key, stanza[key], self.metapkg.PrintedName))
                             except:
-                                print "Unknown key '%s' with problematic value in task %s." % (key, self.task)
+                                logger.error("Unknown key '%s' with problematic value in file %s." % (key, self.metapkg.PrintedName))
 
             if dep == None:
                 continue # ... with next stanza
@@ -1437,20 +1449,20 @@
                             VirtProvides.append(row[0])
                             for hasdeps in tmp_dep_list:
                                 if row[0] == hasdeps.pkg:
-                                    print >>stderr, "    --> %s is mentioned explicitely in dependency list" % row[0]
+                                    logger.error("    --> %s is mentioned explicitely in dependency list" % row[0])
                                     has_expilicite = 1
                         if has_expilicite == 1:
-                            print >>stderr, "Do not keep a record of virtual package %s which has explicite package dependencies" % dep.pkg
+                            logger.error("Do not keep a record of virtual package %s which has explicite package dependencies" % dep.pkg)
                             # ATTENTION: THIS HAS TO BE CHANGED FOR blends-dev BY AN OPTIONAL parameter
                             continue
 
-                        print >>stderr, "Use real package %s instead of virtual package %s." % (VirtProvides[0], dep.pkg)
+                        logger.error("Use real package %s instead of virtual package %s." % (VirtProvides[0], dep.pkg))
                         dep.pkg = VirtProvides[0]
                         dep._QueryUDD4Package(source)
 
                         if len(VirtProvides) > 1:
-                            print >>stderr, "Virtual package %s is provided by more than one package (%s).  Make sure you mention a real package in addition!" \
-                                % (dep.pkg, str(VirtProvides))
+                            logger.error("Virtual package %s is provided by more than one package (%s).  Make sure you mention a real package in addition!" \
+                                % (dep.pkg, str(VirtProvides)))
 
                             for virt_provides in VirtProvides[1:]:
                                 # Add all remaining packages which provide a virtual package to the list
@@ -1465,7 +1477,7 @@
                                 dep.pkg            = virt_provides
                                 dep._QueryUDD4Package(source)
                     else:
-                        print >>stderr, "Warning: Dependency with unknown status: %s (Task %s)" % (dep.pkg, dep.taskname)
+                        logger.warning("Dependency with unknown status: %s (Task %s)" % (dep.pkg, dep.taskname))
 
             tmp_dep_list.append(dep)
             # remarks which are common to several dependencies in a list have to be added to all of the dependencies
@@ -1473,9 +1485,10 @@
                 if remark != {}:
                     dep.remark = remark
                 if fields_obsolete != [] and dep.pkgstatus != 'new':
-                    print "Package %s is an official package and has information in UDD. The following extra information can be removed from tasks file:" % dep.pkg, fields_obsolete
+                    logger.info("Package %s is an official package and has information in UDD. The following extra information can be removed from tasks file %s: %s" % \
+                                     (dep.pkg, dep.taskname, str(fields_obsolete)))
                 if dep.desc['en'] == {}:
-                    print >>stderr, "Missing description for package %s.  This package will be ignored completely." % (dep.pkg)
+                    logger.error("Missing description for package %s in task %s.  This package will be ignored completely." % (dep.pkg, dep.taskname))
                 else:
                     self._AppendDependency2List(dep, source)
 

Modified: blends/trunk/webtools/new_upstream
URL: http://svn.debian.org/viewsvn/blends/blends/trunk/webtools/new_upstream?rev=2312&view=diff&r1=2312&r2=2311&p1=blends/trunk/webtools/new_upstream&p2=blends/trunk/webtools/new_upstream
==============================================================================
--- blends/trunk/webtools/new_upstream	(original)
+++ blends/trunk/webtools/new_upstream	Tue Aug  3 19:35:26 2010
@@ -19,4 +19,4 @@
 ./new_upstream.py $1 \
   | grep -v -e "^Unknown key" \
             -e "^Hint: WNPP for package" \
-  | mailx -s "Updatable packages" tille at debian.org
+  | mailx -s "Updatable packages of $1" tille at debian.org



More information about the Blends-commit mailing list