[tor-commits] [gettor/master] Added more locales to landing page

ilv at torproject.org ilv at torproject.org
Tue Feb 23 22:03:07 UTC 2016


commit b5df39ae701ec203027fc29d84be0514ad299789
Author: ilv <ilv at users.noreply.github.com>
Date:   Tue Feb 23 19:01:54 2016 -0300

    Added more locales to landing page
---
 create_gh_mirrors.py | 106 ++++++++++++++++++++++++++++++++-------------------
 1 file changed, 66 insertions(+), 40 deletions(-)

diff --git a/create_gh_mirrors.py b/create_gh_mirrors.py
index a341940..e555488 100644
--- a/create_gh_mirrors.py
+++ b/create_gh_mirrors.py
@@ -17,12 +17,12 @@ import github3
 import gettor.core
 
 
-def create_readme(tpl_path, md_path, version, links):
+def create_readme(tpl_path, md_path, tb_version, links):
     """Create README file with links stored in github.links.
 
     :param: tpl_path (string) path to file used as template.
     :param: md_path (string) path to file generated.
-    :param: version (string) tor browser version.
+    :param: tb_version (string) tor browser version.
     :param: links (object) github links.
 
     """
@@ -75,77 +75,103 @@ def create_readme(tpl_path, md_path, version, links):
                 "%LINUX64_{}_SIG%".format(lc), linux64_sig
             )
 
-        content_md = content_md.replace("%VERSION%", version)
+        content_md = content_md.replace("%TB_VERSION%", tb_version)
         md_file.write(content_md)
 
-    print "README generated with version %s" % version
+    print "README generated with Tor Browser %s" % tb_version
 
 
-def create_landing_html(tpl_path, html_path, version, links):
+def create_landing_html(tpl_path, html_path, tb_version, links):
     """Create README file with links stored in github.links.
 
     :param: tpl_path (string) path to file used as template.
     :param: html_path (string) path to file generated.
-    :param: version (string) tor browser version.
+    :param: tb_version (string) tor browser version.
     :param: links (object) github links.
 
     """
-    win_link = links.get('windows', 'en')
-    win_pkg, win_sig, win_sha = [e for e in win_link.split("$") if e]
-
-    osx_link = links.get('osx', 'en')
-    osx_pkg, osx_sig, osx_sha = [e for e in osx_link.split("$") if e]
-
-    linux_links = links.get('linux', 'en')
-    linux32_link, linux64_link = linux_links.split(',')
-    linux32_pkg, linux32_sig, linux32_sha = [
-        e for e in linux32_link.split("$") if e
-    ]
-    linux64_pkg, linux64_sig, linux64_sha = [
-        e for e in linux64_link.split("$") if e
-    ]
+    lcs = ['FA', 'ZH', 'TR', 'EN']
 
     html_file = open(html_path, 'w')
     with open(tpl_path, 'r') as tpl_file:
-        content_tpl = tpl_file.read().replace('\n', '')
-        content_html = ''
+        content_html = tpl_file.read().replace('\n', '')
 
-        content_html = content_tpl.replace("%WINDOWS%", win_pkg)
-        content_html = content_html.replace("%WINDOWS_SIG%", win_sig)
-
-        content_html = content_html.replace("%OSX%", osx_pkg)
-        content_html = content_html.replace("%OSX_SIG%", osx_sig)
+        for lc in lcs:
+            win_link = links.get('windows', lc.lower())
+            win_pkg, win_sig, win_sha = [e for e in win_link.split("$") if e]
 
-        content_html = content_html.replace("%LINUX32%", linux32_pkg)
-        content_html = content_html.replace("%LINUX32_SIG%", linux32_sig)
-        content_html = content_html.replace("%LINUX64%", linux64_pkg)
-        content_html = content_html.replace("%LINUX64_SIG%", linux64_sig)
+            osx_link = links.get('osx', lc.lower())
+            osx_pkg, osx_sig, osx_sha = [e for e in osx_link.split("$") if e]
 
-        content_html = content_html.replace("%VERSION%", version)
+            linux_links = links.get('linux', lc.lower())
+            linux32_link, linux64_link = linux_links.split(',')
+            linux32_pkg, linux32_sig, linux32_sha = [
+                e for e in linux32_link.split("$") if e
+            ]
+            linux64_pkg, linux64_sig, linux64_sha = [
+                e for e in linux64_link.split("$") if e
+            ]
+            
+            content_html = content_html.replace(
+                "%WINDOWS_{}%".format(lc), win_pkg
+            )
+            """
+            content_html = content_html.replace(
+                "%WINDOWS_{}_SIG%".format(lc), win_sig
+            )
+            """
+            content_html = content_html.replace(
+                "%OSX_{}%".format(lc), osx_pkg
+            )
+            """
+            content_html = content_html.replace(
+                "%OSX_{}_SIG%".format(lc), osx_sig
+            )
+            """
+            content_html = content_html.replace(
+                "%LINUX32_{}%".format(lc), linux32_pkg
+            )
+            """
+            content_html = content_html.replace(
+                "%LINUX32_{}_SIG%".format(lc), linux32_sig
+            )
+            """
+            content_html = content_html.replace(
+                "%LINUX64_{}%".format(lc), linux64_pkg
+            )
+            """
+            content_html = content_html.replace(
+                "%LINUX64_{}_SIG%".format(lc), linux64_sig
+            )
+            """
+        
+        content_html = content_html.replace(
+            "%TB_VERSION%", tb_version
+        )
         html_file.write(content_html)
 
-    print "HTML generated with version %s" % version
+    print "HTML generated with Tor Browser %s" % tb_version
 
 
 def main():
     """Generate HTML and md files and update it in Github."""
     github_links = 'providers/github.links'
-    tbb_version_path = 'latest_torbrowser.cfg'
+    tb_version_path = 'latest_torbrowser.cfg'
     md_path = 'upload/readme_gh.md'
     html_path = 'upload/landing_gh.html'
     md_tpl_path = 'upload/readme_gh.tpl'
     html_tpl_path = 'upload/landing_gh.tpl'
     github_access_token = ''
 
-    tbb_version_config = ConfigParser.ConfigParser()
-    tbb_version_config.read(tbb_version_path)
-    version = tbb_version_config.get('version', 'current')
+    tb_version_config = ConfigParser.ConfigParser()
+    tb_version_config.read(tb_version_path)
+    tb_version = tb_version_config.get('version', 'current')
 
     links = ConfigParser.ConfigParser()
     links.read(github_links)
 
-    create_landing_html(html_tpl_path, html_path, version, links)
-    create_readme(md_tpl_path, md_path, version, links)
+    create_landing_html(html_tpl_path, html_path, tb_version, links)
+    create_readme(md_tpl_path, md_path, tb_version, links)
 
     landing = open(html_path, 'r')
     content_landing = landing.read().replace('\n', '')
@@ -157,7 +183,7 @@ def main():
     repo_landing = gh.repository('thetorproject', 'gettor')
     repo_readme = gh.repository('thetorproject', 'gettorbrowser')
 
-    file_landing_gh = repo_landing.file_contents('index.html')
+    file_landing_gh = repo_landing.file_contents('index.html', 'gh-pages')
     file_readme_gh = repo_readme.file_contents('README.md')
 
     data_landing = {





More information about the tor-commits mailing list