Skip to content

Commit

Permalink
feat(cli): watch tasks by default
Browse files Browse the repository at this point in the history
The fatbuildrctl command now attach to task output by default after task
submission, as this is what users would expect in most cases. The
-w, --watch option is replaced by the opposite --batch option to allow
submission of tasks in background.

fix #123
  • Loading branch information
rezib committed Mar 6, 2024
1 parent bd4e186 commit 280897e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 39 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
commands in `fatbuildrctl` manpage.

### Changed
- cli: Watch task output by default when submitting tasks. The `-w, --watch`
option is replaced by the opposite `--batch` option to submit tasks in
background (#123).
- docs:
- Update table of available remote features with new registry content
listing and artifact deletion possibilities.
Expand Down
72 changes: 33 additions & 39 deletions fatbuildr/cli/fatbuildrctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,9 @@ def __init__(self):
help='Force creation of images even they already exist',
)
parser_images_create.add_argument(
'-w',
'--watch',
'--batch',
action='store_true',
help='Watch task log and wait until its end',
help='Submit task in background',
)

# Sub-parser for images update
Expand All @@ -266,10 +265,9 @@ def __init__(self):
help='Update container image for this format',
)
parser_images_update.add_argument(
'-w',
'--watch',
'--batch',
action='store_true',
help='Watch task log and wait until its end',
help='Submit task in background',
)

# Sub-parser for images shell
Expand Down Expand Up @@ -314,10 +312,9 @@ def __init__(self):
help='Create build environments for this hardware architecture',
)
parser_images_env_create.add_argument(
'-w',
'--watch',
'--batch',
action='store_true',
help='Watch task log and wait until its end',
help='Submit task in background',
)

# Sub-parser for images env-update
Expand All @@ -340,10 +337,9 @@ def __init__(self):
help='Update build environments for this hardware architecture',
)
parser_images_env_update.add_argument(
'-w',
'--watch',
'--batch',
action='store_true',
help='Watch task log and wait until its end',
help='Submit task in background',
)

# Sub-parser for images env-shell
Expand Down Expand Up @@ -431,10 +427,9 @@ def __init__(self):
parser_build.add_argument('-e', '--email', help='Maintainer email')
parser_build.add_argument('-m', '--msg', help='Build log message')
parser_build.add_argument(
'-w',
'--watch',
'--batch',
action='store_true',
help='Watch build log and wait until its end',
help='Submit task in background',
)
parser_build.add_argument(
'-i',
Expand Down Expand Up @@ -510,10 +505,9 @@ def __init__(self):
default='list',
)
parser_history.add_argument(
'-w',
'--watch',
'--batch',
action='store_true',
help='Watch task log and wait until its end',
help='Submit task in background',
)

parser_history.set_defaults(func=self._run_history)
Expand Down Expand Up @@ -711,19 +705,19 @@ def select_architectures():
# check if operation is on images and run it
if args.operation == 'create':
for format in select_formats():
self._submit_watch(
self._submit_task(
self.connection.image_create,
f"{format} image creation",
args.watch,
args.batch,
format,
args.force,
)
elif args.operation == 'update':
for format in select_formats():
self._submit_watch(
self._submit_task(
self.connection.image_update,
f"{format} image update",
args.watch,
args.batch,
format,
)
elif args.operation == 'shell':
Expand All @@ -743,10 +737,10 @@ def select_architectures():
sys.exit(1)

selected_format = selected_formats[0]
self._submit_watch(
self._submit_task(
self.connection.image_shell,
f"{selected_format} image shell",
True,
False,
selected_format,
os.getenv('TERM'),
args.command,
Expand All @@ -756,11 +750,11 @@ def select_architectures():
for format in select_formats():
for env in select_build_environments(format):
for architecture in select_architectures():
self._submit_watch(
self._submit_task(
self.connection.image_environment_create,
f"{format} {env}-{architecture} build "
"environment creation",
args.watch,
args.batch,
format,
env,
architecture,
Expand All @@ -769,11 +763,11 @@ def select_architectures():
for format in select_formats():
for env in select_build_environments(format):
for architecture in select_architectures():
self._submit_watch(
self._submit_task(
self.connection.image_environment_update,
f"{format} {env}-{architecture} build "
"environment update",
args.watch,
args.batch,
format,
env,
architecture,
Expand Down Expand Up @@ -844,11 +838,11 @@ def select_architectures():
)
sys.exit(1)
selected_architecture = selected_architectures[0]
self._submit_watch(
self._submit_task(
self.connection.image_environment_shell,
f"{selected_format} {selected_env}-{selected_architecture} "
"build environment shell",
True, # watch
False, # batch
selected_format,
selected_env,
selected_architecture,
Expand Down Expand Up @@ -1107,10 +1101,10 @@ def _run_build(self, args):
)
args.interactive = False

# If user asks for interactive build also force watch feature, otherwise
# interactive would be pointless.
# If user asks for interactive build also force deactivation of batch
# feature, otherwise interactive would be pointless.
if args.interactive:
args.watch = True
args.batch = False

apath = self._get_apath(args)
defs = ArtifactDefs(apath, args.artifact) # load generic artifact defs
Expand Down Expand Up @@ -1167,10 +1161,10 @@ def _run_build(self, args):
# Prepare artifact definition tarball, in fatbuildrd runtime
# directory if connected to fatbuildrd through dbus.
tarball = prepare_tarball(apath, self.connection.scheme == 'dbus')
self._submit_watch(
self._submit_task(
self.connection.build,
f"{args.artifact} build",
args.watch,
args.batch,
format,
distribution,
selected_architectures,
Expand Down Expand Up @@ -1238,10 +1232,10 @@ def _run_patches(self, args):
logger.debug("Removing generated source tarball %s", source.path)
source.path.unlink()

def _submit_watch(self, caller, task_name, watch, *args, interactive=False):
def _submit_task(self, caller, task_name, batch, *args, interactive=False):
task_id = caller(*args)
print(f"Submitted {task_name} task {task_id}")
if watch:
if not batch:
self._watch_task(task_id, interactive)

def _watch_task(self, task_id, interactive):
Expand Down Expand Up @@ -1295,8 +1289,8 @@ def _run_history(self, args):
for task in history:
task.report()
elif args.operation == 'purge':
self._submit_watch(
self.connection.history_purge, 'tasks history purge', args.watch
self._submit_task(
self.connection.history_purge, 'tasks history purge', args.batch
)
else:
NotImplementedError(
Expand Down

0 comments on commit 280897e

Please sign in to comment.