mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-21 06:31:31 +00:00
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>
This commit is contained in:
parent
5030159e27
commit
5cc42a5184
1 changed files with 28 additions and 21 deletions
|
@ -880,23 +880,39 @@ class Slots:
|
||||||
for board in failed_boards:
|
for board in failed_boards:
|
||||||
f.write(board + '\n')
|
f.write(board + '\n')
|
||||||
|
|
||||||
class WorkDir:
|
class ReferenceSource:
|
||||||
def __init__(self):
|
|
||||||
"""Create a new working directory."""
|
"""Reference source against which original configs should be parsed."""
|
||||||
self.work_dir = tempfile.mkdtemp()
|
|
||||||
|
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):
|
def __del__(self):
|
||||||
"""Delete the working directory
|
"""Delete the reference source directory
|
||||||
|
|
||||||
This function makes sure the temporary directory is cleaned away
|
This function makes sure the temporary directory is cleaned away
|
||||||
even if Python suddenly dies due to error. It should be done in here
|
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
|
because it is guaranteed the destructor is always invoked when the
|
||||||
instance of the class gets unreferenced.
|
instance of the class gets unreferenced.
|
||||||
"""
|
"""
|
||||||
shutil.rmtree(self.work_dir)
|
shutil.rmtree(self.src_dir)
|
||||||
|
|
||||||
def get(self):
|
def get_dir(self):
|
||||||
return self.work_dir
|
"""Return the absolute path to the reference source directory."""
|
||||||
|
|
||||||
|
return self.src_dir
|
||||||
|
|
||||||
def move_config(configs, options):
|
def move_config(configs, options):
|
||||||
"""Move config options to defconfig files.
|
"""Move config options to defconfig files.
|
||||||
|
@ -914,20 +930,11 @@ def move_config(configs, options):
|
||||||
print 'Move ' + ', '.join(configs),
|
print 'Move ' + ', '.join(configs),
|
||||||
print '(jobs: %d)\n' % options.jobs
|
print '(jobs: %d)\n' % options.jobs
|
||||||
|
|
||||||
reference_src_dir = ''
|
|
||||||
|
|
||||||
if options.git_ref:
|
if options.git_ref:
|
||||||
work_dir = WorkDir()
|
reference_src = ReferenceSource(options.git_ref)
|
||||||
reference_src_dir = work_dir.get()
|
reference_src_dir = reference_src.get_dir()
|
||||||
print "Cloning git repo to a separate work directory..."
|
else:
|
||||||
subprocess.check_output(['git', 'clone', os.getcwd(), '.'],
|
reference_src_dir = ''
|
||||||
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)
|
|
||||||
|
|
||||||
if options.defconfigs:
|
if options.defconfigs:
|
||||||
defconfigs = [line.strip() for line in open(options.defconfigs)]
|
defconfigs = [line.strip() for line in open(options.defconfigs)]
|
||||||
|
|
Loading…
Add table
Reference in a new issue