Skip to content

Commit

Permalink
Add command line options to enable and disable jobs (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamstah authored Jul 30, 2024
1 parent 792fc80 commit 6083cec
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format mostly follows [Keep a Changelog](http://keepachangelog.com/en/1.0.0/
### Added

- New `enabled` option for all jobs. Set to false to disable a job without needing to remove it or comment it out (Requested in #625 by snowman, contributed in #785 by jamstah)
- Command line options to enable and disbale jobs (Requested in #813 by gapato, contributed in #820 by jamstah)
- New option `ignore_incomplete_reads` (Requested in #725 by wschoot, contributed in #787 by wfrisch)
- New option `wait_for` in browser jobs (Requested in #763 by yuis-ice, contributed in #810 by jamstah)
- Added tags to jobs and the ability to select them at the command line (#789, #824 by jamstah)
Expand Down
6 changes: 6 additions & 0 deletions docs/source/manpage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ job list management:
--delete JOB
delete job by location or index

--enable JOB
enable job by location or index

--disable JOB
delete job by location or index

--change_location JOB NEW_LOCATION
change the location of an existing job by location or index

Expand Down
20 changes: 20 additions & 0 deletions lib/urlwatch/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,24 @@ def modify_urls(self):
print('Not found: %r' % (self.urlwatch_config.delete,))
save = False

if self.urlwatch_config.enable is not None:
job = self._find_job(self.urlwatch_config.enable)
if job is not None:
job.enabled = True
print(f'Enabled {job!r}')
else:
print(f'Not found: {self.urlwatch_config.enable!r}')
save = False

if self.urlwatch_config.disable is not None:
job = self._find_job(self.urlwatch_config.disable)
if job is not None:
job.enabled = False
print(f'Disabled {job!r}')
else:
print(f'Not found: {self.urlwatch_config.disable!r}')
save = False

if self.urlwatch_config.add is not None:
# Allow multiple specifications of filter=, so that multiple filters can be specified on the CLI
items = [item.split('=', 1) for item in self.urlwatch_config.add.split(',')]
Expand Down Expand Up @@ -262,6 +280,8 @@ def handle_actions(self):
sys.exit(self.list_urls())
if (self.urlwatch_config.add is not None
or self.urlwatch_config.delete is not None
or self.urlwatch_config.enable is not None
or self.urlwatch_config.disable is not None
or self.urlwatch_config.change_location is not None):
sys.exit(self.modify_urls())

Expand Down
2 changes: 2 additions & 0 deletions lib/urlwatch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def parse_args(self, cmdline_args):
group.add_argument('--list', action='store_true', help='list jobs')
group.add_argument('--add', metavar='JOB', help='add job (key1=value1,key2=value2,...)')
group.add_argument('--delete', metavar='JOB', help='delete job by location or index')
group.add_argument('--enable', metavar='JOB', help='enable job by location or index')
group.add_argument('--disable', metavar='JOB', help='disable job by location or index')
group.add_argument('--change-location', metavar=('JOB', 'NEW_LOCATION'), nargs=2, help='change the location of an existing job by location or index')
group.add_argument('--test-filter', metavar='JOB', help='test filter output of job by location or index')
group.add_argument('--test-diff-filter', metavar='JOB',
Expand Down

0 comments on commit 6083cec

Please sign in to comment.