|
|
@ -260,46 +260,14 @@ class ChangeDetectionStore:
|
|
|
|
return self.data['watching'][uuid].get(val)
|
|
|
|
return self.data['watching'][uuid].get(val)
|
|
|
|
|
|
|
|
|
|
|
|
# Remove a watchs data but keep the entry (URL etc)
|
|
|
|
# Remove a watchs data but keep the entry (URL etc)
|
|
|
|
def scrub_watch(self, uuid, limit_timestamp = False):
|
|
|
|
def scrub_watch(self, uuid):
|
|
|
|
|
|
|
|
import pathlib
|
|
|
|
import hashlib
|
|
|
|
|
|
|
|
del_timestamps = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
changes_removed = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for timestamp, path in self.data['watching'][uuid]['history'].items():
|
|
|
|
self.__data['watching'][uuid].update({'history': {}, 'last_checked': 0, 'last_changed': 0, 'newest_history_key': 0, 'previous_md5': False})
|
|
|
|
if not limit_timestamp or (limit_timestamp is not False and int(timestamp) > limit_timestamp):
|
|
|
|
self.needs_write_urgent = True
|
|
|
|
self.unlink_history_file(path)
|
|
|
|
|
|
|
|
del_timestamps.append(timestamp)
|
|
|
|
|
|
|
|
changes_removed += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not limit_timestamp:
|
|
|
|
|
|
|
|
self.data['watching'][uuid]['last_checked'] = 0
|
|
|
|
|
|
|
|
self.data['watching'][uuid]['last_changed'] = 0
|
|
|
|
|
|
|
|
self.data['watching'][uuid]['previous_md5'] = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for timestamp in del_timestamps:
|
|
|
|
|
|
|
|
del self.data['watching'][uuid]['history'][str(timestamp)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# If there was a limitstamp, we need to reset some meta data about the entry
|
|
|
|
|
|
|
|
# This has to happen after we remove the others from the list
|
|
|
|
|
|
|
|
if limit_timestamp:
|
|
|
|
|
|
|
|
newest_key = self.get_newest_history_key(uuid)
|
|
|
|
|
|
|
|
if newest_key:
|
|
|
|
|
|
|
|
self.data['watching'][uuid]['last_checked'] = int(newest_key)
|
|
|
|
|
|
|
|
# @todo should be the original value if it was less than newest key
|
|
|
|
|
|
|
|
self.data['watching'][uuid]['last_changed'] = int(newest_key)
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
with open(self.data['watching'][uuid]['history'][str(newest_key)], "rb") as fp:
|
|
|
|
|
|
|
|
content = fp.read()
|
|
|
|
|
|
|
|
self.data['watching'][uuid]['previous_md5'] = hashlib.md5(content).hexdigest()
|
|
|
|
|
|
|
|
except (FileNotFoundError, IOError):
|
|
|
|
|
|
|
|
self.data['watching'][uuid]['previous_md5'] = ""
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.needs_write = True
|
|
|
|
for item in pathlib.Path(self.datastore_path).rglob(uuid+"/*.txt"):
|
|
|
|
return changes_removed
|
|
|
|
unlink(item)
|
|
|
|
|
|
|
|
|
|
|
|
def add_watch(self, url, tag="", extras=None, write_to_disk_now=True):
|
|
|
|
def add_watch(self, url, tag="", extras=None, write_to_disk_now=True):
|
|
|
|
if extras is None:
|
|
|
|
if extras is None:
|
|
|
@ -453,7 +421,8 @@ class ChangeDetectionStore:
|
|
|
|
import pathlib
|
|
|
|
import pathlib
|
|
|
|
|
|
|
|
|
|
|
|
# Only in the sub-directories
|
|
|
|
# Only in the sub-directories
|
|
|
|
for item in pathlib.Path(self.datastore_path).rglob("*/*txt"):
|
|
|
|
for uuid in self.data['watching']:
|
|
|
|
|
|
|
|
for item in pathlib.Path(self.datastore_path).rglob(uuid+"/*.txt"):
|
|
|
|
if not str(item) in index:
|
|
|
|
if not str(item) in index:
|
|
|
|
print ("Removing",item)
|
|
|
|
print ("Removing",item)
|
|
|
|
unlink(item)
|
|
|
|
unlink(item)
|
|
|
|