[damned-lies] Modernized some syntax, removed 'print as statement'
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Modernized some syntax, removed 'print as statement'
- Date: Fri, 11 Jan 2013 15:00:54 +0000 (UTC)
commit 37caabc7777e9d1e37a83beaf295a4b3cd7451a5
Author: Claude Paroz <claude 2xlibre net>
Date: Fri Jan 11 15:58:35 2013 +0100
Modernized some syntax, removed 'print as statement'
languages/management/commands/load-plurals.py | 2 +-
stats/management/commands/copy-release.py | 4 ++--
stats/management/commands/migrate-to-git.py | 4 ++--
stats/management/commands/update-stats.py | 20 ++++++++++----------
stats/models.py | 15 ++++++++-------
stats/potdiff.py | 2 +-
stats/tests/__init__.py | 6 ++++--
stats/tests/fixture_factory.py | 2 +-
stats/utils.py | 5 +++--
9 files changed, 32 insertions(+), 28 deletions(-)
---
diff --git a/languages/management/commands/load-plurals.py b/languages/management/commands/load-plurals.py
index 9d0fed1..835f66c 100644
--- a/languages/management/commands/load-plurals.py
+++ b/languages/management/commands/load-plurals.py
@@ -128,4 +128,4 @@ class Command(BaseCommand):
continue
lang.plurals = plurals[locale]
lang.save()
- print "Plural form loaded"
+ return "Plural form loaded"
diff --git a/stats/management/commands/copy-release.py b/stats/management/commands/copy-release.py
index 69d4fc0..931afa0 100644
--- a/stats/management/commands/copy-release.py
+++ b/stats/management/commands/copy-release.py
@@ -33,7 +33,7 @@ class Command(BaseCommand):
try:
rel_to_copy = Release.objects.get(name=args[0])
- except:
+ except Release.DoesNotExist:
raise CommandError("No release named '%s'" % args[0])
new_rel = Release(name=args[1], description=args[1], string_frozen=False, status=rel_to_copy.status)
@@ -47,4 +47,4 @@ class Command(BaseCommand):
branch = cat.branch
new_rel.category_set.add(Category(release=new_rel, branch=branch, name=cat.name))
- print "New release '%s' created" % args[1]
+ return "New release '%s' created" % args[1]
diff --git a/stats/management/commands/migrate-to-git.py b/stats/management/commands/migrate-to-git.py
index 1b6d928..a5b6208 100644
--- a/stats/management/commands/migrate-to-git.py
+++ b/stats/management/commands/migrate-to-git.py
@@ -28,7 +28,7 @@ class Command(BaseCommand):
try:
head_branch.save() # Save will do a checkout
except Exception, e:
- print "Unable to save master branch for module '%s': %s" % (module.name, e)
+ self.stderr.write("Unable to save master branch for module '%s': %s" % (module.name, e))
continue
for branch in module.branch_set.exclude(name='master'):
@@ -40,7 +40,7 @@ class Command(BaseCommand):
try:
utils.run_shell_command(cmd, raise_on_error=True)
except Exception, e:
- print "Unable to checkout branch '%s' of module '%s': %s" % (branch.name, module.name, e)
+ self.stderr.write("Unable to checkout branch '%s' of module '%s': %s" % (branch.name, module.name, e))
continue
branch.update_stats(force=False)
diff --git a/stats/management/commands/update-stats.py b/stats/management/commands/update-stats.py
index e5f0514..cbfc860 100644
--- a/stats/management/commands/update-stats.py
+++ b/stats/management/commands/update-stats.py
@@ -37,13 +37,13 @@ class Command(BaseCommand):
branch_arg, module_arg))
if branch.module.archived and not options['force']:
raise CommandError("The module '%s' is archived." % module_arg)
- print "Updating stats for %s.%s..." % (module_arg, branch_arg)
+ self.stdout.write("Updating stats for %s.%s..." % (module_arg, branch_arg))
try:
branch.update_stats(options['force'])
except Exception:
tbtext = traceback.format_exc()
mail_admins("Error while updating %s %s" % (module_arg, branch_arg), tbtext)
- print >> sys.stderr, "Error during updating, mail sent to admins"
+ raise CommandError("Error during updating, mail sent to admins")
elif len(args) == 1:
# Update all branches of a module
@@ -51,13 +51,13 @@ class Command(BaseCommand):
module = Module.objects.get(name=args[0])
except Module.DoesNotExist:
raise CommandError("Unable to find a module named '%s' in the database" % args[0])
- print "Updating stats for %s..." % (module.name)
+ self.stdout.write("Updating stats for %s..." % (module.name))
for branch in module.branch_set.all():
try:
branch.update_stats(options['force'])
- except:
- print >> sys.stderr, traceback.format_exc()
- print "Error while updating stats for %s (branch '%s')" % (module.name, branch.name)
+ except Exception:
+ raise CommandError("Error while updating stats for %s (branch '%s')" % (
+ module.name, branch.name))
else:
# Update all modules
if options['non-gnome']:
@@ -68,13 +68,13 @@ class Command(BaseCommand):
modules = modules.exclude(archived=True)
for mod in modules:
- print "Updating stats for %s..." % (mod.name)
+ self.stdout.write("Updating stats for %s..." % mod.name)
branches = Branch.objects.filter(module__name=mod)
for branch in branches.all():
try:
branch.update_stats(options['force'])
- except:
- print >> sys.stderr, traceback.format_exc()
- print "Error while updating stats for %s (branch '%s')" % (mod.name, branch.name)
+ except Exception:
+ raise CommandError("Error while updating stats for %s (branch '%s')" % (
+ mod.name, branch.name))
return "Update completed.\n"
diff --git a/stats/models.py b/stats/models.py
index 932c604..9569bcd 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# Copyright (c) 2008-2011 Claude Paroz <claude 2xlibre net>.
+# Copyright (c) 2008-2013 Claude Paroz <claude 2xlibre net>.
# Copyright (c) 2008 Stephane Raimbault <stephane raimbault gmail com>.
#
# This file is part of Damned Lies.
@@ -19,7 +19,7 @@
# along with Damned Lies; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from __future__ import with_statement
+import logging
import os, sys, re
import threading
from time import sleep
@@ -420,7 +420,8 @@ class Branch(models.Model):
potfile, errs, pot_method = utils.generate_doc_pot_file(
domain_path, dom.potbase(), self.module.name)
else:
- print >> sys.stderr, "Unknown domain type '%s', ignoring domain '%s'" % (dom.dtype, dom.name)
+ logging.error("Unknown domain type '%s', ignoring domain '%s'" % (
+ dom.dtype, dom.name))
continue
errors.extend(errs)
linguas = dom.get_linguas(self.co_path())
@@ -439,7 +440,8 @@ class Branch(models.Model):
# *****************************
previous_pot = os.path.join(self.output_dir(dom.dtype), dom.potbase() + "." + self.name + ".pot")
if not potfile:
- if settings.DEBUG: print >> sys.stderr, "Can't generate POT file for %s/%s." % (self.module.name, dom.directory)
+ logging.error("Can't generate POT file for %s/%s." % (
+ self.module.name, dom.directory))
if os.access(previous_pot, os.R_OK):
# Use old POT file
potfile = previous_pot
@@ -508,7 +510,7 @@ class Branch(models.Model):
fig_errors = utils.check_identical_figures(fig_stats, domain_path, lang)
langstats['errors'].extend(fig_errors)
- if settings.DEBUG: print >>sys.stderr, lang + ":\n" + str(langstats)
+ logging.debug("%s:\n%s" % (lang, str(langstats)))
# Save in DB
try:
stat = Statistics.objects.get(language__locale=lang, branch=self, domain=dom)
@@ -647,8 +649,7 @@ class Branch(models.Model):
})
# Run command(s)
- if settings.DEBUG:
- print >>sys.stdout, "Checking '%s.%s' out to '%s'..." % (module_name, self.name, modulepath)
+ logging.debug("Checking '%s.%s' out to '%s'..." % (module_name, self.name, modulepath))
# Do not allow 2 checkouts to run in parallel on the same branch
self.checkout_lock.acquire()
try:
diff --git a/stats/potdiff.py b/stats/potdiff.py
index bd14e35..ca7fcc2 100644
--- a/stats/potdiff.py
+++ b/stats/potdiff.py
@@ -145,4 +145,4 @@ def _parse_contents(contents):
if __name__ == "__main__":
import sys
- print "\n".join(diff(sys.argv[1], sys.argv[2]))
+ print("\n".join(diff(sys.argv[1], sys.argv[2])))
diff --git a/stats/tests/__init__.py b/stats/tests/__init__.py
index 979332c..5f9e4b4 100644
--- a/stats/tests/__init__.py
+++ b/stats/tests/__init__.py
@@ -203,8 +203,10 @@ class ModuleTestCase(TestCase):
response = self.client.get('/module/po/gnome-hello/po/master/ta-reduced.po')
except OSError, e:
if "msginit" in str(e):
- print "You are probably running an unpatched version of the translate-toolkit"
- print "See http://bugs.locamotion.org/show_bug.cgi?id=2129"
+ self.fail(
+ "You are probably running an unpatched version of the translate-toolkit. "
+ "See http://bugs.locamotion.org/show_bug.cgi?id=2129"
+ )
return
else:
raise e
diff --git a/stats/tests/fixture_factory.py b/stats/tests/fixture_factory.py
index 4dff4e5..55ce7c6 100644
--- a/stats/tests/fixture_factory.py
+++ b/stats/tests/fixture_factory.py
@@ -168,4 +168,4 @@ class FixtureFactory(TestCase):
call_command('dumpdata', *['auth.User', 'people', 'teams', 'languages', 'stats'],
indent=1, format='json', stdout=out_file)
out_file.close()
- print "Fixture created in the file %s" % out_file.name
+ print("Fixture created in the file %s" % out_file.name)
diff --git a/stats/utils.py b/stats/utils.py
index 40b8982..2e7bee8 100644
--- a/stats/utils.py
+++ b/stats/utils.py
@@ -21,6 +21,7 @@
import sys, os, re, time
import hashlib
+import logging
from itertools import islice
from subprocess import Popen, PIPE
import errno
@@ -121,7 +122,7 @@ def ellipsize(val, length):
return val
def run_shell_command(cmd, env=None, input_data=None, raise_on_error=False):
- if settings.DEBUG: print >>sys.stderr, cmd
+ logging.debug(cmd)
stdin = None
if input_data:
@@ -138,7 +139,7 @@ def run_shell_command(cmd, env=None, input_data=None, raise_on_error=False):
raise
(output, errout) = pipe.communicate()
status = pipe.returncode
- if settings.DEBUG: print >>sys.stderr, output + errout
+ logging.debug(output + errout)
if raise_on_error and status != STATUS_OK:
raise OSError(status, errout)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]