Anonymous avatar Anonymous committed 9a077e4

removed a circular dependency for bulk uploading

Comments (0)

Files changed (4)

dragoman/lib/client.py

 
 from dragoman.lib.urltemplate import Url
 from dragoman.lib.httpcache import BsddbCache
+from dragoman.lib.gettext_tools import GettextCatalog
 
 class RequestFailure(Exception):
     def __init__(self, msg, resp, content):
         self.catalog = catalog
         self.lang = lang
         self.service = service
+        print 'bulk_by_po' in open(__file__, 'r').read()
 
     def _url(self, phrase=None):
         params = {
             return True
         raise RequestFailure('bulk add failed', resp, content)
 
+	def bulk_by_po(self, po_file):
+		extra_keys = [
+            'extracted_comment', 'reference', 'flag',
+            'previous_untranslated_string',
+        ]
+        po = GettextCatalog(pofile, lang)
+        phrases = []
+        for m in po.messages:
+            extra = [getattr(po, k) for k in extra_keys if hasattr(po, k)]
+            extra = dict(zip(extra_keys, extra))
+            doc = { 'phrase': m['msgid'], 'translation': m['msgstr'] }
+            doc.update(extra)
+            phrases.append(doc)
+        return self.bulk(phrases)
+		
+
 
 class Catalog(object):
     def __init__(self, name, service):

dragoman/lib/gettext_tools.py

 
 from pprint import pformat, pprint
 
-from dragoman.lib.client import Connection, RequestFailure
+# from dragoman.lib.client import Connection, RequestFailure
 
 
 # the different states
         self.messages = p.messages
             
 
-class GettextImporter(object):
+# class GettextImporter(object):
 
-    def __init__(self, base_url, catalog):
-        self.base_url = base_url
-        self.client = Connection(base_url)[catalog]
+#     def __init__(self, base_url, catalog):
+#         self.base_url = base_url
+#         self.client = Connection(base_url)[catalog]
 
-    def do_import(self, pofile, lang):
-        extra_keys = [
-            'extracted_comment', 'reference', 'flag',
-            'previous_untranslated_string',
-        ]
-        po = GettextCatalog(pofile, lang)
-        mo = self.client[lang]
-        phrases = []
-        for m in po.messages:
-            extra = [getattr(po, k) for k in extra_keys if hasattr(po, k)]
-            extra = dict(zip(extra_keys, extra))
-            doc = { 'phrase': m['msgid'], 'translation': m['msgstr'] }
-            doc.update(extra)
-            phrases.append(doc)
-        return mo.bulk(phrases)
+#     def do_import(self, pofile, lang):
+#         extra_keys = [
+#             'extracted_comment', 'reference', 'flag',
+#             'previous_untranslated_string',
+#         ]
+#         po = GettextCatalog(pofile, lang)
+#         mo = self.client[lang]
+#         phrases = []
+#         for m in po.messages:
+#             extra = [getattr(po, k) for k in extra_keys if hasattr(po, k)]
+#             extra = dict(zip(extra_keys, extra))
+#             doc = { 'phrase': m['msgid'], 'translation': m['msgstr'] }
+#             doc.update(extra)
+#             phrases.append(doc)
+#         return mo.bulk(phrases)
 
 
 if __name__ == '__main__':

dragoman/lib/storage.py

     def get(self, abbrev):
         db = get_db()[self.collection]
         result = db.find_one({'abbrev': abbrev})
-        return result['name']
+        if result:
+            return result['name']
+        return None
     __getitem__ = get
 
     def __contains__(self, abbrev):
 
 from dragoman.lib.client import Connection
 
+
 @task
 def run():
     runner.main('devel.yaml', 'dragoman.main', False)
 def run_testmode():
     runner.main('unittest.yaml', 'dragoman.main', False)
 
-@task
-@consume_args
-def upload_po():
-    usage = 'paver upload_po POFILE LANGUAGE URL'
-    try:
-        po, lang, url = options.args[:3]
-    except ValueError:
-        print usage
-        return
-    c = Connection(url)
-    
-    
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.