[lint] remove uses of "print >> sys.stderr" (closes #1908571)
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Tue, 09 Aug 2011 09:43:26 +0200
changeset 7896 4c954e1e73ef
parent 7894 ad0eeb0f7a8d
child 7901 bdb81b1a8243
[lint] remove uses of "print >> sys.stderr" (closes #1908571)
bin/clone_deps.py
cwctl.py
devtools/__init__.py
i18n.py
misc/cwdesklets/rqlsensor/__init__.py
server/checkintegrity.py
server/migractions.py
server/serverconfig.py
server/test/unittest_rql2sql.py
setup.py
skeleton/setup.py
toolsutils.py
--- a/bin/clone_deps.py	Thu Sep 29 14:47:04 2011 +0200
+++ b/bin/clone_deps.py	Tue Aug 09 09:43:26 2011 +0200
@@ -63,7 +63,7 @@
     elif len(sys.argv) == 2:
         base_url = sys.argv[1]
     else:
-        print >> sys.stderr, 'usage %s [base_url]' %  sys.argv[0]
+        sys.stderr.write('usage %s [base_url]\n' %  sys.argv[0])
         sys.exit(1)
     print len(to_clone), 'repositories will be cloned'
     base_dir = normpath(join(dirname(__file__), pardir, pardir))
@@ -104,9 +104,9 @@
 To get started you may read http://docs.cubicweb.org/tutorials/base/index.html.
 """ % {'basedir': os.getcwd(), 'baseurl': base_url, 'sep': os.sep}
     if not_updated:
-        print >> sys.stderr, 'WARNING: The following repositories were not updated (no debian tag found):'
+        sys.stderr.write('WARNING: The following repositories were not updated (no debian tag found):\n')
         for path in not_updated:
-            print >> sys.stderr, '\t-', path
+            sys.stderr.write('\t-%s\n' % path)
 
 if __name__ == '__main__':
     main()
--- a/cwctl.py	Thu Sep 29 14:47:04 2011 +0200
+++ b/cwctl.py	Tue Aug 09 09:43:26 2011 +0200
@@ -155,7 +155,7 @@
             try:
                 status = max(status, self.run_arg(appid))
             except (KeyboardInterrupt, SystemExit):
-                print >> sys.stderr, '%s aborted' % self.name
+                sys.stderr.write('%s aborted\n' % self.name)
                 return 2 # specific error code
         sys.exit(status)
 
@@ -164,14 +164,14 @@
         try:
             status = cmdmeth(appid)
         except (ExecutionError, ConfigurationError), ex:
-            print >> sys.stderr, 'instance %s not %s: %s' % (
-                appid, self.actionverb, ex)
+            sys.stderr.write('instance %s not %s: %s\n' % (
+                    appid, self.actionverb, ex))
             status = 4
         except Exception, ex:
             import traceback
             traceback.print_exc()
-            print >> sys.stderr, 'instance %s not %s: %s' % (
-                appid, self.actionverb, ex)
+            sys.stderr.write('instance %s not %s: %s\n' % (
+                    appid, self.actionverb, ex))
             status = 8
         return status
 
@@ -548,20 +548,19 @@
         helper.poststop() # do this anyway
         pidf = config['pid-file']
         if not exists(pidf):
-            print >> sys.stderr, "%s doesn't exist." % pidf
+            sys.stderr.write("%s doesn't exist.\n" % pidf)
             return
         import signal
         pid = int(open(pidf).read().strip())
         try:
             kill(pid, signal.SIGTERM)
         except Exception:
-            print >> sys.stderr, "process %s seems already dead." % pid
+            sys.stderr.write("process %s seems already dead.\n" % pid)
         else:
             try:
                 wait_process_end(pid)
             except ExecutionError, ex:
-                print >> sys.stderr, ex
-                print >> sys.stderr, 'trying SIGKILL'
+                sys.stderr.write('%s\ntrying SIGKILL\n' % ex)
                 try:
                     kill(pid, signal.SIGKILL)
                 except Exception:
--- a/devtools/__init__.py	Thu Sep 29 14:47:04 2011 +0200
+++ b/devtools/__init__.py	Tue Aug 09 09:43:26 2011 +0200
@@ -581,7 +581,7 @@
         except BaseException:
             if self.dbcnx is not None:
                 self.dbcnx.rollback()
-            print >> sys.stderr, 'building', self.dbname, 'failed'
+            sys.stderr.write('building %s failed\n' % self.dbname)
             #self._drop(self.dbname)
             raise
 
--- a/i18n.py	Thu Sep 29 14:47:04 2011 +0200
+++ b/i18n.py	Tue Aug 09 09:43:26 2011 +0200
@@ -33,7 +33,7 @@
     output = open(output_file, 'w')
     for filepath in files:
         for match in re.finditer('i18n:(content|replace)="([^"]+)"', open(filepath).read()):
-            print >> output, '_("%s")' % match.group(2)
+            output.write('_("%s")' % match.group(2))
     output.close()
 
 
--- a/misc/cwdesklets/rqlsensor/__init__.py	Thu Sep 29 14:47:04 2011 +0200
+++ b/misc/cwdesklets/rqlsensor/__init__.py	Tue Aug 09 09:43:26 2011 +0200
@@ -56,8 +56,6 @@
     def call_action(self, action, path, args=[]):
         index = path[-1]
         output = self._new_output()
-#        import sys
-#        print >>sys.stderr, action, path, args
         if action=="enter-line":
             # change background
             output.set('resultbg[%s]' % index, 'yellow')
--- a/server/checkintegrity.py	Thu Sep 29 14:47:04 2011 +0200
+++ b/server/checkintegrity.py	Tue Aug 09 09:43:26 2011 +0200
@@ -36,9 +36,8 @@
 
 def notify_fixed(fix):
     if fix:
-        print >> sys.stderr, ' [FIXED]'
-    else:
-        print >> sys.stderr
+        sys.stderr.write(' [FIXED]')
+    sys.stderr.write('\n')
 
 def has_eid(session, sqlcursor, eid, eids):
     """return true if the eid is a valid eid"""
@@ -69,9 +68,9 @@
         eids[eid] = False
         return False
     elif len(result) > 1:
-        msg = '  More than one entity with eid %s exists in source !'
-        print >> sys.stderr, msg % eid
-        print >> sys.stderr, '  WARNING : Unable to fix this, do it yourself !'
+        msg = ('  More than one entity with eid %s exists in source !\n'
+               '  WARNING : Unable to fix this, do it yourself !\n')
+        sys.stderr.write(msg % eid)
     eids[eid] = True
     return True
 
@@ -169,8 +168,8 @@
     for row in cursor.fetchall():
         eid = row[0]
         if not has_eid(session, cursor, eid, eids):
-            msg = '  Entity with eid %s exists in the text index but in no source'
-            print >> sys.stderr, msg % eid,
+            msg = '  Entity with eid %s exists in the text index but in no source\n'
+            sys.stderr.write(msg % eid)
             if fix:
                 session.system_sql('DELETE FROM appears WHERE uid=%s;' % eid)
             notify_fixed(fix)
@@ -183,8 +182,8 @@
     for row in cursor.fetchall():
         eid = row[0]
         if not has_eid(session, cursor, eid, eids):
-            msg = '  Entity with eid %s exists in the system table but in no source'
-            print >> sys.stderr, msg % eid,
+            msg = '  Entity with eid %s exists in the system table but in no source\n'
+            sys.stderr.write(msg % eid)
             if fix:
                 session.system_sql('DELETE FROM entities WHERE eid=%s;' % eid)
             notify_fixed(fix)
@@ -213,7 +212,7 @@
             # no need to call has_eid
             if not eid in eids or not eids[eid]:
                 msg = '  Entity with eid %s exists in the %s table but not in the system table'
-                print >> sys.stderr, msg % (eid, eschema.type),
+                sys.stderr.write(msg % (eid, eschema.type))
                 if fix:
                     session.system_sql('DELETE FROM %s WHERE %s=%s;' % (table, column, eid))
                 notify_fixed(fix)
@@ -221,7 +220,7 @@
 
 def bad_related_msg(rtype, target, eid, fix):
     msg = '  A relation %s with %s eid %s exists but no such entity in sources'
-    print >> sys.stderr, msg % (rtype, target, eid),
+    sys.stderr.write(msg % (rtype, target, eid))
     notify_fixed(fix)
 
 
@@ -294,8 +293,8 @@
                 else:
                     rql = 'Any X WHERE NOT Y %s X, X is %s' % (rschema, etype)
                 for entity in session.execute(rql).entities():
-                    print >> sys.stderr, '%s #%s is missing mandatory %s relation %s' % (
-                        entity.__regid__, entity.eid, role, rschema),
+                    sys.stderr.write('%s #%s is missing mandatory %s relation %s' % (
+                            entity.__regid__, entity.eid, role, rschema))
                     if fix:
                         #if entity.cw_describe()['source']['uri'] == 'system': XXX
                         entity.cw_delete()
@@ -315,8 +314,8 @@
                 rql = 'Any X WHERE X %s NULL, X is %s, X cw_source S, S name "system"' % (
                     rschema, rdef.subject)
                 for entity in session.execute(rql).entities():
-                    print >> sys.stderr, '%s #%s is missing mandatory attribute %s' % (
-                        entity.__regid__, entity.eid, rschema),
+                    sys.stderr.write('%s #%s is missing mandatory attribute %s' % (
+                            entity.__regid__, entity.eid, rschema))
                     if fix:
                         entity.cw_delete()
                     notify_fixed(fix)
@@ -339,7 +338,7 @@
                                         % (eidcolumn, table, column))
             for eid, in cursor.fetchall():
                 msg = '  %s with eid %s has no %s'
-                print >> sys.stderr, msg % (etype, eid, rel),
+                sys.stderr.write(msg % (etype, eid, rel))
                 if fix:
                     session.system_sql("UPDATE %s SET %s=%%(v)s WHERE %s=%s ;"
                                        % (table, column, eidcolumn, eid),
--- a/server/migractions.py	Thu Sep 29 14:47:04 2011 +0200
+++ b/server/migractions.py	Tue Aug 09 09:43:26 2011 +0200
@@ -160,7 +160,7 @@
             return super(ServerMigrationHelper, self).cmd_process_script(
                   migrscript, funcname, *args, **kwargs)
         except ExecutionError, err:
-            print >> sys.stderr, "-> %s" % err
+            sys.stderr.write("-> %s\n" % err)
         except BaseException:
             self.rollback()
             raise
--- a/server/serverconfig.py	Thu Sep 29 14:47:04 2011 +0200
+++ b/server/serverconfig.py	Tue Aug 09 09:43:26 2011 +0200
@@ -302,9 +302,7 @@
                         if attr != 'adapter':
                             self.error('skip unknown option %s in sources file')
                 sconfig = _sconfig
-            print >> stream, '[%s]' % section
-            print >> stream, generate_source_config(sconfig)
-            print >> stream
+            stream.write('[%s]\n%s\n' % (section, generate_source_config(sconfig)))
         restrict_perms_to_user(sourcesfile)
 
     def pyro_enabled(self):
--- a/server/test/unittest_rql2sql.py	Thu Sep 29 14:47:04 2011 +0200
+++ b/server/test/unittest_rql2sql.py	Tue Aug 09 09:43:26 2011 +0200
@@ -46,12 +46,12 @@
     for modname in drivers[driver]:
         try:
             if not quiet:
-                print >> sys.stderr, 'Trying %s' % modname
+                sys.stderr.write('Trying %s\n' % modname)
             module = db.load_module_from_name(modname, use_sys=False)
             break
         except ImportError:
             if not quiet:
-                print >> sys.stderr, '%s is not available' % modname
+                sys.stderr.write('%s is not available\n' % modname)
             continue
     else:
         return mock_object(STRING=1, BOOLEAN=2, BINARY=3, DATETIME=4, NUMBER=5), drivers[driver][0]
--- a/setup.py	Thu Sep 29 14:47:04 2011 +0200
+++ b/setup.py	Tue Aug 09 09:43:26 2011 +0200
@@ -119,7 +119,7 @@
             src = '%s/%s' % (directory, filename)
             dest = to_dir + src[len(from_dir):]
             if verbose:
-               print >> sys.stderr, src, '->', dest
+               sys.stderr.write('%s -> %s\n' % (src, dest))
             if os.path.isdir(src):
                 if not exists(dest):
                     os.mkdir(dest)
--- a/skeleton/setup.py	Thu Sep 29 14:47:04 2011 +0200
+++ b/skeleton/setup.py	Tue Aug 09 09:43:26 2011 +0200
@@ -105,7 +105,7 @@
             src = join(directory, filename)
             dest = to_dir + src[len(from_dir):]
             if verbose:
-                print >> sys.stderr, src, '->', dest
+                sys.stderr.write('%s -> %s\n' % (src, dest))
             if os.path.isdir(src):
                 if not exists(dest):
                     os.mkdir(dest)
--- a/toolsutils.py	Thu Sep 29 14:47:04 2011 +0200
+++ b/toolsutils.py	Tue Aug 09 09:43:26 2011 +0200
@@ -180,7 +180,7 @@
                            'Section %s is defined more than once' % section
                     config[section] = current = {}
                     continue
-                print >> sys.stderr, 'ignoring malformed line\n%r' % line
+                sys.stderr.write('ignoring malformed line\n%r\n' % line)
                 continue
             option = option.strip().replace(' ', '_')
             value = value.strip()