Mercurial > code > home > repos > reposync
comparison sync.py @ 3:4077903a9520
upgrade PyGithub. use keychain for ssh sock path
Ignore-this: ab5c52463f0b6cc01bc3dece4bc2192f
author | drewp@bigasterisk.com |
---|---|
date | Mon, 27 May 2013 01:08:16 -0700 |
parents | 22ccc05756de |
children | 7f479502a8ab |
comparison
equal
deleted
inserted
replaced
2:22ccc05756de | 3:4077903a9520 |
---|---|
1 #!bin/python | 1 #!bin/python |
2 | 2 |
3 import os, subprocess, urllib2, json, logging, traceback, time | 3 import os, subprocess, urllib2, json, logging, traceback, time, re |
4 from github import Github, GithubException | 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): |
29 def syncToLocalGit(self): | 29 def syncToLocalGit(self): |
30 darcsDir = os.path.join(self.config['darcsDir'], self.name) | 30 darcsDir = os.path.join(self.config['darcsDir'], self.name) |
31 try: | 31 try: |
32 os.rmdir(os.path.join(darcsDir, 'darcs_testing_for_nfs')) | 32 os.rmdir(os.path.join(darcsDir, 'darcs_testing_for_nfs')) |
33 except OSError: pass | 33 except OSError: pass |
34 self.runGitCommand([self.config['darcsToGitCmd'], '--no-verbose', darcsDir]) | 34 self.runGitCommand([self.config['darcsToGitCmd'], '--verbose', darcsDir]) |
35 | 35 |
36 def runGitCommand(self, args): | 36 def runGitCommand(self, args): |
37 try: | 37 try: |
38 subprocess.check_call(args, cwd=self.gitDir(), | 38 subprocess.check_call(args, cwd=self.gitDir(), |
39 env={'SSH_AUTH_SOCK': self.config['SSH_AUTH_SOCK'], | 39 env={'SSH_AUTH_SOCK': self.config['SSH_AUTH_SOCK'], |
45 | 45 |
46 def makeGitHubRepo(self): | 46 def makeGitHubRepo(self): |
47 try: | 47 try: |
48 self.gh.create_repo(self.name) | 48 self.gh.create_repo(self.name) |
49 except GithubException, e: | 49 except GithubException, e: |
50 assert e.data['errors'][0]['message'].startswith('name already exists'), e | 50 assert e.data['errors'][0]['message'].startswith('name already exists'), (e, self.name) |
51 return | 51 return |
52 self.runGitCommand(['git', 'remote', 'add', 'origin', | 52 self.runGitCommand(['git', 'remote', 'add', 'origin', |
53 'git@github.com:%s/%s.git' % (self.gh.login, | 53 'git@github.com:%s/%s.git' % (self.gh.login, |
54 self.name)]) | 54 self.name)]) |
55 | 55 |
56 def pushToGitHub(self): | 56 def pushToGitHub(self): |
57 self.runGitCommand(['git', 'push', 'origin', 'master']) | 57 self.runGitCommand(['git', 'push', 'origin', 'master']) |
58 | 58 |
59 def getSshAuthSock(): | |
60 keychain = subprocess.check_output([ | |
61 "keychain", "--noask", "--quiet", "--eval", "id_rsa"]) | |
62 m = re.search(r'SSH_AUTH_SOCK=([^; \n]+)', keychain) | |
63 if m is not None: | |
64 return m.group(1) | |
65 else: | |
66 raise ValueError("couldn't find SSH_AUTH_SOCK in output " | |
67 "from keychain: %r" % keychain) | |
68 | |
59 config = json.loads(open("config.json").read()) | 69 config = json.loads(open("config.json").read()) |
70 config['SSH_AUTH_SOCK'] = getSshAuthSock() | |
60 | 71 |
61 # to get this token: | 72 # to get this token: |
62 # curl -u drewp https://api.github.com/authorizations -d '{"scopes":["repo"]}' | 73 # curl -u drewp https://api.github.com/authorizations -d '{"scopes":["repo"]}' |
63 # from http://developer.github.com/v3/oauth/#oauth-authorizations-api | 74 # from http://developer.github.com/v3/oauth/#oauth-authorizations-api |
64 gh = Github(config['gitHubToken']).get_user() | 75 gh = Github(config['gitHubToken']).get_user() |