[elbe-devel] [PATCH 3/3] elbepack: pbuilder: move pbuilder actions out of pbuilderaction.py
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Fri Jul 26 10:55:12 CEST 2024
The pbuilder actions are highly specific to the pbuilder subcommand.
There is no reason to have them somewhere else.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
debian/python3-elbe-common.install | 1 -
elbepack/commands/pbuilder.py | 257 +++++++++++++++++++++++++++++++++++-
elbepack/pbuilderaction.py | 258 -------------------------------------
3 files changed, 254 insertions(+), 262 deletions(-)
diff --git a/debian/python3-elbe-common.install b/debian/python3-elbe-common.install
index c1dbd0b42e4f..84aab76ed876 100644
--- a/debian/python3-elbe-common.install
+++ b/debian/python3-elbe-common.install
@@ -31,7 +31,6 @@ usr/lib/python3.*/*-packages/elbepack/isooptions.py
usr/lib/python3.*/*-packages/elbepack/licencexml.py
usr/lib/python3.*/*-packages/elbepack/log.py
usr/lib/python3.*/*-packages/elbepack/packers.py
-usr/lib/python3.*/*-packages/elbepack/pbuilderaction.py
usr/lib/python3.*/*-packages/elbepack/pkgutils.py
usr/lib/python3.*/*-packages/elbepack/qemu_firmware.py
usr/lib/python3.*/*-packages/elbepack/repodir.py
diff --git a/elbepack/commands/pbuilder.py b/elbepack/commands/pbuilder.py
index 1bf16edd2ae3..e7f2f9d6777f 100644
--- a/elbepack/commands/pbuilder.py
+++ b/elbepack/commands/pbuilder.py
@@ -3,10 +3,261 @@
# SPDX-FileCopyrightText: 2015-2017 Linutronix GmbH
import argparse
+import subprocess
+import sys
-from elbepack.cli import add_arguments_from_decorated_function
+from elbepack.cli import add_argument, add_arguments_from_decorated_function
from elbepack.commands.preprocess import add_xmlpreprocess_passthrough_arguments
-from elbepack.pbuilderaction import pbuilder_actions
+from elbepack.directories import run_elbe
+from elbepack.filesystem import TmpdirFilesystem
+from elbepack.xmlpreprocess import preprocess_file
+
+
+ at add_argument('--writeproject', help='write project name to file')
+ at add_argument('--ccache-size', dest='ccachesize', default='10G',
+ help='set a limit for the compiler cache size '
+ '(should be a number followed by an optional '
+ 'suffix: k, M, G, T. Use 0 for no limit.)')
+ at add_argument('--cross', dest='cross', default=False,
+ action='store_true',
+ help='Creates an environment for crossbuilding if '
+ 'combined with create. Combined with build it'
+ ' will use this environment.')
+ at add_argument('--no-ccache', dest='noccache', default=False,
+ action='store_true',
+ help="Deactivates the compiler cache 'ccache'")
+ at add_argument('--xmlfile', help='xmlfile to use')
+ at add_argument('--project', help='project directory on the initvm')
+def _create(args):
+ crossopt = []
+ if args.cross:
+ crossopt = ['--cross']
+ if args.noccache:
+ ccacheopt = ['--no-ccache']
+ else:
+ ccacheopt = ['--ccache-size', args.ccachesize]
+
+ if args.xmlfile:
+ with preprocess_file(args.xmlfile, args.variants) as preproc:
+ ps = run_elbe(['control', 'create_project'],
+ capture_output=True, encoding='utf-8')
+ if ps.returncode != 0:
+ print('elbe control create_project failed.',
+ file=sys.stderr)
+ print(ps.stderr, file=sys.stderr)
+ print('Giving up', file=sys.stderr)
+ sys.exit(152)
+
+ prjdir = ps.stdout.strip()
+ ps = run_elbe(['control', 'set_xml', prjdir, preproc],
+ capture_output=True, encoding='utf-8')
+
+ if ps.returncode != 0:
+ print('elbe control set_xml failed.', file=sys.stderr)
+ print(ps.stderr, file=sys.stderr)
+ print('Giving up', file=sys.stderr)
+ sys.exit(153)
+
+ if args.writeproject:
+ wpf = open(args.writeproject, 'w')
+ wpf.write(prjdir)
+ wpf.close()
+
+ elif args.project:
+ prjdir = args.project
+ else:
+ args.parser.error('you need to specify --project option')
+
+ print('Creating pbuilder')
+
+ try:
+ run_elbe(['control', 'build_pbuilder', prjdir, *crossopt, *ccacheopt],
+ check=True)
+ except subprocess.CalledProcessError:
+ print('elbe control build_pbuilder Failed', file=sys.stderr)
+ print('Giving up', file=sys.stderr)
+ sys.exit(156)
+
+ try:
+ run_elbe(['control', 'wait_busy', prjdir], check=True)
+ except subprocess.CalledProcessError:
+ print('elbe control wait_busy Failed', file=sys.stderr)
+ print('Giving up', file=sys.stderr)
+ sys.exit(157)
+
+ print('')
+ print('Building Pbuilder finished !')
+ print('')
+
+
+ at add_argument('--project', required=True, help='project directory on the initvm')
+def _update(args):
+ prjdir = args.project
+
+ print('Updating pbuilder')
+
+ try:
+ run_elbe(['control', 'update_pbuilder', prjdir], check=True)
+ except subprocess.CalledProcessError:
+ print('elbe control update_pbuilder Failed', file=sys.stderr)
+ print('Giving up', file=sys.stderr)
+ sys.exit(159)
+
+ print('')
+ print('Updating Pbuilder finished !')
+ print('')
+
+
+ at add_argument('--origfile', default=[], action='append', help='upload orig file')
+ at add_argument('--profile', default='', help='profile that shall be built')
+ at add_argument('--skip-download', action='store_true', dest='skip_download', default=False,
+ help='Skip downloading generated Files')
+ at add_argument('--source', dest='srcdir', default='.', help='directory containing sources')
+ at add_argument('--cross', dest='cross', default=False,
+ action='store_true',
+ help='Creates an environment for crossbuilding if '
+ 'combined with create. Combined with build it'
+ ' will use this environment.')
+ at add_argument('--output', dest='outdir', default='..',
+ help='directory where to save downloaded Files')
+ at add_argument('--xmlfile', help='xmlfile to use')
+ at add_argument('--project', help='project directory on the initvm')
+def _build(args):
+ crossopt = []
+ if args.cross:
+ crossopt = ['--cross']
+ tmp = TmpdirFilesystem()
+
+ if args.xmlfile:
+ ps = run_elbe(['control', '--retries', '60', 'create_project', args.xmlfile],
+ capture_output=True, encoding='utf-8')
+ if ps.returncode != 0:
+ print('elbe control create_project failed.', file=sys.stderr)
+ print(ps.stderr, file=sys.stderr)
+ print('Giving up', file=sys.stderr)
+ sys.exit(160)
+
+ prjdir = ps.stdout.strip()
+
+ try:
+ run_elbe(['control', 'build_pbuilder', prjdir], check=True)
+ except subprocess.CalledProcessError:
+ print('elbe control build_pbuilder Failed', file=sys.stderr)
+ print('Giving up', file=sys.stderr)
+ sys.exit(161)
+
+ try:
+ run_elbe(['control', 'wait_busy', prjdir], check=True)
+ except subprocess.CalledProcessError:
+ print('elbe control wait_busy Failed', file=sys.stderr)
+ print('Giving up', file=sys.stderr)
+ sys.exit(162)
+
+ print('')
+ print('Building Pbuilder finished !')
+ print('')
+ elif args.project:
+ prjdir = args.project
+ run_elbe(['control', 'rm_log', prjdir], check=True)
+ else:
+ args.parser.error('you need to specify --project or --xmlfile option')
+
+ print('')
+ print('Packing Source into tmp archive')
+ print('')
+ try:
+ subprocess.run(['tar', '-C', args.srcdir, '-czf', tmp.fname('pdebuild.tar.gz'), '.'],
+ check=True)
+ except subprocess.CalledProcessError:
+ print('tar Failed', file=sys.stderr)
+ print('Giving up', file=sys.stderr)
+ sys.exit(164)
+
+ for of in args.origfile:
+ print('')
+ print(f"Pushing orig file '{of}' into pbuilder")
+ print('')
+ try:
+ run_elbe(['control', 'set_orig', prjdir, of], check=True)
+ except subprocess.CalledProcessError:
+ print('elbe control set_orig Failed', file=sys.stderr)
+ print('Giving up', file=sys.stderr)
+ sys.exit(165)
+
+ print('')
+ print('Pushing source into pbuilder')
+ print('')
+
+ try:
+ run_elbe([
+ 'control', 'set_pdebuild',
+ '--profile', args.profile, *crossopt,
+ prjdir, tmp.fname('pdebuild.tar.gz'),
+ ], check=True)
+ except subprocess.CalledProcessError:
+ print('elbe control set_pdebuild Failed', file=sys.stderr)
+ print('Giving up', file=sys.stderr)
+ sys.exit(166)
+ try:
+ run_elbe(['control', 'wait_busy', prjdir], check=True)
+ except subprocess.CalledProcessError:
+ print('elbe control wait_busy Failed', file=sys.stderr)
+ print('Giving up', file=sys.stderr)
+ sys.exit(167)
+ print('')
+ print('Pdebuild finished !')
+ print('')
+
+ if args.skip_download:
+ print('')
+ print('Listing available files:')
+ print('')
+ try:
+ run_elbe(['control', 'get_files', '--pbuilder-only', prjdir], check=True)
+ except subprocess.CalledProcessError:
+ print('elbe control get_files Failed', file=sys.stderr)
+ print('', file=sys.stderr)
+ print('dumping logfile', file=sys.stderr)
+
+ try:
+ run_elbe(['control', 'dump_file', prjdir, 'log.txt'], check=True)
+ except subprocess.CalledProcessError:
+ print('elbe control dump_file Failed', file=sys.stderr)
+ print('', file=sys.stderr)
+ print('Giving up', file=sys.stderr)
+
+ sys.exit(168)
+
+ print('')
+ print(f"Get Files with: 'elbe control get_file {prjdir} <filename>'")
+ else:
+ print('')
+ print(f'Saving generated Files to {args.outdir}')
+ print('')
+
+ try:
+ run_elbe(['control', 'get_files', '--pbuilder-only',
+ '--output', args.outdir, prjdir], check=True)
+ except subprocess.CalledProcessError:
+ print('elbe control get_files Failed', file=sys.stderr)
+ print('', file=sys.stderr)
+ print('dumping logfile', file=sys.stderr)
+
+ try:
+ run_elbe(['control', 'dump_file', prjdir, 'log.txt'], check=True)
+ except subprocess.CalledProcessError:
+ print('elbe control dump_file Failed', file=sys.stderr)
+ print('', file=sys.stderr)
+ print('Giving up', file=sys.stderr)
+
+ sys.exit(169)
+
+
+_actions = {
+ 'create': _create,
+ 'update': _update,
+ 'build': _build,
+}
def run_command(argv):
@@ -16,7 +267,7 @@ def run_command(argv):
subparsers = aparser.add_subparsers(required=True)
- for action_name, do_action in pbuilder_actions.items():
+ for action_name, do_action in _actions.items():
action_parser = subparsers.add_parser(action_name)
action_parser.set_defaults(func=do_action)
add_arguments_from_decorated_function(action_parser, do_action)
diff --git a/elbepack/pbuilderaction.py b/elbepack/pbuilderaction.py
deleted file mode 100644
index b2e8b2ec14bf..000000000000
--- a/elbepack/pbuilderaction.py
+++ /dev/null
@@ -1,258 +0,0 @@
-# ELBE - Debian Based Embedded Rootfilesystem Builder
-# SPDX-License-Identifier: GPL-3.0-or-later
-# SPDX-FileCopyrightText: 2015-2017 Linutronix GmbH
-
-import subprocess
-import sys
-
-from elbepack.cli import add_argument
-from elbepack.directories import run_elbe
-from elbepack.filesystem import TmpdirFilesystem
-from elbepack.xmlpreprocess import preprocess_file
-
-
- at add_argument('--writeproject', help='write project name to file')
- at add_argument('--ccache-size', dest='ccachesize', default='10G',
- help='set a limit for the compiler cache size '
- '(should be a number followed by an optional '
- 'suffix: k, M, G, T. Use 0 for no limit.)')
- at add_argument('--cross', dest='cross', default=False,
- action='store_true',
- help='Creates an environment for crossbuilding if '
- 'combined with create. Combined with build it'
- ' will use this environment.')
- at add_argument('--no-ccache', dest='noccache', default=False,
- action='store_true',
- help="Deactivates the compiler cache 'ccache'")
- at add_argument('--xmlfile', help='xmlfile to use')
- at add_argument('--project', help='project directory on the initvm')
-def _create(args):
- crossopt = []
- if args.cross:
- crossopt = ['--cross']
- if args.noccache:
- ccacheopt = ['--no-ccache']
- else:
- ccacheopt = ['--ccache-size', args.ccachesize]
-
- if args.xmlfile:
- with preprocess_file(args.xmlfile, args.variants) as preproc:
- ps = run_elbe(['control', 'create_project'],
- capture_output=True, encoding='utf-8')
- if ps.returncode != 0:
- print('elbe control create_project failed.',
- file=sys.stderr)
- print(ps.stderr, file=sys.stderr)
- print('Giving up', file=sys.stderr)
- sys.exit(152)
-
- prjdir = ps.stdout.strip()
- ps = run_elbe(['control', 'set_xml', prjdir, preproc],
- capture_output=True, encoding='utf-8')
-
- if ps.returncode != 0:
- print('elbe control set_xml failed.', file=sys.stderr)
- print(ps.stderr, file=sys.stderr)
- print('Giving up', file=sys.stderr)
- sys.exit(153)
-
- if args.writeproject:
- wpf = open(args.writeproject, 'w')
- wpf.write(prjdir)
- wpf.close()
-
- elif args.project:
- prjdir = args.project
- else:
- args.parser.error('you need to specify --project option')
-
- print('Creating pbuilder')
-
- try:
- run_elbe(['control', 'build_pbuilder', prjdir, *crossopt, *ccacheopt],
- check=True)
- except subprocess.CalledProcessError:
- print('elbe control build_pbuilder Failed', file=sys.stderr)
- print('Giving up', file=sys.stderr)
- sys.exit(156)
-
- try:
- run_elbe(['control', 'wait_busy', prjdir], check=True)
- except subprocess.CalledProcessError:
- print('elbe control wait_busy Failed', file=sys.stderr)
- print('Giving up', file=sys.stderr)
- sys.exit(157)
-
- print('')
- print('Building Pbuilder finished !')
- print('')
-
-
- at add_argument('--project', required=True, help='project directory on the initvm')
-def _update(args):
- prjdir = args.project
-
- print('Updating pbuilder')
-
- try:
- run_elbe(['control', 'update_pbuilder', prjdir], check=True)
- except subprocess.CalledProcessError:
- print('elbe control update_pbuilder Failed', file=sys.stderr)
- print('Giving up', file=sys.stderr)
- sys.exit(159)
-
- print('')
- print('Updating Pbuilder finished !')
- print('')
-
-
- at add_argument('--origfile', default=[], action='append', help='upload orig file')
- at add_argument('--profile', default='', help='profile that shall be built')
- at add_argument('--skip-download', action='store_true', dest='skip_download', default=False,
- help='Skip downloading generated Files')
- at add_argument('--source', dest='srcdir', default='.', help='directory containing sources')
- at add_argument('--cross', dest='cross', default=False,
- action='store_true',
- help='Creates an environment for crossbuilding if '
- 'combined with create. Combined with build it'
- ' will use this environment.')
- at add_argument('--output', dest='outdir', default='..',
- help='directory where to save downloaded Files')
- at add_argument('--xmlfile', help='xmlfile to use')
- at add_argument('--project', help='project directory on the initvm')
-def _build(args):
- crossopt = []
- if args.cross:
- crossopt = ['--cross']
- tmp = TmpdirFilesystem()
-
- if args.xmlfile:
- ps = run_elbe(['control', '--retries', '60', 'create_project', args.xmlfile],
- capture_output=True, encoding='utf-8')
- if ps.returncode != 0:
- print('elbe control create_project failed.', file=sys.stderr)
- print(ps.stderr, file=sys.stderr)
- print('Giving up', file=sys.stderr)
- sys.exit(160)
-
- prjdir = ps.stdout.strip()
-
- try:
- run_elbe(['control', 'build_pbuilder', prjdir], check=True)
- except subprocess.CalledProcessError:
- print('elbe control build_pbuilder Failed', file=sys.stderr)
- print('Giving up', file=sys.stderr)
- sys.exit(161)
-
- try:
- run_elbe(['control', 'wait_busy', prjdir], check=True)
- except subprocess.CalledProcessError:
- print('elbe control wait_busy Failed', file=sys.stderr)
- print('Giving up', file=sys.stderr)
- sys.exit(162)
-
- print('')
- print('Building Pbuilder finished !')
- print('')
- elif args.project:
- prjdir = args.project
- run_elbe(['control', 'rm_log', prjdir], check=True)
- else:
- args.parser.error('you need to specify --project or --xmlfile option')
-
- print('')
- print('Packing Source into tmp archive')
- print('')
- try:
- subprocess.run(['tar', '-C', args.srcdir, '-czf', tmp.fname('pdebuild.tar.gz'), '.'],
- check=True)
- except subprocess.CalledProcessError:
- print('tar Failed', file=sys.stderr)
- print('Giving up', file=sys.stderr)
- sys.exit(164)
-
- for of in args.origfile:
- print('')
- print(f"Pushing orig file '{of}' into pbuilder")
- print('')
- try:
- run_elbe(['control', 'set_orig', prjdir, of], check=True)
- except subprocess.CalledProcessError:
- print('elbe control set_orig Failed', file=sys.stderr)
- print('Giving up', file=sys.stderr)
- sys.exit(165)
-
- print('')
- print('Pushing source into pbuilder')
- print('')
-
- try:
- run_elbe([
- 'control', 'set_pdebuild',
- '--profile', args.profile, *crossopt,
- prjdir, tmp.fname('pdebuild.tar.gz'),
- ], check=True)
- except subprocess.CalledProcessError:
- print('elbe control set_pdebuild Failed', file=sys.stderr)
- print('Giving up', file=sys.stderr)
- sys.exit(166)
- try:
- run_elbe(['control', 'wait_busy', prjdir], check=True)
- except subprocess.CalledProcessError:
- print('elbe control wait_busy Failed', file=sys.stderr)
- print('Giving up', file=sys.stderr)
- sys.exit(167)
- print('')
- print('Pdebuild finished !')
- print('')
-
- if args.skip_download:
- print('')
- print('Listing available files:')
- print('')
- try:
- run_elbe(['control', 'get_files', '--pbuilder-only', prjdir], check=True)
- except subprocess.CalledProcessError:
- print('elbe control get_files Failed', file=sys.stderr)
- print('', file=sys.stderr)
- print('dumping logfile', file=sys.stderr)
-
- try:
- run_elbe(['control', 'dump_file', prjdir, 'log.txt'], check=True)
- except subprocess.CalledProcessError:
- print('elbe control dump_file Failed', file=sys.stderr)
- print('', file=sys.stderr)
- print('Giving up', file=sys.stderr)
-
- sys.exit(168)
-
- print('')
- print(f"Get Files with: 'elbe control get_file {prjdir} <filename>'")
- else:
- print('')
- print(f'Saving generated Files to {args.outdir}')
- print('')
-
- try:
- run_elbe(['control', 'get_files', '--pbuilder-only',
- '--output', args.outdir, prjdir], check=True)
- except subprocess.CalledProcessError:
- print('elbe control get_files Failed', file=sys.stderr)
- print('', file=sys.stderr)
- print('dumping logfile', file=sys.stderr)
-
- try:
- run_elbe(['control', 'dump_file', prjdir, 'log.txt'], check=True)
- except subprocess.CalledProcessError:
- print('elbe control dump_file Failed', file=sys.stderr)
- print('', file=sys.stderr)
- print('Giving up', file=sys.stderr)
-
- sys.exit(169)
-
-
-pbuilder_actions = {
- 'create': _create,
- 'update': _update,
- 'build': _build,
-}
--
2.45.2
More information about the elbe-devel
mailing list