Split out DistCatcher.
This commit is contained in:
parent
093343b085
commit
1dac0c527a
1 changed files with 59 additions and 41 deletions
|
@ -365,13 +365,56 @@ def dupe_vcs_tree(tree, directory):
|
||||||
parent = tree.branch.get_parent()
|
parent = tree.branch.get_parent()
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
parent = tree._repository.controldir.open_branch()
|
parent = tree._repository.controldir.open_branch().get_parent()
|
||||||
except NotBranchError:
|
except NotBranchError:
|
||||||
parent = None
|
parent = None
|
||||||
if parent:
|
if parent:
|
||||||
result.open_branch().set_parent(parent)
|
result.open_branch().set_parent(parent)
|
||||||
|
|
||||||
|
|
||||||
|
class DistCatcher(object):
|
||||||
|
|
||||||
|
def __init__(self, directory):
|
||||||
|
self.export_directory = directory
|
||||||
|
self.files = []
|
||||||
|
self.existing_files = None
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
self.existing_files = os.listdir(self.export_directory)
|
||||||
|
return self
|
||||||
|
|
||||||
|
def find_files(self):
|
||||||
|
new_files = os.listdir(self.export_directory)
|
||||||
|
diff_files = set(new_files) - set(self.existing_files)
|
||||||
|
diff = set([n for n in diff_files if get_filetype(n) is not None])
|
||||||
|
if len(diff) == 1:
|
||||||
|
fn = diff.pop()
|
||||||
|
logging.info('Found tarball %s in package directory.', fn)
|
||||||
|
self.files.append(os.path.join(self.export_directory, fn))
|
||||||
|
return fn
|
||||||
|
if 'dist' in diff_files:
|
||||||
|
for entry in os.scandir(
|
||||||
|
os.path.join(self.export_directory, 'dist')):
|
||||||
|
if get_filetype(entry.name) is not None:
|
||||||
|
logging.info(
|
||||||
|
'Found tarball %s in dist directory.', entry.name)
|
||||||
|
self.files.append(entry.path)
|
||||||
|
return entry.name
|
||||||
|
logging.info('No tarballs found in dist directory.')
|
||||||
|
|
||||||
|
parent_directory = os.path.dirname(self.export_directory)
|
||||||
|
diff = set(os.listdir(parent_directory)) - set([subdir])
|
||||||
|
if len(diff) == 1:
|
||||||
|
fn = diff.pop()
|
||||||
|
logging.info('Found tarball %s in parent directory.', fn)
|
||||||
|
self.files.append(os.path.join(parent_directory, fn))
|
||||||
|
return fn
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
self.find_files()
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def create_dist_schroot(
|
def create_dist_schroot(
|
||||||
tree: Tree, target_dir: str,
|
tree: Tree, target_dir: str,
|
||||||
chroot: str, packaging_tree: Optional[Tree] = None,
|
chroot: str, packaging_tree: Optional[Tree] = None,
|
||||||
|
@ -398,47 +441,22 @@ def create_dist_schroot(
|
||||||
else:
|
else:
|
||||||
dupe_vcs_tree(tree, export_directory)
|
dupe_vcs_tree(tree, export_directory)
|
||||||
|
|
||||||
existing_files = os.listdir(export_directory)
|
with DistCatcher(export_directory) as dc:
|
||||||
|
oldcwd = os.getcwd()
|
||||||
|
os.chdir(export_directory)
|
||||||
|
try:
|
||||||
|
session.chdir(os.path.join(reldir, subdir))
|
||||||
|
run_dist(session)
|
||||||
|
except NoBuildToolsFound:
|
||||||
|
logging.info(
|
||||||
|
'No build tools found, falling back to simple export.')
|
||||||
|
return None
|
||||||
|
finally:
|
||||||
|
os.chdir(oldcwd)
|
||||||
|
|
||||||
oldcwd = os.getcwd()
|
for path in dc.files:
|
||||||
os.chdir(export_directory)
|
shutil.copy(path, target_dir)
|
||||||
try:
|
return os.path.join(target_dir, os.path.basename(path))
|
||||||
session.chdir(os.path.join(reldir, subdir))
|
|
||||||
run_dist(session)
|
|
||||||
except NoBuildToolsFound:
|
|
||||||
logging.info(
|
|
||||||
'No build tools found, falling back to simple export.')
|
|
||||||
return None
|
|
||||||
finally:
|
|
||||||
os.chdir(oldcwd)
|
|
||||||
|
|
||||||
new_files = os.listdir(export_directory)
|
|
||||||
diff_files = set(new_files) - set(existing_files)
|
|
||||||
diff = set([n for n in diff_files if get_filetype(n) is not None])
|
|
||||||
if len(diff) == 1:
|
|
||||||
fn = diff.pop()
|
|
||||||
logging.info('Found tarball %s in package directory.', fn)
|
|
||||||
shutil.copy(
|
|
||||||
os.path.join(export_directory, fn),
|
|
||||||
target_dir)
|
|
||||||
return fn
|
|
||||||
if 'dist' in diff_files:
|
|
||||||
for entry in os.scandir(os.path.join(export_directory, 'dist')):
|
|
||||||
if get_filetype(entry.name) is not None:
|
|
||||||
logging.info(
|
|
||||||
'Found tarball %s in dist directory.', entry.name)
|
|
||||||
shutil.copy(entry.path, target_dir)
|
|
||||||
return entry.name
|
|
||||||
logging.info('No tarballs found in dist directory.')
|
|
||||||
|
|
||||||
diff = set(os.listdir(directory)) - set([subdir])
|
|
||||||
if len(diff) == 1:
|
|
||||||
fn = diff.pop()
|
|
||||||
logging.info('Found tarball %s in parent directory.', fn)
|
|
||||||
shutil.copy(
|
|
||||||
os.path.join(directory, fn),
|
|
||||||
target_dir)
|
|
||||||
return fn
|
|
||||||
|
|
||||||
logging.info('No tarball created :(')
|
logging.info('No tarball created :(')
|
||||||
raise DistNoTarball()
|
raise DistNoTarball()
|
||||||
|
|
Loading…
Add table
Reference in a new issue