# HG changeset patch # User drewp@bigasterisk.com # Date 1301905499 25200 # Node ID 90405940c2633f595734376af0dd7003b64c6c85 start Ignore-this: dff7ea315a05d30553e01e9a903aff4e diff -r 000000000000 -r 90405940c263 readme --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/readme Mon Apr 04 01:24:59 2011 -0700 @@ -0,0 +1,14 @@ +Mirrors a directory of darcs repos onto github. + +Config description: +{ + "user" : "", + "SSH_AUTH_SOCK" : "path to ssh-agent socket file, like /tmp/ssh-abcde12345/agent.12345", + "gitHubToken" : "", + "gitsyncDir" : "", + "darcsDir" : "", + "darcsToGitCmd" : "/usr/bin/darcs-to-git" +} + +See also: +http://www.silverwareconsulting.com/index.cfm/2009/10/30/Placing-Config-Files-Under-Version-Control-with-Git-and-GitHub diff -r 000000000000 -r 90405940c263 sync.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sync.py Mon Apr 04 01:24:59 2011 -0700 @@ -0,0 +1,60 @@ +#!bin/python + +import os, subprocess, urllib2, jsonlib, logging, traceback +from github import github +logging.basicConfig(level=logging.INFO) +log = logging.getLogger() + +class Project(object): + def __init__(self, config, gh, name): + self.config = config + self.gh = gh + self.name = name + + def gitDir(self): + gitDir = os.path.join(self.config['gitSyncDir'], self.name) + try: + os.mkdir(gitDir) + except OSError: pass + return gitDir + + def syncToLocalGit(self): + darcsDir = os.path.join(self.config['darcsDir'], self.name) + try: + os.rmdir(os.path.join(darcsDir, 'darcs_testing_for_nfs')) + except OSError: pass + 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']}) + + def makeGitHubRepo(self): + try: + self.gh.repos.create(self.name) + except urllib2.HTTPError: + return + self.runGitCommand(['git', 'remote', 'add', 'origin', + 'git@github.com:%s/%s.git' % (self.gh.user, + 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']) + +for proj in os.listdir(config['darcsDir']): + if 'repo' not in proj: + continue + if not os.path.isdir(os.path.join(config['darcsDir'], proj)): + continue + try: + p = Project(config, gh, proj) + log.info("syncing %s" % proj) + p.syncToLocalGit() + p.makeGitHubRepo() + p.pushToGitHub() + except Exception, e: + traceback.print_exc() +