jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/351745 )
Change subject: Bash autocompletion for job names
......................................................................
Bash autocompletion for job names
Changes -l option to just list slugs. run-job -s is the new way to
get full status
Change-Id: Id95fbf223c6a2d61cdd443d6f618577c642a80c9
---
M README.md
M bin/run-job
A tools/autocomplete.sh
3 files changed, 54 insertions(+), 18 deletions(-)
Approvals:
Mepps: Looks good to me, approved
jenkins-bot: Verified
diff --git a/README.md b/README.md
index 13bdd2d..04b735e 100644
--- a/README.md
+++ b/README.md
@@ -42,6 +42,7 @@
Other actions on jobs can be accessed like:
run-job --list-jobs
+ run-job --status
Jobs are listed in a format like so:
diff --git a/bin/run-job b/bin/run-job
index 2f7fa3f..1d4d86a 100755
--- a/bin/run-job
+++ b/bin/run-job
@@ -9,29 +9,36 @@
from processcontrol import job_state
-def list_jobs():
+def list_jobs(verbose):
for job_slug in job_spec.list():
try:
- # FIXME: Nicer if this inner loop moved to Job rather
than having
- # status come from an ephemeral runner.
- job = job_spec.load(job_slug)
- message = "{job} - {name}".format(job=job_slug,
name=job.name)
- status = runner.JobRunner(job).status()
- if status is not None:
- message += " " + yaml.dump(status).strip()
+ if verbose:
+ # FIXME: Nicer if this inner loop moved to Job
rather than having
+ # status come from an ephemeral runner.
+ job = job_spec.load(job_slug)
+ message = "{job} - {name}".format(job=job_slug,
name=job.name)
+ status = runner.JobRunner(job).status()
+ if status is not None:
+ message += " " +
yaml.dump(status).strip()
- # TODO: command-line flag to verbose or not.
- if job.description is not None:
- message += "\n " + job.description
+ # TODO: command-line flag to verbose or not.
+ if job.description is not None:
+ message += "\n " + job.description
- if len(job.tags) > 0:
- message += "\n tags: " + ", ".join(job.tags)
+ if len(job.tags) > 0:
+ message += "\n tags: " + ",
".join(job.tags)
- stored_state = job_state.load_state(job_slug)
- message += "\n last status: " +
stored_state.last_completion_status
+ stored_state = job_state.load_state(job_slug)
+ message += "\n last status: " +
stored_state.last_completion_status
+ else:
+ message = job_slug
except AssertionError:
- message = "{job} ***Invalid
configuration***".format(job=job_slug)
+ if verbose:
+ message = "{job} ***Invalid
configuration***".format(job=job_slug)
+ else:
+ break
+
print(message)
@@ -42,7 +49,8 @@
job_group = parser.add_mutually_exclusive_group()
job_group.add_argument("job", nargs="?", help="Run a given job.",
type=str)
job_group.add_argument("-j", "--job", dest="job_name", help="Run a
given job.", type=str)
- parser.add_argument("-l", "--list-jobs", help="Print a summary of
available jobs.", action='store_true')
+ parser.add_argument("-l", "--list-jobs", help="Print a list of
available jobs.", action='store_true')
+ parser.add_argument("-s", "--status", help="Print status of all jobs",
action='store_true')
# TODO: --kill-job, --disable-group, --enable-group
args = parser.parse_args()
@@ -57,4 +65,7 @@
runner.run()
if args.list_jobs:
- list_jobs()
+ list_jobs(False)
+
+ if args.status:
+ list_jobs(True)
diff --git a/tools/autocomplete.sh b/tools/autocomplete.sh
new file mode 100644
index 0000000..f4adad2
--- /dev/null
+++ b/tools/autocomplete.sh
@@ -0,0 +1,24 @@
+_run-job_complete()
+{
+ local cur_word prev_word possibilities
+ cur_word="${COMP_WORDS[COMP_CWORD]}"
+ prev_word="${COMP_WORDS[COMP_CWORD-1]}"
+
+ possibilities=`run-job -l`
+
+ if [[ ${COMP_CWORD} == 1 ]]
+ then
+ possibilities+=" --job --list-jobs --status"
+ fi
+
+ # autocomplete for -j --job, or nothing
+ if [[ ${prev_word} == "-j" || ${prev_word} == "--job" || ${COMP_CWORD}
== 1 ]]
+ then
+ COMPREPLY=( $(compgen -W "${possibilities}" -- ${cur_word}) )
+ else
+ COMPREPLY=()
+ fi
+ return 0
+}
+
+complete -F _run-job_complete run-job
--
To view, visit https://gerrit.wikimedia.org/r/351745
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id95fbf223c6a2d61cdd443d6f618577c642a80c9
Gerrit-PatchSet: 2
Gerrit-Project: wikimedia/fundraising/process-control
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: AndyRussG <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Eileen <[email protected]>
Gerrit-Reviewer: Katie Horn <[email protected]>
Gerrit-Reviewer: Mepps <[email protected]>
Gerrit-Reviewer: XenoRyet <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits