Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Refactor for Python3 (#28091) #23

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ with gtalk users.
*Twitter*: Receive requests via Twitter direct messages, contact the core module
if necessary and respond to the user in the specified language. Unfinished.

*Github*: Run `torsocks python3 create_gh_mirrors.py` to update the github
archive at https://github.com/TheTorProject/gettor - it depends on the github3
and urllib modules.

*DB*: Store anonymous info about the people that interact with GetTor in order
to keep count of the number of requests per person and avoid malicious users
that try to collapse the service. It also keeps count of how many requests
Expand Down
10 changes: 5 additions & 5 deletions core_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
try:
core = gettor.core.Core()
links = core.get_links('dummy service', 'linux', 'en')
print links
print(links)
except gettor.core.ConfigError as e:
print "Misconfiguration: " + str(e)
print("Misconfiguration: " + str(e))
except gettor.core.UnsupportedOSError as e:
print "Unsupported OS: " + str(e)
print("Unsupported OS: " + str(e))
except gettor.core.UnsupportedLocaleError as e:
print "Unsupported Locale: " + str(e)
print("Unsupported Locale: " + str(e))
except gettor.core.InternalError as e:
print "Internal error: " + str(e)
print("Internal error: " + str(e))
117 changes: 74 additions & 43 deletions create_gh_mirrors.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
"""create_gh_mirrors -- Create landing page and readme for Github."""

import os
import ConfigParser
import configparser

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.

"""
Expand Down Expand Up @@ -75,77 +75,108 @@ 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)
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]

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("%OSX%", osx_pkg)
content_html = content_html.replace("%OSX_SIG%", osx_sig)
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("%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)
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("%VERSION%", version)
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')
try:
tb_version_config = configparser.ConfigParser()
tb_version_config.read(tb_version_path)
tb_version = tb_version_config['version']['current']

except:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not do an unconditional except: -- instead, let's catch specific exceptions.

raise SystemExit("Failed to parse %s. Does it exist?" % tb_version_path)
# TODO add some hint how to generate it

links = ConfigParser.ConfigParser()
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', '')
Expand All @@ -157,7 +188,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 = {
Expand All @@ -172,10 +203,10 @@ def main():
}

file_landing_gh.update(**data_landing)
print "Landing page updated in gettor"
print ("Landing page updated in gettor")

file_readme_gh.update(**data_readme)
print "README updated in gettorbrowser"
print ("README updated in gettorbrowser")

if __name__ == "__main__":
main()
10 changes: 10 additions & 0 deletions css/bootstrap.min.css

Large diffs are not rendered by default.

83 changes: 83 additions & 0 deletions css/gettor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* Fonts */
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 400;
src: local('Lato Regular'), local('Lato-Regular'), url('../fonts/lato-regular.woff') format('woff');
}
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 700;
src: local('Lato Bold'), local('Lato-Bold'), url('../fonts/lato-bold.woff') format('woff');
}
@font-face {
font-family: 'Lato';
font-style: italic;
font-weight: 400;
src: local('Lato Italic'), local('Lato-Italic'), url('../fonts/lato-italic.woff') format('woff');
}

body {
padding-bottom: 20px;
/*background-color: #4ba027;*/
}

footer {
color: #aaa;
}

a:link, a:visited {
color: #AF02D7;
text-decoration: none;
}

a:hover {
color: #65007D;
}

#main {
background-color: #fff;
margin: 5% 0;
font-family: "Lato";
font-size: 16px;
font-weight: lighter;
}

#main h2 {
color: #8500A3;
}

#head-title {
color: #fff !important;
font-size: 23px;
}

#head-link {
text-align: right;
}

#head-link a:link {
color: #ccc;
}

#head-link a:hover {
color: #fff;
text-decoration: none;
}

.navbar {
background-color: #770093 !important;
}

.pad-big-left {
padding-left: 110px;
}

.pad-big-right {
padding-right: 110px;
}

.big-link {
font-size: 26px;
}
Binary file added fonts/glyphicons-halflings-regular.eot
Binary file not shown.
Loading