Created
October 15, 2013 08:02
-
-
Save kitelife/6988132 to your computer and use it in GitHub Desktop.
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 os | |
import subprocess | |
SITES_ROOT = '/data/sh_ecc/' | |
def remove_excess_ele(ele_set): | |
excess_ele_list = ['.', '..'] | |
for ele in excess_ele_list: | |
if ele in ele_set: | |
ele_set.remove('.') | |
return ele_set | |
def main(): | |
current_path = os.getcwd() | |
current_path_parts = current_path.split('/') | |
''' | |
owner = current_path_parts[-2] | |
repos_name = current_path_parts[-1].split('.')[0] | |
owner_path = SITES_ROOT + owner | |
repos_path = owner_path + '/' + repos_name | |
if not os.path.exists(owner_path): | |
os.mkdir(owner_path) | |
if not os.path.exists(repos_path): | |
os.mkdir(repos_path) | |
''' | |
repos_path = SITES_ROOT | |
branches = remove_excess_ele(set(os.listdir(current_path + '/refs/heads'))) | |
sites = remove_excess_ele(set(os.listdir(repos_path))) | |
to_setup = branches.difference(sites) | |
to_delete = sites.difference(branches) | |
sites_existed = branches.intersection(sites) | |
for branch in to_setup: | |
cmd = "cd " + repos_path + " && unset GIT_DIR && git clone " + current_path + ' ' + branch | |
p = subprocess.Popen(cmd, shell=True) | |
p.wait() | |
if branch != 'master': | |
cmd = "cd " + repos_path + '/' + branch + " && unset GIT_DIR && git checkout -b " + branch + " origin/" + branch | |
p = subprocess.Popen(cmd, shell=True) | |
p.wait() | |
for site in to_delete: | |
cmd = 'rm -rf ' + repos_path + '/' + site | |
p = subprocess.Popen(cmd, shell=True) | |
p.wait() | |
for site in sites_existed: | |
cmd = "cd " + repos_path + '/' + site + ' && unset GIT_DIR && git pull' | |
p = subprocess.Popen(cmd, shell=True) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment