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

[or-cvs] r21070: {projects} Making localized package work, final touch (projects/gettor/lib/gettor)



Author: kaner
Date: 2009-11-30 16:22:17 -0500 (Mon, 30 Nov 2009)
New Revision: 21070

Modified:
   projects/gettor/lib/gettor/constants.py
   projects/gettor/lib/gettor/packages.py
   projects/gettor/lib/gettor/requests.py
Log:
Making localized package work, final touch


Modified: projects/gettor/lib/gettor/constants.py
===================================================================
--- projects/gettor/lib/gettor/constants.py	2009-11-30 18:16:53 UTC (rev 21069)
+++ projects/gettor/lib/gettor/constants.py	2009-11-30 21:22:17 UTC (rev 21070)
@@ -82,7 +82,7 @@
     us an email with the following text:
 
         tor-browser-bundle
-        Lang: zh-CN
+        Lang: zh_CN
 
     Or, if you want the tor-browser-bundle in farsi, write us an email
     with the following text:
@@ -105,7 +105,7 @@
     nl:     Dutch
     pl:     Polish
     ru:     Russian
-    zh-CN:  Chinese
+    zh_CN:  Chinese
 
     If you select no language, you will receive the english version.
 

Modified: projects/gettor/lib/gettor/packages.py
===================================================================
--- projects/gettor/lib/gettor/packages.py	2009-11-30 18:16:53 UTC (rev 21069)
+++ projects/gettor/lib/gettor/packages.py	2009-11-30 21:22:17 UTC (rev 21070)
@@ -25,7 +25,9 @@
 
 class Packages:
     #                "bundle name": ("single file regex", "split file regex")
-    packageRegex = { "tor-browser-bundle_en": ("tor-browser-.*_en-US.exe$", "tor-browser-.*_en-US_split"),
+    packageRegex = { "tor-browser-bundle": ("tor-browser-.*_en-US.exe$", "tor-browser-.*_en-US_split"),
+                     "tor-im-browser-bundle": ("tor-im-browser-.*_en-US.exe$", "tor-im-browser-.*_en-US_split"),
+                     "tor-browser-bundle_en": ("tor-browser-.*_en-US.exe$", "tor-browser-.*_en-US_split"),
                      "tor-im-browser-bundle_en": ("tor-im-browser-.*_en-US.exe$", "tor-im-browser-.*_en-US_split"),
                      "tor-browser-bundle_de": ("tor-browser-.*_de.exe$", "tor-browser-.*_de_split"),
                      "tor-im-browser-bundle_de": ("tor-im-browser-.*_de.exe$", "tor-im-browser-.*_de_split"),
@@ -47,8 +49,8 @@
                      "tor-im-browser-bundle_pt": ("tor-im-browser-.*_pt.exe$", "tor-im-browser-.*_pt_split"),
                      "tor-browser-bundle_ru": ("tor-browser-.*_ru.exe$", "tor-browser-.*_ru_split"),
                      "tor-im-browser-bundle_ru": ("tor-im-browser-.*_ru.exe$", "tor-im-browser-.*_ru_split"),
-                     "tor-browser-bundle_zh-CN": ("tor-browser-.*_zh-CN.exe$", "tor-browser-.*_zh-CN_split"),
-                     "tor-im-browser-bundle_zh-CN": ("tor-im-browser-.*_zh-CN.exe$", "tor-im-browser-.*_zh-CN_split"),
+                     "tor-browser-bundle_zh_CN": ("tor-browser-.*_zh-CN.exe$", "tor-browser-.*_zh-CN_split"),
+                     "tor-im-browser-bundle_zh_CN": ("tor-im-browser-.*_zh-CN.exe$", "tor-im-browser-.*_zh-CN_split"),
                      "source-bundle": ("tor-.*.tar.gz$", "Now to something completely different"),
                      "windows-bundle": ("vidalia-bundle-.*.exe$", "vidalia-bundle-.*_split"),
                      "macosx-ppc-bundle": ("vidalia-bundle-.*-ppc.dmg$", "vidalia-bundle-.*-ppc_split"),
@@ -93,8 +95,9 @@
         return self.packageList
 
     def buildPackages(self):
-        for filename in os.listdir(self.distDir):
-            for (pack, (regex_single, regex_split)) in self.packageRegex.items():
+        # Reverse this: Loop through package regex and look for match 
+        for (pack, (regex_single, regex_split)) in self.packageRegex.items():
+            for filename in os.listdir(self.distDir):
                 # Splitfile hacks. XXX: Refactor
                 if re.compile(regex_split).match(filename):
                     packSplitDir = None
@@ -131,6 +134,7 @@
                     zipFileName  = self.packDir + "/" + pack + ".z"
                     # If .asc file is there, build Zip file
                     if os.access(ascfile, os.R_OK):
+		    	print "ok: ", zipFileName
                         zip = zipfile.ZipFile(zipFileName, "w")
                         zip.write(file, os.path.basename(file))
                         zip.write(ascfile, os.path.basename(ascfile))

Modified: projects/gettor/lib/gettor/requests.py
===================================================================
--- projects/gettor/lib/gettor/requests.py	2009-11-30 18:16:53 UTC (rev 21069)
+++ projects/gettor/lib/gettor/requests.py	2009-11-30 21:22:17 UTC (rev 21070)
@@ -37,7 +37,7 @@
                        "nl": "Dutch",
                        "pl": "Polish",
                        "ru": "Russian",
-                       "zh-CN": "Chinese"  }
+                       "zh_CN": "Chinese"  }
 
     def __init__(self, config):
         """ Read message from stdin, parse all the stuff we want to know
@@ -76,6 +76,10 @@
         assert len(self.packages) > 0, "Empty package list"
 
     def parseMail(self):
+    	# First of all, check what language the user wants
+        if not self.gotPlusReq:
+	    self.findOutLang()
+        self.checkLang()
         # Parse line by line
         for line in email.Iterators.body_line_iterator(self.parsedMessage):
             # Skip quotes
@@ -89,23 +93,32 @@
             self.matchPackage(line)
             # Check for split delivery in line
             self.matchSplit(line)
-            # Change locale only if none is set so far
-            if not self.gotPlusReq:
-                self.matchLang(line)
             # Check if this is a command
             self.matchCommand(line)
 
-        self.checkLang()
+	# XXX HACK
+	self.torSpecialPackageExpansion()
     
         if self.returnPackage is None:
             log.info("User didn't select any packages")
-        else:
-            # This should go sometime XXX
-            self.torSpecialPackageExpansion()
 
         return (self.replytoAddress, self.replyLocale, self.returnPackage, \
                 self.splitDelivery, self.signature, self.commandaddress)
 
+    def findOutLang(self):
+        # Parse line by line
+        for line in email.Iterators.body_line_iterator(self.parsedMessage):
+            # Skip quotes
+            if line.startswith(">"):
+                continue
+            # Strip HTML from line
+            # XXX: Actually we should rather read the whole body into a string
+            #      and strip that. -kaner
+            line = self.stripTags(line)
+	    # Check to see if we got a language request with 'Lang:'
+	    self.matchLang(line)
+        
+
     def matchPlusAddress(self):
         match = re.search('(?<=\+)\w+', self.toAddress)
         if match:
@@ -164,6 +177,15 @@
                     % self.replytoAddress
             self.commandaddress = address
 
+    def torSpecialPackageExpansion(self):
+        # If someone wants one of the localizable packages, add language 
+        # suffix. This isn't nice because we're hard-coding package names here
+        # Attention: This needs to correspond to the  packages in packages.py
+        if self.returnPackage == "tor-browser-bundle" \
+                               or self.returnPackage == "tor-im-browser-bundle":
+            # "tor-browser-bundle" => "tor-browser-bundle_de"
+	    self.returnPackage = self.returnPackage + "_" + self.replyLocale 
+
     def checkLang(self):
         # Actually use a map here later XXX
         for (key, lang) in self.supportedLangs.items():
@@ -175,15 +197,6 @@
                         % (self.replyLocale, self.defaultLang))
             self.replyLocale = self.defaultLang
 
-    def torSpecialPackageExpansion(self):
-        # If someone wants one of the localizable packages, add language 
-        # suffix. This isn't nice because we're hard-coding package names here
-        # Attention: This needs to correspond to the  packages in packages.py
-        if self.returnPackage == "tor-browser-bundle" \
-                               or self.returnPackage == "tor-im-browser-bundle":
-            # "tor-browser-bundle" => "tor-browser-bundle_de"
-            self.returnPackage = self.returnPackage + "_" + self.replyLocale 
-
     def stripTags(self, string):
         """Simple HTML stripper"""
         return re.sub(r'<[^>]*?>', '', string)