update_files 1.68 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python3

from github import Github

import sys
import json
import urllib
import subprocess

REPO_NAME = "TheTorProject/gettorbrowser"

def delete_old_releases(repo):
    for release in repo.get_releases():
        release.delete_release()

#Download list of tor browser releases and upload them to github
def upload_files(release):
    url = urllib.request.urlopen("https://aus1.torproject.org/torbrowser/update_3/release/downloads.json")
    data = json.loads(url.read().decode())
    for arch in data['downloads']:
        for locale in data['downloads'][arch]:
            for asset in data['downloads'][arch][locale]:
                url = data['downloads'][arch][locale][asset]
                filename = url.split('/')[-1]
25
26
27
28
29
                try:
                    subprocess.check_call(["/usr/bin/wget", "--quiet", url])
                    release.upload_asset(filename)
                except:
                    print("Error: failed to download "+url)
30
                    print("Please upload this file manually.")
31

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55


def main(token):

    #Initialize a new release
    g = Github(token)
    repo = g.get_repo(REPO_NAME)

    delete_old_releases(repo)

    #Create a new release
    release = repo.create_git_release("torbrowser-release", "Tor Browser releases", "These releases were uploaded to be distributed with gettor.")
    upload_files(release)


if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: {} AUTH_TOKEN".format(sys.argv[0]), file=sys.stderr)
        print("\nAUTH_TOKEN should be an authentication token for a user"
              "with access to the gettor repository.", file=sys.stderr)
        sys.exit(1)
    token = sys.argv[1]

    sys.exit(main(token))