comparison sync.py @ 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
comparison
equal deleted inserted replaced
0:90405940c263 1:1da34eecdfd8
1 #!bin/python 1 #!bin/python
2 2
3 import os, subprocess, urllib2, jsonlib, logging, traceback 3 import os, subprocess, urllib2, json, logging, traceback, time
4 from github import github 4 from github import Github, GithubException
5 logging.basicConfig(level=logging.INFO) 5 logging.basicConfig(level=logging.INFO)
6 log = logging.getLogger() 6 log = logging.getLogger()
7 7
8 class Project(object): 8 class Project(object):
9 def __init__(self, config, gh, name): 9 def __init__(self, config, gh, name):
24 os.rmdir(os.path.join(darcsDir, 'darcs_testing_for_nfs')) 24 os.rmdir(os.path.join(darcsDir, 'darcs_testing_for_nfs'))
25 except OSError: pass 25 except OSError: pass
26 self.runGitCommand([self.config['darcsToGitCmd'], '--no-verbose', darcsDir]) 26 self.runGitCommand([self.config['darcsToGitCmd'], '--no-verbose', darcsDir])
27 27
28 def runGitCommand(self, args): 28 def runGitCommand(self, args):
29 subprocess.check_call(args, cwd=self.gitDir(), 29 try:
30 env={'SSH_AUTH_SOCK': self.config['SSH_AUTH_SOCK']}) 30 subprocess.check_call(args, cwd=self.gitDir(),
31 env={'SSH_AUTH_SOCK': self.config['SSH_AUTH_SOCK'],
32 'HOME': os.environ['HOME'], # darcs-to-git uses this
33 })
34 except:
35 log.error("in %s" % self.gitDir())
36 raise
31 37
32 def makeGitHubRepo(self): 38 def makeGitHubRepo(self):
33 try: 39 try:
34 self.gh.repos.create(self.name) 40 self.gh.create_repo(self.name)
35 except urllib2.HTTPError: 41 except GithubException, e:
42 assert e.data['errors'][0]['message'].startswith('name already exists'), e
36 return 43 return
37 self.runGitCommand(['git', 'remote', 'add', 'origin', 44 self.runGitCommand(['git', 'remote', 'add', 'origin',
38 'git@github.com:%s/%s.git' % (self.gh.user, 45 'git@github.com:%s/%s.git' % (self.gh.login,
39 self.name)]) 46 self.name)])
40 47
41 def pushToGitHub(self): 48 def pushToGitHub(self):
42 self.runGitCommand(['git', 'push', 'origin', 'master']) 49 self.runGitCommand(['git', 'push', 'origin', 'master'])
43 50
44 config = jsonlib.read(open("config.json").read()) 51 config = json.loads(open("config.json").read())
45 gh = github.GitHub(config['user'], config['gitHubToken']) 52
53 # to get this token:
54 # curl -u drewp https://api.github.com/authorizations -d '{"scopes":["repo"]}'
55 # from http://developer.github.com/v3/oauth/#oauth-authorizations-api
56 gh = Github(config['gitHubToken']).get_user()
46 57
47 for proj in os.listdir(config['darcsDir']): 58 for proj in os.listdir(config['darcsDir']):
48 if 'repo' not in proj: 59 if 'repo' not in proj:
49 continue 60 continue
50 if not os.path.isdir(os.path.join(config['darcsDir'], proj)): 61 if not os.path.isdir(os.path.join(config['darcsDir'], proj)):