Skip to content

Commit

Permalink
Style fixes, minor tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorshannon committed Dec 20, 2022
1 parent f0cec7c commit dd10f89
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
24 changes: 13 additions & 11 deletions docs/source/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ Quickly adding new URLs to the job list from the command line::

urlwatch --add url=http://example.org,name=Example

Updating a URL and keeping past history
---------------------------------------

Job history is stored based on the value of the ``url`` parameter, so updating
a job's URL in the configuration file ``urls.yaml`` will create a new job with
no history. Retain history by using ``--change_location``::

urlwatch --change_location http://example.org#old http://example.org#new

The command also works with Browser and Shell jobs, changing ``navigate`` and
``command`` respectively.

Using word-based differences
----------------------------
Expand Down Expand Up @@ -383,6 +372,19 @@ the URLs, like this:
- grep: "Thing B"
Updating a URL and keeping past history
---------------------------------------

Job history is stored based on the value of the ``url`` parameter, so updating
a job's URL in the configuration file ``urls.yaml`` will create a new job with
no history. Retain history by using ``--change_location``::

urlwatch --change_location http://example.org#old http://example.org#new

The command also works with Browser and Shell jobs, changing ``navigate`` and
``command`` respectively.


Running a subset of jobs
------------------------

Expand Down
20 changes: 10 additions & 10 deletions lib/urlwatch/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,17 @@ def modify_urls(self):
if self.urlwatch_config.change_location is not None:
new_loc = self.urlwatch_config.change_location[1]
# Ensure the user isn't overwriting an existing job with the change.
if new_loc in [j.get_location() for j in self.urlwatcher.jobs]:
print('The new location "%s" already exists for a job. Use that'
' existing job or choose a different value.' % new_loc)
if new_loc in (j.get_location() for j in self.urlwatcher.jobs):
print('The new location "%s" already exists for a job. Use that '
'existing job or choose a different value.' % new_loc)
save = False
else:
job = self._find_job(self.urlwatch_config.change_location[0])
if job is not None:
# Update the job's location (which will also update the
# guid) and move any history in the cache over to the job's
# Update the job's location (which will also update the
# guid) and move any history in the cache over to the job's
# updated guid.
print('Moving location of %s to "%s"' % (job, new_loc))
print('Moving location of %r to "%s"' % (job, new_loc))
old_guid = job.get_guid()
old_loc = job.get_location()
job.set_location(new_loc)
Expand All @@ -234,7 +234,7 @@ def modify_urls(self):
if num_moved:
print('Moved %d snapshots of "%s" to "%s"' % (num_moved, old_loc, new_loc))
else:
print('Not found: %r' % self.urlwatch_config.change_location[0])
print('Not found: %s' % self.urlwatch_config.change_location[0])
save = False

if save:
Expand All @@ -260,9 +260,9 @@ def handle_actions(self):
sys.exit(self.dump_history(self.urlwatch_config.dump_history))
if self.urlwatch_config.list:
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.change_location is not None):
if (self.urlwatch_config.add is not None
or self.urlwatch_config.delete is not None
or self.urlwatch_config.change_location is not None):
sys.exit(self.modify_urls())

def check_edit_config(self):
Expand Down
2 changes: 1 addition & 1 deletion lib/urlwatch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ 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('--change_location', metavar=('JOB', 'NEW_LOCATION'), nargs=2, help='change the location of an existing 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',
help='test diff filter output of job by location or index (needs at least 2 snapshots)')
Expand Down
2 changes: 1 addition & 1 deletion lib/urlwatch/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,6 @@ def clean(self, guid):
def move(self, guid, new_guid):
key = self._make_key(guid)
new_key = self._make_key(new_guid)
# Note if a list with 'new_key' already exists, the data stored there
# Note if a list with 'new_key' already exists, the data stored there
# will be overwritten.
self.db.rename(key, new_key)

0 comments on commit dd10f89

Please sign in to comment.