aboutsummaryrefslogtreecommitdiff
path: root/repo_to_repo.py
diff options
context:
space:
mode:
authorHan Shen <shenhan@google.com>2013-03-18 13:53:52 -0700
committerHan Shen <shenhan@google.com>2013-03-20 11:09:54 -0700
commiteb77c44ba613280fe4514d512737477b4830d63e (patch)
tree9b3a073d1cb669fac4b21de4a67d54fa0153eef5 /repo_to_repo.py
parent3e017d00c7c0501b6eacace8f4f39037d9618278 (diff)
downloadtoolchain-utils-eb77c44ba613280fe4514d512737477b4830d63e.tar.gz
Refactor repo_to_repo.py a little bit.
I'm writing a script to do compiler bootstrap, which needs to sync a user provided gcc directory with chromiumos git repository and submit all that changes to chromiumos git locally. The modification includes - 1. added a new repo type - FileRepo, which is literally no-op but set "_root_dir" to its directory 2. outlined the submit code from PushSources, so that this submit routine could be called from outside I also tested that this worked even if the input FileRepo is read-only. Tested using a test rtr file as below - { "input": [{ "type": "file", "address": "/usr/local/google/home/shenhan/temp2", },], "output": [{ "type": "git", "address": "file:///usr/local/google/home/shenhan/temp", "ignores": [".svn", ".git"], },], } TEST=run repo_to_repo.py with gcc-4_7-mobile profile. Change-Id: Ib73be0b4fa8612428801b10a17abdcdc1a2822e3 Reviewed-on: https://gerrit-int.chromium.org/33990 Reviewed-by: asharif <asharif@google.com> Commit-Queue: Han Shen <shenhan@google.com> Tested-by: Han Shen <shenhan@google.com>
Diffstat (limited to 'repo_to_repo.py')
-rwxr-xr-xrepo_to_repo.py52
1 files changed, 43 insertions, 9 deletions
diff --git a/repo_to_repo.py b/repo_to_repo.py
index 88433dfe..08d61e9a 100755
--- a/repo_to_repo.py
+++ b/repo_to_repo.py
@@ -4,6 +4,7 @@
__author__ = 'asharif@google.com (Ahmad Sharif)'
+import datetime
import optparse
import os
import re
@@ -40,13 +41,16 @@ def SplitMapping(mapping):
class Repo(object):
- def __init__(self):
+ def __init__(self, no_create_tmp_dir=False):
self.repo_type = None
self.address = None
self.mappings = None
self.revision = None
self.ignores = ['.gitignore', '.p4config', 'README.google']
- self._root_dir = tempfile.mkdtemp()
+ if no_create_tmp_dir:
+ self._root_dir = None
+ else:
+ self._root_dir = tempfile.mkdtemp()
self._ce = command_executer.GetCommandExecuter()
self._logger = logger.GetLogger()
@@ -92,6 +96,24 @@ class Repo(object):
self.mappings])
+# Note - this type of repo is used only for "readonly", in other words, this
+# only serves as a incoming repo.
+class FileRepo(Repo):
+ def __init__(self, address, ignores=None):
+ Repo.__init__(self, no_create_tmp_dir=True)
+ self.repo_type = 'file'
+ self.address = address
+ self.mappings = None
+ self.branch = None
+ self.revision = '{0} (as of "{1}")'.format(address, datetime.datetime.now())
+ self.gerrit = None
+ self._root_dir = self.address
+
+ def CleanupRoot(self):
+ """Override to prevent deletion."""
+ pass
+
+
class P4Repo(Repo):
def __init__(self, address, mappings, revision=None):
Repo.__init__(self)
@@ -198,12 +220,8 @@ class GitRepo(Repo):
ret = self._ce.RunCommand(command)
return ret
- def PushSources(self, commit_message=None, dry_run=False, message_file=None):
+ def CommitLocally(self, commit_message=None, message_file=None):
with misc.WorkingDirectory(self._root_dir):
- push_args = ''
- if dry_run:
- push_args += ' -n '
-
command = 'pwd'
for ignore in self.ignores:
command += '&& echo \'%s\' >> .git/info/exclude' % ignore
@@ -215,8 +233,15 @@ class GitRepo(Repo):
else:
raise Exception("No commit message given!")
command += '&& git commit -v %s' % message_arg
- ret = self._ce.RunCommand(command)
- if ret: return ret
+ return self._ce.RunCommand(command)
+
+ def PushSources(self, commit_message=None, dry_run=False, message_file=None):
+ ret = self.CommitLocally(commit_message, message_file)
+ if ret: return ret
+ push_args = ''
+ if dry_run:
+ push_args += ' -n '
+ with misc.WorkingDirectory(self._root_dir):
if self.gerrit:
label = 'somelabel'
command = 'git remote add %s %s' % (label, self.address)
@@ -226,6 +251,7 @@ class GitRepo(Repo):
command = 'git push -v %s origin %s:%s' % (push_args, self.branch,
self.branch)
ret = self._ce.RunCommand(command)
+ return ret
def MapSources(self, root_dir):
if not self.mappings:
@@ -288,6 +314,8 @@ class RepoReader(object):
mappings=repo_mappings,
ignores=repo_ignores,
gerrit=gerrit)
+ elif repo_type == 'file':
+ repo = FileRepo(repo_address)
else:
logger.GetLogger().LogFatal('Unknown repo type: %s' % repo_type)
return repo
@@ -321,6 +349,12 @@ def Main(argv):
rr = RepoReader(options.input_file)
[input_repos, output_repos] = rr.ParseFile()
+ # Make sure FileRepo is not used as output destination.
+ for output_repo in output_repos:
+ if output_repo.repo_type == 'file':
+ logger.GetLogger().LogFatal(
+ 'FileRepo is only supported as an input repo.')
+
for output_repo in output_repos:
ret = output_repo.SetupForPush()
if ret: return ret