Skip to content
Snippets Groups Projects

Make one script for automatic updates

Merged HackerNCoder requested to merge (removed):main into main
2 unresolved threads
Files
3
#!/usr/bin/env python3
# Dependencies:
# pip3 install PyGithub
# pip3 install python-gitlab
# pip3 install internetarchive
# Before running, place the authentication token for a user with push access to
# the Github repository in an environment variable 'GITHUB_AUTH' and a token to
# access the GitLab repository in an environment variable 'GITLAB_AUTH'
# the Github repository in an environment variable 'GITHUB_AUTH', a token to
# access the GitLab repository in an environment variable 'GITLAB_AUTH' and the
# Internet Archive S3 Access and Secret tokens in the 'IA_ACCESS' and 'IA_SECRET'
# environment variables
from github import Github
from gitlab import Gitlab
import internetarchive as ia
import sys
import json
@@ -90,6 +94,33 @@ class GithubRemote:
def upload(self, filename, arch):
self.release.upload_asset(filename)
class GdriveRemote:
def clean_up(self):
try:
subprocess.check_call(["rclone", "delete gdrive:releases"])
subprocess.check_call(["rclone", "cleanup gdrive:releases"])
except:
print("Error: failed to delete or cleanup with rclone", file=sys.stderr)
return 1
def upload(self, filename, arch):
try:
subprocess.check_call(["rclone", "copy", filename, "gdrive:releases"])
except:
print("Error: failed to rclone "+filename+" to Google Drive", file=sys.stderr)
class IARemote:
def __init__(self, token):
self.access = token.split("\n")[0]
self.secret = token.split("\n")[1]
def upload(self, filename):
md = dict(collection="open_source_software", title=filename, mediatype="software")
item = ia.get_item("Tor_Browser_"+version)
item.modify_metadata(dict(title="Tor Browser "+version))
r = item.upload(files=[filename], metadata=md, access_key=self.access, secret_key=self.secret)
#Download list of tor browser releases and upload them to remote repositories
def upload_files(remotes):
if len(remotes) == 0:
@@ -162,7 +193,21 @@ def main():
gitlab.create_projects()
remotes.append(gitlab)
return upload_files(remotes)
if 'IA_ACCESS' not in os.environ and 'IA_SECRET' not in os.environ:
print("WARNING: No Internet Archive S3 authentication tokens given", file=sys.stderr)
print("The authentication tokens for Internet Archive should be placed in the environment"
"variables 'IA_ACCESS' and 'IA_SECRET'", file=sys.stderr)
else:
ia = IARemote(os.environ['IA_ACCESS']+"\n"+os.environ['IA_SECRET'])
remotes.append(ia)
gdrive = GdriveRemote()
gdrive.clean_up()
remotes.append(gdrive)
upload_files(remotes)
return 0
if __name__ == "__main__":
sys.exit(main())
Loading