Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
packaging
apkg
Commits
b6dd5863
Commit
b6dd5863
authored
Mar 22, 2021
by
Jakub Ružička
Browse files
refactor: os.makedirs -> Path.mkdir
get rid of py35path and "import os" in the process.
parent
a4b52ab9
Changes
9
Hide whitespace changes
Inline
Side-by-side
apkg/lib/ar.py
View file @
b6dd5863
"""
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
.
make
dir
s
(
p
y35path
(
ar_base_path
)
,
exist_ok
=
True
)
ar_base_path
.
mk
dir
(
p
arents
=
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
.
make
dir
s
(
p
y35path
(
ar_base_path
)
,
exist_ok
=
True
)
ar_base_path
.
mk
dir
(
p
arents
=
True
,
exist_ok
=
True
)
archive_path
.
open
(
'wb'
).
write
(
r
.
content
)
log
.
success
(
'downloaded archive: %s'
,
archive_path
)
results
=
[
archive_path
]
...
...
apkg/lib/common.py
View file @
b6dd5863
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
.
make
dir
s
(
p
y35path
(
dst
)
,
exist_ok
=
True
)
dst
.
mk
dir
(
p
arents
=
True
,
exist_ok
=
True
)
dst_full
=
dst
.
resolve
()
new_paths
=
[]
for
p
in
paths
:
...
...
apkg/lib/srcpkg.py
View file @
b6dd5863
"""
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
.
make
dir
s
(
p
y35path
(
build_path
)
,
exist_ok
=
True
)
build_path
.
mk
dir
(
p
arents
=
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
)
...
...
apkg/pkgstyles/arch.py
View file @
b6dd5863
...
...
@@ -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
{})
o
s
.
makedirs
(
out_path
)
o
ut_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
)
o
s
.
make
dir
s
(
p
y35path
(
out_path
)
,
exist_ok
=
True
)
o
ut_path
.
mk
dir
(
p
arents
=
True
,
exist_ok
=
True
)
pkgs
=
[]
# find and copy resulting packages
for
src_pkg
in
glob
.
iglob
(
'%s/*.zst'
%
build_path
):
...
...
apkg/pkgstyles/deb.py
View file @
b6dd5863
...
...
@@ -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
)
o
s
.
make
dir
s
(
p
y35path
(
out_path
)
)
o
ut_path
.
mk
dir
(
p
arents
=
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
.
make
dir
s
(
p
y35path
(
build_path
)
)
o
s
.
make
dir
s
(
p
y35path
(
out_path
)
)
build_path
.
mk
dir
(
p
arents
=
True
)
o
ut_path
.
mk
dir
(
p
arents
=
True
)
isolated
=
kwargs
.
get
(
'isolated'
)
if
isolated
:
log
.
info
(
"starting isolated build using pbuilder"
)
...
...
apkg/pkgstyles/rpm.py
View file @
b6dd5863
...
...
@@ -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
)
o
s
.
make
dir
s
(
p
y35path
(
out_path
)
)
o
ut_path
.
mk
dir
(
p
arents
=
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
)
o
s
.
make
dir
s
(
p
y35path
(
out_path
)
)
o
ut_path
.
mk
dir
(
p
arents
=
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
)
o
s
.
make
dir
s
(
p
y35path
(
out_path
)
)
o
ut_path
.
mk
dir
(
p
arents
=
True
)
for
m
in
re
.
finditer
(
RE_RPMBUILD_OUT_RPM
,
out
):
rpm
=
m
.
group
(
1
)
src_pkg
=
Path
(
rpm
)
...
...
apkg/pkgtemplate.py
View file @
b6dd5863
...
...
@@ -32,13 +32,13 @@ class PackageTemplate:
if
out_path
.
exists
():
log
.
verbose
(
"template render dir exists: %s"
,
out_path
)
else
:
o
s
.
make
dir
s
(
p
y35path
(
out_path
)
,
exist_ok
=
True
)
o
ut_path
.
mk
dir
(
p
arents
=
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
.
make
dir
s
(
p
y35path
(
dst_dir
)
,
exist_ok
=
True
)
dst_dir
.
mk
dir
(
p
arents
=
True
,
exist_ok
=
True
)
for
fn
in
files
:
dst
=
out_path
/
rel_dir
/
fn
...
...
apkg/util/archive.py
View file @
b6dd5863
"""
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
]
o
s
.
makedirs
(
out_path
,
exist_ok
=
True
)
o
ut_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
"
)))
...
...
apkg/util/test.py
View file @
b6dd5863
...
...
@@ -21,7 +21,7 @@ def inject_tree(src_path, dst_path, ignore_dirs=[]):
overwrite existing files
"""
if
not
dst_path
.
exists
():
os
.
make
dir
s
(
p
y35path
(
dst_path
)
,
exist_ok
=
True
)
dst_path
.
mk
dir
(
p
arents
=
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
.
make
dir
s
(
p
y35path
(
dst_dir
)
,
exist_ok
=
True
)
dst_dir
.
mk
dir
(
p
arents
=
True
,
exist_ok
=
True
)
for
fn
in
files
:
dst
=
dst_dir
/
fn
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment