[damned-lies] Allow retrieving pot file by http



commit 07eedf1fcc794a1b14b5f9b154f2733022f2bac4
Author: Claude Paroz <claude 2xlibre net>
Date:   Thu Aug 4 19:41:44 2011 +0200

    Allow retrieving pot file by http

 stats/models.py         |   13 +++++++++++++
 stats/tests/__init__.py |   40 +++++++++++++++++++++++-----------------
 stats/views.py          |    2 +-
 3 files changed, 37 insertions(+), 18 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index 7a7aa66..f71a88a 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -778,10 +778,23 @@ class Domain(models.Model):
         if not self.pot_method: # default is intltool
             env = {"XGETTEXT_ARGS": "\"--msgid-bugs-address=%s\"" % self.module.get_bugs_enter_url()}
             pot_command = "intltool-update -g '%(domain)s' -p" % {'domain': self.potbase()}
+        elif self.pot_method.startswith('http://'):
+            # Get POT from URL and save file locally
+            import urllib2
+            req = urllib2.Request(self.pot_method)
+            try:
+                handle = urllib2.urlopen(req)
+            except URLError, e:
+                return "", (("error", ugettext_noop("Error retrieving pot file from URL.")),)
+            potfile = os.path.join(vcs_path, self.potbase() + ".pot")
+            with open(potfile, 'w') as f:
+                f.write(handle.read())
+            pot_command = ":" # noop
         elif self.module.name == 'damned-lies':
             # special case for d-l, pot file should be generated from running instance dir
             podir = "."
             vcs_path = "./po"
+
         command = "cd \"%(dir)s\" && %(pot_command)s" % {
             "dir" : podir,
             "pot_command" : pot_command,
diff --git a/stats/tests/__init__.py b/stats/tests/__init__.py
index 5b06b12..7a74096 100644
--- a/stats/tests/__init__.py
+++ b/stats/tests/__init__.py
@@ -62,29 +62,26 @@ class ModuleTestCase(TestCase):
     def setUp(self):
         # TODO: load bulk data from fixtures
         Branch.checkout_on_creation = False
-        self.mod = Module(name="gnome-hello",
-                  bugs_base="http://bugzilla.gnome.org";,
-                  bugs_product="test", # This product really exists
-                  bugs_component="test",
-                  vcs_type="git",
-                  vcs_root="git://git.gnome.org/gnome-hello",
-                  vcs_web="http://git.gnome.org/browse/gnome-hello/";)
+        self.mod = Module.objects.create(
+            name="gnome-hello",
+            bugs_base="http://bugzilla.gnome.org";,
+            bugs_product="test", # This product really exists
+            bugs_component="test",
+            vcs_type="git",
+            vcs_root="git://git.gnome.org/gnome-hello",
+            vcs_web="http://git.gnome.org/browse/gnome-hello/";)
         self.mod.save()
-        dom = Domain(module=self.mod, name='po', description='UI Translations', dtype='ui', directory='po')
-        dom.save()
-        dom = Domain(module=self.mod, name='help', description='User Guide', dtype='doc', directory='help')
-        dom.save()
+        dom = Domain.objects.create(module=self.mod, name='po', description='UI Translations', dtype='ui', directory='po')
+        dom = Domain.objects.create(module=self.mod, name='help', description='User Guide', dtype='doc', directory='help')
 
         self.b = Branch(name='master', module=self.mod)
         self.b.save(update_statistics=False)
 
-        self.rel = Release(name='gnome-2-24', status='official',
-                      description='GNOME 2.24 (stable)',
-                      string_frozen=True)
-        self.rel.save()
+        self.rel = Release.objects.create(
+            name='gnome-2-24', status='official',
+            description='GNOME 2.24 (stable)', string_frozen=True)
 
-        self.cat = Category(release=self.rel, branch=self.b, name='desktop')
-        self.cat.save()
+        self.cat = Category.objects.create(release=self.rel, branch=self.b, name='desktop')
 
     def tearDown(self):
         if os.access(self.co_path, os.X_OK):
@@ -175,6 +172,15 @@ class ModuleTestCase(TestCase):
         self.assertEqual(len(res), 2)
         self.assertEqual(res[0]['path'], "figures/gnome.png")
 
+    def testHttpPot(self):
+        dom = Domain.objects.create(
+            module=self.mod, name='http-po',
+            description='UI Translations', dtype='ui',
+            pot_method='http://l10n.gnome.org/POT/damned-lies.master/damned-lies.master.pot')
+        self.b.checkout()
+        potfile, errs = dom.generate_pot_file(self.b)
+        self.assertTrue(os.path.exists(potfile))
+
     def testIdenticalFigureWarning(self):
         """ Detect warning if translated figure is identical to original figure """
         self.b.checkout()
diff --git a/stats/views.py b/stats/views.py
index 965cb5d..124682a 100644
--- a/stats/views.py
+++ b/stats/views.py
@@ -152,7 +152,7 @@ def docimages(request, module_name, potbase, branch_name, langcode):
                                       domain__name=potbase,
                                       language__locale=langcode)
     except Statistics.DoesNotExist:
-        pot_stat = Statistics.objects.get(
+        pot_stat = get_object_or_404(Statistics,
             branch__module=mod.id,
             branch__name=branch_name,
             domain__name=potbase,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]