Refactor if: nesting in build_mirror
Change-Id: Ia0fe43e1f44704d5d93235ceadfcf74d00aa190b
This commit is contained in:
@@ -235,8 +235,7 @@ class Mirror(object):
|
|||||||
if (not branch.startswith("remotes/origin")
|
if (not branch.startswith("remotes/origin")
|
||||||
or "origin/HEAD" in branch):
|
or "origin/HEAD" in branch):
|
||||||
continue
|
continue
|
||||||
print("Fetching pip requires for %s:%s" %
|
print("Fetching pip requires for %s:%s" % (project, branch))
|
||||||
(project, branch))
|
|
||||||
if not self.args.no_update:
|
if not self.args.no_update:
|
||||||
self.run_command("git reset --hard %s" % branch)
|
self.run_command("git reset --hard %s" % branch)
|
||||||
self.run_command("git clean -x -f -d -q")
|
self.run_command("git clean -x -f -d -q")
|
||||||
@@ -250,94 +249,93 @@ class Mirror(object):
|
|||||||
"tools/test-requires"):
|
"tools/test-requires"):
|
||||||
if os.path.exists(requires_file):
|
if os.path.exists(requires_file):
|
||||||
reqlist.append(requires_file)
|
reqlist.append(requires_file)
|
||||||
if reqlist:
|
if not reqlist:
|
||||||
|
print("no requirements")
|
||||||
|
continue
|
||||||
|
|
||||||
|
self.run_command(
|
||||||
|
venv_format % dict(
|
||||||
|
extra_search_dir=pip_cache_dir, venv_dir=venv))
|
||||||
|
for requirement in ["pip", "wheel", "virtualenv"]:
|
||||||
self.run_command(
|
self.run_command(
|
||||||
venv_format % dict(
|
upgrade_format % dict(
|
||||||
extra_search_dir=pip_cache_dir, venv_dir=venv))
|
pip=pip, download_cache=pip_cache_dir,
|
||||||
for requirement in [
|
build_dir=build, find_links=wheelhouse,
|
||||||
"pip", "wheel", "virtualenv"]:
|
requirement=requirement))
|
||||||
self.run_command(
|
for requirement in [
|
||||||
upgrade_format % dict(
|
"pip", "setuptools", "distribute", "virtualenv"]:
|
||||||
pip=pip, download_cache=pip_cache_dir,
|
|
||||||
build_dir=build, find_links=wheelhouse,
|
|
||||||
requirement=requirement))
|
|
||||||
for requirement in [
|
|
||||||
"pip", "setuptools", "distribute", "virtualenv"]:
|
|
||||||
self.run_command(
|
|
||||||
wheel_format % dict(
|
|
||||||
pip=pip, download_cache=pip_cache_dir,
|
|
||||||
find_links=wheelhouse, wheel_dir=wheelhouse,
|
|
||||||
requirement=requirement))
|
|
||||||
if os.path.exists(build):
|
|
||||||
shutil.rmtree(build)
|
|
||||||
new_reqs = self.process_http_requirements(reqlist,
|
|
||||||
pip_cache_dir,
|
|
||||||
pip)
|
|
||||||
(reqfp, reqfn) = tempfile.mkstemp()
|
|
||||||
os.write(reqfp, '\n'.join(new_reqs))
|
|
||||||
os.close(reqfp)
|
|
||||||
self.run_command(
|
self.run_command(
|
||||||
wheel_file_format % dict(
|
wheel_format % dict(
|
||||||
pip=pip, download_cache=pip_cache_dir,
|
pip=pip, download_cache=pip_cache_dir,
|
||||||
find_links=wheelhouse, wheel_dir=wheelhouse,
|
find_links=wheelhouse, wheel_dir=wheelhouse,
|
||||||
requirements_file=reqfn))
|
requirement=requirement))
|
||||||
out = self.run_command(
|
if os.path.exists(build):
|
||||||
pip_format % dict(
|
shutil.rmtree(build)
|
||||||
pip=pip, extra_args="",
|
new_reqs = self.process_http_requirements(reqlist,
|
||||||
download_cache=pip_cache_dir, build_dir=build,
|
pip_cache_dir,
|
||||||
find_links=wheelhouse, requirements_file=reqfn))
|
pip)
|
||||||
if "\nSuccessfully installed " not in out:
|
(reqfp, reqfn) = tempfile.mkstemp()
|
||||||
sys.stderr.write("Installing pip requires for %s:%s "
|
os.write(reqfp, '\n'.join(new_reqs))
|
||||||
"failed.\n%s\n" %
|
os.close(reqfp)
|
||||||
(project, branch, out))
|
self.run_command(
|
||||||
print("pip install did not indicate success")
|
wheel_file_format % dict(
|
||||||
else:
|
pip=pip, download_cache=pip_cache_dir,
|
||||||
freeze = self.run_command("%s freeze -l" % pip)
|
find_links=wheelhouse, wheel_dir=wheelhouse,
|
||||||
requires = self.find_pkg_info(build)
|
requirements_file=reqfn))
|
||||||
reqfd = open(reqs, "w")
|
out = self.run_command(
|
||||||
for line in freeze.split("\n"):
|
pip_format % dict(
|
||||||
if line.startswith("-e ") or (
|
pip=pip, extra_args="",
|
||||||
"==" in line and " " not in line):
|
download_cache=pip_cache_dir, build_dir=build,
|
||||||
requires.add(line)
|
find_links=wheelhouse, requirements_file=reqfn))
|
||||||
for r in requires:
|
if "\nSuccessfully installed " not in out:
|
||||||
reqfd.write(r + "\n")
|
sys.stderr.write("Installing pip requires for %s:%s "
|
||||||
reqfd.close()
|
"failed.\n%s\n" %
|
||||||
self.run_command(venv_format % dict(
|
(project, branch, out))
|
||||||
extra_search_dir=pip_cache_dir, venv_dir=venv))
|
print("pip install did not indicate success")
|
||||||
for requirement in [
|
continue
|
||||||
"pip", "wheel"]:
|
|
||||||
self.run_command(
|
freeze = self.run_command("%s freeze -l" % pip)
|
||||||
upgrade_format % dict(
|
requires = self.find_pkg_info(build)
|
||||||
pip=pip, download_cache=pip_cache_dir,
|
reqfd = open(reqs, "w")
|
||||||
build_dir=build, find_links=wheelhouse,
|
for line in freeze.split("\n"):
|
||||||
requirement=requirement))
|
if line.startswith("-e ") or (
|
||||||
if os.path.exists(build):
|
"==" in line and " " not in line):
|
||||||
shutil.rmtree(build)
|
requires.add(line)
|
||||||
self.run_command(
|
for r in requires:
|
||||||
wheel_file_format % dict(
|
reqfd.write(r + "\n")
|
||||||
pip=pip, download_cache=pip_cache_dir,
|
reqfd.close()
|
||||||
find_links=wheelhouse, wheel_dir=wheelhouse,
|
self.run_command(venv_format % dict(
|
||||||
requirements_file=reqs))
|
extra_search_dir=pip_cache_dir, venv_dir=venv))
|
||||||
out = self.run_command(
|
for requirement in ["pip", "wheel"]:
|
||||||
pip_format % dict(
|
self.run_command(
|
||||||
pip=pip, extra_args="--no-install",
|
upgrade_format % dict(
|
||||||
download_cache=pip_cache_dir, build_dir=build,
|
pip=pip, download_cache=pip_cache_dir,
|
||||||
find_links=wheelhouse, requirements_file=reqs))
|
build_dir=build, find_links=wheelhouse,
|
||||||
if "\nSuccessfully downloaded " not in out:
|
requirement=requirement))
|
||||||
sys.stderr.write("Downloading pip requires for "
|
if os.path.exists(build):
|
||||||
"%s:%s failed.\n%s\n" %
|
shutil.rmtree(build)
|
||||||
(project, branch, out))
|
self.run_command(
|
||||||
print("pip install did not indicate success")
|
wheel_file_format % dict(
|
||||||
print("cached:\n%s" % freeze)
|
pip=pip, download_cache=pip_cache_dir,
|
||||||
# save the list of installed packages to a file
|
find_links=wheelhouse, wheel_dir=wheelhouse,
|
||||||
if self.args.export_file:
|
requirements_file=reqs))
|
||||||
print("Export installed package list to " +
|
out = self.run_command(
|
||||||
self.args.export_file)
|
pip_format % dict(
|
||||||
with open(self.args.export_file, "w") \
|
pip=pip, extra_args="--no-install",
|
||||||
as package_list_file:
|
download_cache=pip_cache_dir, build_dir=build,
|
||||||
package_list_file.write(freeze)
|
find_links=wheelhouse, requirements_file=reqs))
|
||||||
else:
|
if "\nSuccessfully downloaded " not in out:
|
||||||
print("no requirements")
|
sys.stderr.write("Downloading pip requires for "
|
||||||
|
"%s:%s failed.\n%s\n" %
|
||||||
|
(project, branch, out))
|
||||||
|
print("pip install did not indicate success")
|
||||||
|
print("cached:\n%s" % freeze)
|
||||||
|
# save the list of installed packages to a file
|
||||||
|
if self.args.export_file:
|
||||||
|
print("Export installed package list to " +
|
||||||
|
self.args.export_file)
|
||||||
|
with open(self.args.export_file, "w") as package_list_file:
|
||||||
|
package_list_file.write(freeze)
|
||||||
shutil.rmtree(workdir)
|
shutil.rmtree(workdir)
|
||||||
|
|
||||||
def _get_distro(self):
|
def _get_distro(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user