Skip to content

Commit 65ac0f7

Browse files
authored
Merge pull request #45 from xcp-ng/cleanups
Assorted code cleanups
2 parents 6297417 + c192dba commit 65ac0f7

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

src/xcp_ng_dev/cli.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import subprocess
1414
import shutil
1515
import sys
16-
import uuid
1716
import argcomplete
1817

1918
CONTAINER_PREFIX = "ghcr.io/xcp-ng/xcp-ng-build-env"
@@ -134,7 +133,6 @@ def buildparser():
134133
'separate the arguments for this tool and the command with " -- ".')
135134

136135
# shell -- like run bash
137-
parser_shell = argparse.ArgumentParser()
138136
parser_shell = subparsers_container.add_parser(
139137
'shell',
140138
help='Drop a shell into the prepared container')
@@ -144,7 +142,6 @@ def buildparser():
144142
return parser
145143

146144
def container(args):
147-
build = args.action == 'build'
148145
branch = args.branch
149146
docker_arch = args.platform or ("linux/amd64/v2" if branch == "9.0" else "linux/amd64")
150147

@@ -159,23 +156,22 @@ def container(args):
159156

160157
if hasattr(args, 'command') and args.command != []:
161158
docker_args += ["-e", "COMMAND=%s" % ' '.join(args.command)]
162-
if build:
159+
if args.action == 'build':
163160
build_dir = os.path.abspath(args.source_dir)
164161
docker_args += ["-v", f"{build_dir}:/home/builder/rpmbuild"]
165162
docker_args += ["-e", "BUILD_LOCAL=1"]
166-
print(f"Building directory {build_dir}")
163+
print(f"Building directory {build_dir}", file=sys.stderr)
167164
if hasattr(args, 'define') and args.define:
168165
docker_args += ["-e", "RPMBUILD_DEFINE=%s" % args.define]
169166
if hasattr(args, 'rpmbuild_opts') and args.rpmbuild_opts:
170167
docker_args += ["-e", "RPMBUILD_OPTS=%s" % ' '.join(args.rpmbuild_opts)]
171168
if hasattr(args, 'rpmbuild_stage') and args.rpmbuild_stage:
172169
if args.rpmbuild_stage not in RPMBUILD_STAGES:
173-
parser.error(f"--rpmbuild-stage={args.rpmbuild_stage} not in '{RPMBUILD_STAGES}'")
170+
print(f"--rpmbuild-stage={args.rpmbuild_stage} not in '{RPMBUILD_STAGES}'", file=sys.stderr)
171+
sys.exit(1)
174172
docker_args += ["-e", f"RPMBUILD_STAGE={args.rpmbuild_stage}"]
175173
if hasattr(args, 'output_dir') and args.output_dir:
176-
if not os.path.isdir(args.output_dir):
177-
print(f"{args.output_dir} is not a valid output directory.")
178-
sys.exit(1)
174+
os.makedirs(args.output_dir, exist_ok=True)
179175
docker_args += ["-v", "%s:/home/builder/output" %
180176
os.path.abspath(args.output_dir)]
181177
if args.no_exit:
@@ -191,7 +187,7 @@ def container(args):
191187
if args.dir:
192188
for localdir in args.dir:
193189
if not os.path.isdir(localdir):
194-
print("Local directory argument is not a directory!")
190+
print("Local directory argument is not a directory!", file=sys.stderr)
195191
sys.exit(1)
196192
ext_path = os.path.abspath(localdir)
197193
int_path = os.path.basename(ext_path)

test/test.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ REPOS=xcp-emu-manager
1111
CONTAINER_NAME=${CONTAINER_NAME:-build-env}
1212

1313
for REPO in ${REPOS}; do
14-
REPO_PATH=/tmp/"$REPO"
14+
REPO_PATH=$(mktemp --directory --tmpdir xcp-buildenv-test.XXXXXX)
15+
trap "rm -rf '$REPO_PATH'" EXIT
1516
git clone --branch "$TARGET_XCP_NG_VERSION" https://github.com/xcp-ng-rpms/"$REPO" "$REPO_PATH"
1617

1718
xcp-ng-dev container build "$REPO_PATH" "$TARGET_XCP_NG_VERSION" \
1819
--name "$CONTAINER_NAME" \
1920
--fail-on-error \
2021
--rm
21-
22-
rm -rf "$REPO_PATH"
2322
done

0 commit comments

Comments
 (0)