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

[tor-commits] [gettor/master] Better format for sending the links



commit c745cbd07d09b368b058b208a51c5ae66e8aa736
Author: ilv <ilv@xxxxxxxxxxxxxxxxxxxxxxxx>
Date:   Thu Aug 27 15:16:08 2015 -0300

    Better format for sending the links
---
 gettor/core.py                      |   86 +++++++++++++++++++++++++++++++----
 gettor/smtp.py                      |   19 +++++---
 lang/core/i18n/en/en.po             |    2 +-
 lang/smtp/i18n/en/LC_MESSAGES/en.po |    4 +-
 4 files changed, 94 insertions(+), 17 deletions(-)

diff --git a/gettor/core.py b/gettor/core.py
index 219fed2..49fbbb2 100644
--- a/gettor/core.py
+++ b/gettor/core.py
@@ -197,7 +197,18 @@ class Core(object):
 
         # read the links files using ConfigParser
         # see the README for more details on the format used
-        links = []
+        links_files = []
+        
+        links32 = {}
+        links64 = {}
+        
+        # for the message to be sent
+        if osys == 'windows':
+            arch = '32/64'
+        elif osys == 'osx':
+            arch = '64'
+        else:
+            arch = '32'
 
         # look for files ending with .links
         p = re.compile('.*\.links$')
@@ -205,7 +216,7 @@ class Core(object):
         for name in os.listdir(self.linksdir):
             path = os.path.abspath(os.path.join(self.linksdir, name))
             if os.path.isfile(path) and p.match(path):
-                links.append(path)
+                links_files.append(path)
 
         # let's create a dictionary linking each provider with the links
         # found for os and lc. This way makes it easy to check if no
@@ -216,7 +227,7 @@ class Core(object):
         spt = '=' * 72
 
         # reading links from providers directory
-        for name in links:
+        for name in links_files:
             # we're reading files listed on linksdir, so they must exist!
             config = ConfigParser.ConfigParser()
             # but just in case they don't
@@ -231,14 +242,34 @@ class Core(object):
 
                 # check if current provider pname has links for os in lc
                 providers[pname] = config.get(osys, lc)
-                # avoid showing it all together
-                providers[pname] = providers[pname].replace(",", "")
-                providers[pname] = providers[pname].replace("$", "\n\n")
+            except ConfigParser.Error as e:
+                # we should at least have the english locale available
+                self.log.error("Request for %s, returning 'en' instead" % lc)
+                providers[pname] = config.get(osys, 'en')
+            try:
+                #test = providers[pname].split("$")
+                #self.log.debug(test)
+                if osys == 'linux':
+                    t32, t64 = [t for t in providers[pname].split(",") if t]
+                    
+                    link, signature, chs32 = [l for l in t32.split("$") if l]
+                    links32[link] = signature
+
+                    link, signature, chs64 = [l for l in t64.split("$") if l]
+                    links64[link] = signature
+                    
+                else:
+                    link, signature, chs32 = [l for l in providers[pname].split("$") if l]
+                    links32[link] = signature
+                    
+                #providers[pname] = providers[pname].replace(",", "")
+                #providers[pname] = providers[pname].replace("$", "\n\n")
 
                 # all packages are signed with same key
                 # (Tor Browser developers)
                 fingerprint = config.get('key', 'fingerprint')
-                fingerprint_msg = self._get_msg('fingerprint', lc)
+                # for now, english messages only
+                fingerprint_msg = self._get_msg('fingerprint', 'en')
                 fingerprint_msg = fingerprint_msg % fingerprint
             except ConfigParser.Error as e:
                 raise InternalError("%s" % str(e))
@@ -246,10 +277,47 @@ class Core(object):
         # create the final links list with all providers
         all_links = []
 
+        msg = "Tor Browser %s-bit:" % arch
+        for link in links32:
+            msg = "%s\n%s" % (msg, link)
+            
+        all_links.append(msg)
+        
+        if osys == 'linux':
+            msg = "\n\n\nTor Browser 64-bit:"
+            for link in links64:
+                msg = "%s\n%s" % (msg, link)
+        
+            all_links.append(msg)
+        
+        msg = "\n\n\nTor Browser's signature %s-bit (in the same order):" %\
+              arch
+        for link in links32:
+            msg = "%s\n%s" % (msg, links32[link])
+        
+        all_links.append(msg)
+        
+        if osys == 'linux':
+            msg = "\n\n\nTor Browser's signature 64-bit:"
+            for link in links64:
+                msg = "%s\n%s" % (msg, links64[link])
+            
+            all_links.append(msg)
+        
+        msg = "\n\n\nSHA256 of Tor Browser %s-bit (advanced): %s\n" %\
+              (arch, chs32)
+        all_links.append(msg)
+        
+        if osys == 'linux':
+            msg = "SHA256 of Tor Browser 64-bit (advanced): %s\n" % chs64
+            all_links.append(msg)
+
+        """
         for key in providers.keys():
             # get more friendly description of the provider
             try:
-                provider_desc = self._get_msg('provider_desc', lc)
+                # for now, english messages only
+                provider_desc = self._get_msg('provider_desc', 'en')
                 provider_desc = provider_desc % key
 
                 all_links.append(
@@ -258,6 +326,7 @@ class Core(object):
                 )
             except ConfigError as e:
                 raise InternalError("%s" % str(e))
+        """
 
         # add fingerprint after the links
         all_links.append(fingerprint_msg)
@@ -405,6 +474,7 @@ class Core(object):
         """Add request to database."""
         self.log.debug("Trying to add request to database")
         try:
+            self.db.connect()
             self.db.add_request()
             self.log.debug("Request added!")
         except db.DBError as e:
diff --git a/gettor/smtp.py b/gettor/smtp.py
index 4db3ac7..34477ef 100644
--- a/gettor/smtp.py
+++ b/gettor/smtp.py
@@ -76,7 +76,7 @@ class SMTP(object):
         config = ConfigParser.ConfigParser()
 
         if cfg is None or not os.path.isfile(cfg):
-            cfg = DEFAULT_CONFIG_FILE
+            cfg = default_cfg
 
         try:
             with open(cfg) as f:
@@ -240,7 +240,12 @@ class SMTP(object):
         """
         req = self._parse_text(msg)
         lc = self._get_lc(addr)
-        req['lc'] = lc
+        supported_lc = self.core.get_supported_lc()
+
+        if lc in supported_lc:
+            req['lc'] = lc
+        else:
+            req['lc'] = 'en'
 
         return req
 
@@ -361,8 +366,8 @@ class SMTP(object):
         """
         # obtain the content in the proper language and send it
         try:
-            links_subject = self._get_msg('links_subject', lc)
-            links_msg = self._get_msg('links_msg', lc)
+            links_subject = self._get_msg('links_subject', 'en')
+            links_msg = self._get_msg('links_msg', 'en')
             links_msg = links_msg % (os, lc, links)
 
             self._send_email(
@@ -490,7 +495,7 @@ class SMTP(object):
                     self.log.debug("Trying to send help...")
                     # make sure we can send emails
                     try:
-                        self._send_help(req['lc'], our_addr, norm_from_addr)
+                        self._send_help('en', our_addr, norm_from_addr)
                         status = 'success'
                     except SendEmailError as e:
                         status = 'internal_error'
@@ -503,7 +508,7 @@ class SMTP(object):
                     self.log.debug("Trying to send the mirrors...")
                     # make sure we can send emails
                     try:
-                        self._send_mirrors(req['lc'], our_addr, norm_from_addr)
+                        self._send_mirrors('en', our_addr, norm_from_addr)
                         status = 'success'
                     except SendEmailError as e:
                         status = 'internal_error'
@@ -519,7 +524,7 @@ class SMTP(object):
                             'SMTP', req['os'], req['lc']
                         )
                     # if core fails, we fail too
-                    except (core.InternalError, core.ConfigurationError) as e:
+                    except (core.InternalError, core.ConfigError) as e:
                         status = 'core_error'
                         self.log.debug("FAILED: %s" % str(e))
                         # something went wrong with the core
diff --git a/lang/core/i18n/en/en.po b/lang/core/i18n/en/en.po
index b8d4509..0b28a70 100644
--- a/lang/core/i18n/en/en.po
+++ b/lang/core/i18n/en/en.po
@@ -2,7 +2,7 @@ domain "en"
 
 #: Fingerprint message
 msgid "fingerprint"
-msgstr "Fingerprint of the key used to sign Tor Browser:\n%s"
+msgstr "Fingerprint of key used to sign Tor Browser (advanced): %s"
 
 #: Provider description
 msgid "provider_desc"
diff --git a/lang/smtp/i18n/en/LC_MESSAGES/en.po b/lang/smtp/i18n/en/LC_MESSAGES/en.po
index dcb2e35..ee6a24e 100644
--- a/lang/smtp/i18n/en/LC_MESSAGES/en.po
+++ b/lang/smtp/i18n/en/LC_MESSAGES/en.po
@@ -28,6 +28,7 @@ Below are the links for your request (Tor Browser for %s, %s package):\n\
 \n\
 %s\n\
 \n\
+===========================================================================\n\
 Still need help? If you have any questions, trouble connecting to Tor\n\
 network, or need to talk to a human, please contact our support team at:\n\
 \n\
@@ -63,7 +64,8 @@ Please reply to this message with one of the options below:\n\
     windows\n\
     linux\n\
     osx\n\
+    mirrors\n\
 \n\
-And I will send you the download instructions quickly.\n\
+And I will send you the download/access instructions quickly.\n\
 \n\
 Tip: Just send a blank reply to this message if you are not sure."



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits