changeset 1:1da34eecdfd8

port to PyGithub so repo creates work again Ignore-this: 5e00f0483c54df98dddda680b00d1318
author drewp@bigasterisk.com
date Tue, 08 Jan 2013 23:40:24 -0800
parents 90405940c263
children 22ccc05756de
files pydeps sync.py
diffstat 2 files changed, 21 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pydeps	Tue Jan 08 23:40:24 2013 -0800
@@ -0,0 +1,1 @@
+PyGithub==1.10.0
--- a/sync.py	Mon Apr 04 01:24:59 2011 -0700
+++ b/sync.py	Tue Jan 08 23:40:24 2013 -0800
@@ -1,7 +1,7 @@
 #!bin/python
 
-import os, subprocess, urllib2, jsonlib, logging, traceback
-from github import github
+import os, subprocess, urllib2, json, logging, traceback, time
+from github import Github, GithubException
 logging.basicConfig(level=logging.INFO)
 log = logging.getLogger()
 
@@ -26,23 +26,34 @@
         self.runGitCommand([self.config['darcsToGitCmd'], '--no-verbose', darcsDir])
 
     def runGitCommand(self, args):
-        subprocess.check_call(args, cwd=self.gitDir(),
-                          env={'SSH_AUTH_SOCK': self.config['SSH_AUTH_SOCK']})
+        try:
+            subprocess.check_call(args, cwd=self.gitDir(),
+                                  env={'SSH_AUTH_SOCK': self.config['SSH_AUTH_SOCK'],
+                                       'HOME': os.environ['HOME'], # darcs-to-git uses this
+                                       })
+        except:
+            log.error("in %s" % self.gitDir())
+            raise
 
     def makeGitHubRepo(self):
         try:
-            self.gh.repos.create(self.name)
-        except urllib2.HTTPError:
+            self.gh.create_repo(self.name)
+        except GithubException, e:
+            assert e.data['errors'][0]['message'].startswith('name already exists'), e
             return
         self.runGitCommand(['git', 'remote', 'add', 'origin',
-                            'git@github.com:%s/%s.git' % (self.gh.user,
+                            'git@github.com:%s/%s.git' % (self.gh.login,
                                                           self.name)])
 
     def pushToGitHub(self):
         self.runGitCommand(['git', 'push', 'origin', 'master'])
 
-config = jsonlib.read(open("config.json").read())
-gh = github.GitHub(config['user'], config['gitHubToken'])
+config = json.loads(open("config.json").read())
+
+# 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()
 
 for proj in os.listdir(config['darcsDir']):
     if 'repo' not in proj: