diff options
author | Masahiro Yamada | 2016-06-15 14:33:51 +0900 |
---|---|---|
committer | Masahiro Yamada | 2016-06-22 09:22:42 +0900 |
commit | 5cc42a51846cd69596081a9cd9d2bd0495815525 (patch) | |
tree | 45b9808b151a4fd43d8d0065586816b62326edb8 /tools/moveconfig.py | |
parent | 5030159e27a1d6293f0f064807d4eef5dd6de714 (diff) |
tools: moveconfig: change class WorkDir to class ReferenceSource
The class WorkDir can be used in a very generic way, but currently
it is only used for containing a reference source directory.
This commit changes it for a more dedicated use. The move_config
function can be more readable by enclosing the git-clone and git-
checkout in the class constructor.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
Diffstat (limited to 'tools/moveconfig.py')
-rwxr-xr-x | tools/moveconfig.py | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/tools/moveconfig.py b/tools/moveconfig.py index 03acbea94cf..44be51fb8ae 100755 --- a/tools/moveconfig.py +++ b/tools/moveconfig.py @@ -880,23 +880,39 @@ class Slots: for board in failed_boards: f.write(board + '\n') -class WorkDir: - def __init__(self): - """Create a new working directory.""" - self.work_dir = tempfile.mkdtemp() +class ReferenceSource: + + """Reference source against which original configs should be parsed.""" + + def __init__(self, commit): + """Create a reference source directory based on a specified commit. + + Arguments: + commit: commit to git-clone + """ + self.src_dir = tempfile.mkdtemp() + print "Cloning git repo to a separate work directory..." + subprocess.check_output(['git', 'clone', os.getcwd(), '.'], + cwd=self.src_dir) + print "Checkout '%s' to build the original autoconf.mk." % \ + subprocess.check_output(['git', 'rev-parse', '--short', commit]).strip() + subprocess.check_output(['git', 'checkout', commit], + stderr=subprocess.STDOUT, cwd=self.src_dir) def __del__(self): - """Delete the working directory + """Delete the reference source directory This function makes sure the temporary directory is cleaned away even if Python suddenly dies due to error. It should be done in here because it is guaranteed the destructor is always invoked when the instance of the class gets unreferenced. """ - shutil.rmtree(self.work_dir) + shutil.rmtree(self.src_dir) + + def get_dir(self): + """Return the absolute path to the reference source directory.""" - def get(self): - return self.work_dir + return self.src_dir def move_config(configs, options): """Move config options to defconfig files. @@ -914,20 +930,11 @@ def move_config(configs, options): print 'Move ' + ', '.join(configs), print '(jobs: %d)\n' % options.jobs - reference_src_dir = '' - if options.git_ref: - work_dir = WorkDir() - reference_src_dir = work_dir.get() - print "Cloning git repo to a separate work directory..." - subprocess.check_output(['git', 'clone', os.getcwd(), '.'], - cwd=reference_src_dir) - print "Checkout '%s' to build the original autoconf.mk." % \ - subprocess.check_output(['git', 'rev-parse', '--short', - options.git_ref]).strip() - subprocess.check_output(['git', 'checkout', options.git_ref], - stderr=subprocess.STDOUT, - cwd=reference_src_dir) + reference_src = ReferenceSource(options.git_ref) + reference_src_dir = reference_src.get_dir() + else: + reference_src_dir = '' if options.defconfigs: defconfigs = [line.strip() for line in open(options.defconfigs)] |