Skip to content

Commit

Permalink
elbepack: migrate os.system to subprocess package
Browse files Browse the repository at this point in the history
The subprocess APIs are more powerful, better documented and
standardized.

Signed-off-by: Thomas Weißschuh <[email protected]>
Reviewed-by: Benedikt Spranger <[email protected]>
  • Loading branch information
t-8ch committed Mar 18, 2024
1 parent b2ebb2c commit 23ed1b4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 52 deletions.
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import subprocess
import sys
sys.path.insert(0, os.path.abspath('..'))


os.system("make")
subprocess.run(['make'], check=True)

# -- General configuration ------------------------------------------------

Expand Down
48 changes: 23 additions & 25 deletions elbepack/commands/toolchainextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import os
import sys
import tempfile
from optparse import OptionParser
from tempfile import mkdtemp

from elbepack.debpkg import build_binary_deb
from elbepack.log import elbe_logging
Expand Down Expand Up @@ -46,36 +46,34 @@ def run_command(argv):
opt.path,
defaults['arch'])

tmpdir = mkdtemp()
with tempfile.TemporaryDirectory() as tmpdir:
for lib in toolchain.pkg_libs:
files = toolchain.get_files_for_pkg(lib)

for lib in toolchain.pkg_libs:
files = toolchain.get_files_for_pkg(lib)
pkglibpath = os.path.join('usr/lib', defaults['triplet'])
fmap = [(f, pkglibpath) for f in files]

pkglibpath = os.path.join('usr/lib', defaults['triplet'])
fmap = [(f, pkglibpath) for f in files]
build_binary_deb(
lib,
defaults['arch'],
defaults['toolchainver'],
lib +
' extracted from toolchain',
fmap,
toolchain.pkg_deps[lib],
tmpdir)

build_binary_deb(
lib,
defaults['arch'],
defaults['toolchainver'],
lib +
' extracted from toolchain',
fmap,
toolchain.pkg_deps[lib],
tmpdir)
pkgs = os.listdir(tmpdir)

pkgs = os.listdir(tmpdir)
with elbe_logging({'streams': sys.stdout}):

with elbe_logging({'streams': sys.stdout}):
repo = ToolchainRepo(defaults['arch'],
opt.codename,
opt.output)

repo = ToolchainRepo(defaults['arch'],
opt.codename,
opt.output)
for p in pkgs:
repo.includedeb(os.path.join(tmpdir, p))

for p in pkgs:
repo.includedeb(os.path.join(tmpdir, p))

repo.finalize()
os.system(f'rm -r "{tmpdir}"')
repo.finalize()

return 0
50 changes: 25 additions & 25 deletions elbepack/debpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
# SPDX-FileCopyrightText: 2014, 2017 Linutronix GmbH

import os
import shutil
import string
from tempfile import mkdtemp
import subprocess
import tempfile

control_template_string = """Package: ${name}
Version: ${version}
Expand Down Expand Up @@ -46,32 +48,30 @@ def build_binary_deb(
deps,
target_dir):

tmpdir = mkdtemp()
pkgfname = f'{name}_{version}_{arch}'
pkgdir = os.path.join(tmpdir, pkgfname)
with tempfile.TemporaryDirectory() as tmpdir:
pkgfname = f'{name}_{version}_{arch}'
pkgdir = os.path.join(tmpdir, pkgfname)

os.system(f'mkdir -p "{os.path.join(pkgdir, "DEBIAN")}"')
write_file(
os.path.join(
pkgdir,
'DEBIAN',
'control'),
0o644,
gen_controlfile(
name,
version,
arch,
description,
deps))
os.makedirs(os.path.join(pkgdir, 'DEBIAN'), exist_ok=True)
write_file(
os.path.join(
pkgdir,
'DEBIAN',
'control'),
0o644,
gen_controlfile(
name,
version,
arch,
description,
deps))

for (fname, instpath) in files:
full_instpath = os.path.join(pkgdir, instpath)
os.system(f'mkdir -p "{full_instpath}"')
os.system(f'cp -a "{fname}" "{full_instpath}"')
for (fname, instpath) in files:
full_instpath = os.path.join(pkgdir, instpath)
os.makedirs(full_instpath, exist_ok=True)
shutil.copyfile(fname, full_instpath)

os.system(f'dpkg-deb --build "{pkgdir}"')
os.system(
f'cp -v "{os.path.join(tmpdir, pkgfname + ".deb")}" "{target_dir}"')
os.system(f'rm -r "{tmpdir}"')
subprocess.run(['dpkg-deb', '--build', pkgdir], check=True)
shutil.copyfile(os.path.join(tmpdir, pkgfname + '.deb'), target_dir)

return pkgfname + '.deb'

0 comments on commit 23ed1b4

Please sign in to comment.