Commit b6dd5863 authored by Jakub Ružička's avatar Jakub Ružička
Browse files

refactor: os.makedirs -> Path.mkdir

get rid of py35path and "import os" in the process.
parent a4b52ab9
"""
apkg lib for handling source archives
"""
import os
from pathlib import Path
import shutil
import requests
......@@ -74,7 +73,7 @@ def make_archive(
log.info(msg, archive_fn)
archive_path = ar_base_path / archive_fn
log.info("copying archive to: %s", archive_path)
os.makedirs(py35path(ar_base_path), exist_ok=True)
ar_base_path.mkdir(parents=True, exist_ok=True)
shutil.copy(py35path(in_archive_path), py35path(archive_path))
log.success("made archive: %s", archive_path)
results = [archive_path]
......@@ -126,7 +125,7 @@ def get_archive(
_, _, archive_fn = archive_url.rpartition('/')
archive_path = ar_base_path / archive_fn
log.info('saving archive to: %s', archive_path)
os.makedirs(py35path(ar_base_path), exist_ok=True)
ar_base_path.mkdir(parents=True, exist_ok=True)
archive_path.open('wb').write(r.content)
log.success('downloaded archive: %s', archive_path)
results = [archive_path]
......
import os
from pathlib import Path
import shutil
import sys
......@@ -16,7 +15,7 @@ def copy_paths(paths, dst):
utility to copy a list of paths to dst
"""
if not dst.exists():
os.makedirs(py35path(dst), exist_ok=True)
dst.mkdir(parents=True, exist_ok=True)
dst_full = dst.resolve()
new_paths = []
for p in paths:
......
"""
apkg lib for handling source archives
"""
import os
from pathlib import Path
import shutil
......@@ -114,7 +113,7 @@ def make_srcpkg(
if build_path.exists():
log.info("removing existing build dir: %s", build_path)
shutil.rmtree(py35path(build_path))
os.makedirs(py35path(build_path), exist_ok=True)
build_path.mkdir(parents=True, exist_ok=True)
# ensure output dir doesn't exist unless it was specified
if not result_dir and out_path.exists():
log.info("removing existing result dir: %s", out_path)
......
......@@ -9,7 +9,6 @@ apkg package style for **Arch** linux.
"""
import glob
from pathlib import Path
import os
import shutil
from apkg import exception
......@@ -59,7 +58,7 @@ def build_srcpkg(
out_archive = out_path / archive_path.name
log.info("building arch source package: %s", in_pkgbuild)
template.render(build_path, env or {})
os.makedirs(out_path)
out_path.mkdir(parents=True)
log.info("copying PKGBUILD and archive to: %s", out_path)
shutil.copyfile(in_pkgbuild, out_pkgbuild)
shutil.copyfile(archive_path, out_archive)
......@@ -87,7 +86,7 @@ def build_packages(
with cd(build_path):
run('makepkg', direct='auto')
log.info("copying built packages to result dir: %s", out_path)
os.makedirs(py35path(out_path), exist_ok=True)
out_path.mkdir(parents=True, exist_ok=True)
pkgs = []
# find and copy resulting packages
for src_pkg in glob.iglob('%s/*.zst' % build_path):
......
......@@ -10,7 +10,6 @@ and its many clones such as Ubuntu or Mint.
or `--isolated` using `pbuilder`
"""
import glob
import os
from pathlib import Path
import re
import shutil
......@@ -77,7 +76,7 @@ def build_srcpkg(
source_path = build_path / nv
log.info("building deb source package: %s", nv)
log.info("unpacking archive: %s", archive_path)
os.makedirs(py35path(source_path))
source_path.mkdir(parents=True)
run('aunpack', '-X', build_path, archive_path)
if not source_path.exists():
# NOTE: if this happens oftern (it shouldn't), consider using
......@@ -106,7 +105,7 @@ def build_srcpkg(
direct='auto')
log.info("copying source package to result dir: %s", out_path)
os.makedirs(py35path(out_path))
out_path.mkdir(parents=True)
_copy_srcpkg_files(build_path, out_path)
fns = glob.glob('%s/*' % out_path)
# make sure .dsc is first
......@@ -126,8 +125,8 @@ def build_packages(
srcpkg_paths,
**kwargs):
srcpkg_path = srcpkg_paths[0]
os.makedirs(py35path(build_path))
os.makedirs(py35path(out_path))
build_path.mkdir(parents=True)
out_path.mkdir(parents=True)
isolated = kwargs.get('isolated')
if isolated:
log.info("starting isolated build using pbuilder")
......
......@@ -10,7 +10,6 @@ such as Fedora, CentOS, SUSE, RHEL.
or `--isolated` using `mock`
"""
import glob
import os
from pathlib import Path
import re
import shutil
......@@ -115,7 +114,7 @@ def build_srcpkg(
spec_path)
log.info("copying .src.rpm to result dir: %s", out_path)
os.makedirs(py35path(out_path))
out_path.mkdir(parents=True)
srcpkgs = []
for m in re.finditer(RE_RPMBUILD_OUT_SRPM, out):
srpm = m.group(1)
......@@ -148,7 +147,7 @@ def build_packages(
preserve_env=True,
direct='auto')
log.info("copying built packages to result dir: %s", out_path)
os.makedirs(py35path(out_path))
out_path.mkdir(parents=True)
for rpm in glob.iglob('%s/*.rpm' % build_path):
src_pkg = Path(rpm)
dst_pkg = out_path / src_pkg.name
......@@ -162,7 +161,7 @@ def build_packages(
'--define', '_topdir %s' % rpmbuild_topdir.resolve(),
srcpkg_path)
log.info("copying built packages to result dir: %s", out_path)
os.makedirs(py35path(out_path))
out_path.mkdir(parents=True)
for m in re.finditer(RE_RPMBUILD_OUT_RPM, out):
rpm = m.group(1)
src_pkg = Path(rpm)
......
......@@ -32,13 +32,13 @@ class PackageTemplate:
if out_path.exists():
log.verbose("template render dir exists: %s", out_path)
else:
os.makedirs(py35path(out_path), exist_ok=True)
out_path.mkdir(parents=True, exist_ok=True)
# recursively render all files
for d, _, files in os.walk(py35path(self.path)):
rel_dir = Path(d).relative_to(self.path)
dst_dir = out_path / rel_dir
os.makedirs(py35path(dst_dir), exist_ok=True)
dst_dir.mkdir(parents=True, exist_ok=True)
for fn in files:
dst = out_path / rel_dir / fn
......
"""
apkg archive (tarball) utils
"""
import os
from pathlib import Path
from apkg import exception
......@@ -19,7 +18,7 @@ def unpack_archive(archive_path, out_path):
def root_dir(ps):
return Path(ps).parts[0]
os.makedirs(out_path, exist_ok=True)
out_path.mkdir(parents=True, exist_ok=True)
o = run('aunpack', '-X', out_path, archive_path)
# parse output and make sure there's only a single root dir
root_dirs = set(map(root_dir, o.split("\n")))
......
......@@ -21,7 +21,7 @@ def inject_tree(src_path, dst_path, ignore_dirs=[]):
overwrite existing files
"""
if not dst_path.exists():
os.makedirs(py35path(dst_path), exist_ok=True)
dst_path.mkdir(parents=True, exist_ok=True)
# recursively copy all files
for d, subdirs, files in os.walk(py35path(src_path)):
......@@ -36,7 +36,7 @@ def inject_tree(src_path, dst_path, ignore_dirs=[]):
rel_dir = Path(d).relative_to(src_path)
dst_dir = dst_path / rel_dir
os.makedirs(py35path(dst_dir), exist_ok=True)
dst_dir.mkdir(parents=True, exist_ok=True)
for fn in files:
dst = dst_dir / fn
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment