[tor-commits] [gettor/master] Send out the short user manual together with GetTor packages.

kaner at torproject.org kaner at torproject.org
Mon Oct 24 15:43:44 UTC 2011


commit 96948a01265142e39022a704dfb228ab3dbb6696
Author: Christian Fromme <kaner at strace.org>
Date:   Wed Oct 19 21:43:24 2011 +0200

    Send out the short user manual together with GetTor packages.
    Fixes #4163.
---
 lib/gettor/packages.py  |   12 ++++++++++++
 lib/gettor/responses.py |   26 ++++++++++++++++++++++++++
 lib/gettor/utils.py     |    3 +++
 3 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/lib/gettor/packages.py b/lib/gettor/packages.py
index cbfddb4..0f205c1 100644
--- a/lib/gettor/packages.py
+++ b/lib/gettor/packages.py
@@ -11,6 +11,7 @@ import gettor.config
 import gettor.utils
 import re
 import glob
+import shutil
 
 # Stolen from Mike's TorCtl:
 class RouterVersion:
@@ -60,6 +61,7 @@ class Packages:
         self.packageList = {}
         self.distDir = os.path.join(config.BASEDIR, "dist")
         self.packDir = os.path.join(config.BASEDIR, "packages")
+        self.docDir = os.path.join(config.BASEDIR, "doc")
         self.initRsync(config.RSYNC_MIRROR, silent)
         self.packageList = config.PACKAGES
 
@@ -194,6 +196,16 @@ class Packages:
         logging.debug("All split files for package %s created." % pack)
         return True
 
+    def copyManuals(self):
+        """Copy the short user manuals to their destination directory
+        """
+        manualDir = os.path.join(self.distDir, "manual")
+        gettor.utils.createDir(self.docDir)
+        for f in glob.glob(os.path.join(manualDir, "*.xhtml")):
+            copyTo = os.path.join(self.docDir, os.path.basename(f))
+            shutil.copyfile(f, copyTo)
+            logging.debug("%s copied." % f)
+
     def getPart(self, fileName):
         """Helper function: Extract the `partXX' part of the file name.
         """
diff --git a/lib/gettor/responses.py b/lib/gettor/responses.py
index 6a5adf7..94d8400 100644
--- a/lib/gettor/responses.py
+++ b/lib/gettor/responses.py
@@ -260,6 +260,7 @@ class Response:
         f = os.path.join(self.config.BASEDIR, "packages", pack + ".z")
         txt = getPackageMsg(self.t)
         msg = self.makeMsg(txt, to, fileName=f)
+        msg = self.addUserManual(msg, self.reqInfo['locale'])
         try:
             status = self.sendEmail(to, msg)
         except:
@@ -431,6 +432,31 @@ class Response:
 
         return message
 
+    def addUserManual(self, message, lang="en"):
+        """Add the short user manual to an existing message.
+        """
+        docDir = os.path.join(self.config.BASEDIR, "doc")
+        mName = "short-user-manual_" + lang + ".xhtml"
+        docName = os.path.join(docDir, mName)
+        if not os.access(docName, os.R_OK):
+            # Fall back to english if a certain locale isn't 
+            # available
+            mName = "short-user-manual_en.xhtml"
+            docName = os.path.join(docDir, mName)
+        if os.access(docName, os.R_OK):
+            filePart = MIMEBase("application", "xhtml")
+            fp = open(docName, 'rb')
+            filePart.set_payload(fp.read())
+            fp.close()
+            encoders.encode_base64(filePart)
+            # Add file part
+            filePart.add_header('Content-Disposition', 'attachment', filename=mName)
+            message.attach(filePart)
+        else:
+            logging.error("Could not open manual file %d" % docName)
+
+        return message
+
     def sendEmail(self, sendTo, message, smtpserver="localhost:25"):
         """Send out message via STMP. If an error happens, be verbose about 
            the reason
diff --git a/lib/gettor/utils.py b/lib/gettor/utils.py
index c06e40f..6ac754b 100644
--- a/lib/gettor/utils.py
+++ b/lib/gettor/utils.py
@@ -85,6 +85,9 @@ def prepPackages(conf):
     if not packs.buildPackages():
        return False
 
+    # Copy the short user manual
+    packs.copyManuals()
+
     logging.debug("Building packages done.")
     return True
 





More information about the tor-commits mailing list