aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Doan <andy.doan@linaro.org>2015-06-02 12:27:05 -0500
committerAndy Doan <andy.doan@linaro.org>2015-06-02 12:27:05 -0500
commitb4bd54dfa3015664dc1042e09bc074ccbac04d1b (patch)
tree7cefc4e8fd13e3cedb86166506bb0e512de290a4
parent76ae382768d69cd26f4a438f18603583058ac658 (diff)
fix easiest pep8 spacing complaints
There are tons of pep8 and pyflakes issues in this file, making it a little hard to do checks against new changes. Change-Id: Id7137d234c1d6385ba588ad38bef1896f60716b9
-rwxr-xr-xgit-gerrit-mirror23
1 files changed, 20 insertions, 3 deletions
diff --git a/git-gerrit-mirror b/git-gerrit-mirror
index 2c5f17b..3075dd3 100755
--- a/git-gerrit-mirror
+++ b/git-gerrit-mirror
@@ -16,6 +16,7 @@ DEST_KEYWORD = "DESTINATION"
log = logging.getLogger(__file__)
+
class MirrorConfig(object):
def __init__(self, fname):
@@ -104,6 +105,7 @@ class MirrorConfig(object):
"Get all mirror repo paths as dict (key - src path, value - dest path)"
return self.host_map[host][1]
+
def run_command(cmdline, favor_dry_run=True):
if favor_dry_run and options.dry_run:
log.info("Would run: %s", cmdline)
@@ -111,6 +113,7 @@ def run_command(cmdline, favor_dry_run=True):
log.debug("Running: %s", cmdline)
os.system(cmdline)
+
def scan_git_projects(basedir):
git_repos = []
for root, dirs, files in os.walk(basedir):
@@ -121,10 +124,12 @@ def scan_git_projects(basedir):
git_repos.append((os.path.abspath(abspath), relpath))
return git_repos
+
def get_manifest_projects(manifest):
dom = minidom.parse(manifest)
return [p.getAttribute("name") for p in dom.getElementsByTagName("project")]
+
def get_cached(get_func, get_params_array, cache_id=None, cache_ttl=120):
if cache_id is None:
cache_id = get_params_array[0]
@@ -144,6 +149,7 @@ def get_cached(get_func, get_params_array, cache_id=None, cache_ttl=120):
f.close()
return result
+
def get_gerrit_projects(gerrit_host):
parts = gerrit_host.split(":", 1)
if len(parts) == 1:
@@ -155,12 +161,14 @@ def get_gerrit_projects(gerrit_host):
return [x.strip() for x in
subprocess.check_output(cmd, shell=True).split('\n') if x]
+
def get_url_project_list(url):
f = urllib.urlopen(url)
projects = [l.strip() for l in f]
f.close()
return projects
+
def get_ssh_identity_file_option():
"""Return an identity file option to use in SSH command based on config."""
ssh_identity = conf.get_var(options.dest, "ssh_identity")
@@ -170,6 +178,7 @@ def get_ssh_identity_file_option():
ssh_identity_option = ''
return ssh_identity_option
+
def get_project_map_for_a_host(host):
"""Get {src: dest} project map for a host. These can be either:
1. Manually specified projects (with destination remaps or no)
@@ -197,6 +206,7 @@ def get_project_map_for_a_host(host):
projects.extend(conf.get_repo_map(host).keys())
return dict((p, conf.get_mirror_repo(host, p)) for p in projects)
+
def create_gerrit_projects(projects):
gerrit_port = conf.get_var(options.dest, "gerrit_port")
gerrit_host = conf.get_var(options.dest, "gerrit_host")
@@ -206,6 +216,7 @@ def create_gerrit_projects(projects):
run_command("ssh %s -p %s %s gerrit create-project --name %s" %
(ssh_identity_option, gerrit_port, gerrit_host, project))
+
def clone_repos(host, basedir, projects):
"Clone-mirror repos from remote server"
new_repos = []
@@ -228,6 +239,7 @@ def clone_repos(host, basedir, projects):
new_repos.append(p + '.git')
return new_repos
+
def fetch_repos(git_repos):
"Update locally present mirror repos from remote server"
for abspath, relpath in git_repos:
@@ -236,6 +248,7 @@ def fetch_repos(git_repos):
os.chdir(abspath)
run_command("git fetch")
+
def push_repos(host, git_repos, force=False):
"Push-mirror locally present mirror repos to remote Gerrit git server"
for abspath, relpath in git_repos:
@@ -252,12 +265,14 @@ def push_repos(host, git_repos, force=False):
cmdline = "time git push%s %s/%s.git 'refs/heads/*' 'refs/tags/*'" % (extra_opts, repo_root, mirror_projname)
run_command(cmdline)
+
def update_grok(manifest, repo_root, repo):
log.debug('updating grok manifest for %s', repo)
cmd = '/usr/local/bin/grok-manifest -n -m %s -t %s -n %s' % (manifest, repo_root, repo)
cmd = 'cd %s; %s' % (repo_root, cmd)
run_command(cmd)
+
def handle_updated_repos(conf, repos):
manifest = conf.get_var(options.dest, 'grok_manifest')
if manifest:
@@ -265,17 +280,19 @@ def handle_updated_repos(conf, repos):
for p in repos:
update_grok(manifest, root, p)
+
def host_url_to_path(host):
host_p = urlparse.urlparse(host.rstrip("/"))
return options.mirror_dir + "/" + host_p.netloc + host_p.path.replace("/", "__")
+
def check_args(optparser, args, expected):
if len(args) != expected:
optparser.error("Wrong number of arguments")
-#gerrit-mirror.py clone git://android.git.kernel.org aosp-projects.txt
-#gerrit-mirror.py fetch
-#gerrit-mirror.py push
+# gerrit-mirror.py clone git://android.git.kernel.org aosp-projects.txt
+# gerrit-mirror.py fetch
+# gerrit-mirror.py push
optparser = optparse.OptionParser(usage="""%prog <options> <command> <args>...
Command: