changeset 9:2c4d383d464c

move config stuff into Project
author drewp@bigasterisk.com
date Fri, 16 Jul 2021 00:19:01 -0700
parents cc3321b8adc1
children 460a2cf8b22b
files sync.py sync_to_github.py
diffstat 2 files changed, 9 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/sync.py	Fri Jul 16 00:18:34 2021 -0700
+++ b/sync.py	Fri Jul 16 00:19:01 2021 -0700
@@ -6,10 +6,13 @@
 logging.basicConfig(level=logging.INFO)
 log = logging.getLogger()
 
-class Project(object):
-    def __init__(self, config, gh, projRoot: Path):
-        self.config = config
-        self.gh = gh
+
+class Project:
+    def __init__(self, projRoot: Path):
+        self.config = json.load(open(Path(__file__).parent / "config.json"))
+        self.config['SSH_AUTH_SOCK'] = getSshAuthSock()
+
+        self.gh = Github(self.config['githubToken']).get_user()
         self.projRoot = projRoot
         self.name = projRoot.name
 
@@ -49,7 +52,6 @@
         try:
             self.gh.create_repo(self.name)
         except GithubException as e:
-            print('exists')
             assert e.data['errors'][0]['message'].startswith('name already exists'), (e, self.name)
             return
         self.runGitCommand(['git', 'remote', 'add', 'origin',
@@ -78,21 +80,17 @@
     return m.group(1)
 
 if __name__ == '__main__':
-    config = json.loads(open("config.json").read())
-    config['SSH_AUTH_SOCK'] = getSshAuthSock()
 
     # to get this token:
     # curl -u drewp https://api.github.com/authorizations -d '{"scopes":["repo"]}'
     # --new:
     # from https://docs.github.com/en/developers/apps/building-oauth-apps/authorizing-oauth-apps#non-web-application-flow -> https://github.com/settings/tokens to make one
 
-    gh = Github(config['gitHubToken']).get_user()
-
     for proj in os.listdir(config['darcsDir']):
         if not os.path.isdir(os.path.join(config['darcsDir'], proj)):
             continue
         try:
-            p = Project(config, gh, proj)
+            p = Project(proj)
 
             if p.darcsTime() < time.time() - 86400*config['tooOldDays']:
                 continue
--- a/sync_to_github.py	Fri Jul 16 00:18:34 2021 -0700
+++ b/sync_to_github.py	Fri Jul 16 00:19:01 2021 -0700
@@ -1,18 +1,8 @@
 #!/usr/bin/python3
 from pathlib import Path
-import json
 
-from github import Github
 from sync import Project, getSshAuthSock
 
-config = json.loads(open("config.json").read())
-config['SSH_AUTH_SOCK'] = getSshAuthSock()
-
-# to get this token:
-# curl -u drewp https://api.github.com/authorizations -d '{"scopes":["repo"]}'
-# from http://developer.github.com/v3/oauth/#oauth-authorizations-api
-gh = Github(config['gitHubToken']).get_user()
-
-p = Project(config, gh, Path('.').absolute())
+p = Project(Path('.').absolute())
 p.makeGithubRepo()
 p.hgToGithub()