Created
June 2, 2015 21:55
-
-
Save andrewpwade/9560bc942870c441c227 to your computer and use it in GitHub Desktop.
Add all git repositories in a path to trac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import subprocess | |
import os | |
import re | |
env = "/home/trac/trac" | |
search_path = "/home/git/repositories" | |
def add_repo(env, name, path): | |
subprocess.check_call(['trac-admin', env, 'repository', 'add', name, path, 'git']) | |
subprocess.check_call(['trac-admin', env, 'repository', 'sync', name]) | |
def trac_repo_list(env): | |
for line in subprocess.check_output(['trac-admin', env, 'repository', 'list']).strip().splitlines(): | |
match = re.search('^(\w+)\s+(git)', line) | |
if not match: | |
continue | |
yield match.group(1) | |
def find_git_repos(path): | |
for (dirpath, dirnames, filenames) in os.walk(path): | |
for d in dirnames: | |
if os.path.exists(os.path.join(dirpath, d, 'HEAD')): | |
yield os.path.join(dirpath, d) | |
break | |
trac_repos = list(trac_repo_list(env)) | |
git_repos = list(find_git_repos(search_path)) | |
for repo_path in git_repos: | |
name = os.path.splitext(os.path.basename(repo_path))[0] | |
if name in trac_repos: | |
continue | |
add_repo(env, name, repo_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment