summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbenediktb <benedikt@blablub.de>2013-08-08 22:02:10 +0200
committerbenediktb <benedikt@blablub.de>2013-08-08 22:02:10 +0200
commit3fa2c37bd48ef22937c5644995ac443f557c0871 (patch)
treec7c34da29ffbb92ee49bf68888e0341843835695
parente591fb06b06b5a74893b378b94ee459a56737498 (diff)
Added "runonce" option to updater
When called with "--runonce", the updater now quits after one round of updates instead of running continuously. Can be used for calling the updater as a cronjob. This was easier to accomplish than writing a startup script or anything similar ...
-rw-r--r--bin/updater.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/bin/updater.py b/bin/updater.py
index 4ada726f3..dab7f6f45 100644
--- a/bin/updater.py
+++ b/bin/updater.py
@@ -79,13 +79,14 @@ class UpdateThread(threading.Thread):
class Updater:
- def __init__(self, base_url, thread_num, interval, user, password, timeout):
+ def __init__(self, base_url, thread_num, interval, user, password, timeout, runonce):
self.thread_num = thread_num
self.interval = interval
self.base_url = base_url
self.user = user
self.password = password
self.timeout = timeout
+ self.runonce = runonce
if self.base_url[-1] != '/':
self.base_url += '/'
@@ -117,9 +118,10 @@ class Updater:
for thread in threads:
thread.join()
- # wait until the interval finished to run again
- time.sleep(self.interval)
- self.run()
+ if self.runonce != True:
+ # wait until the interval finished to run again
+ time.sleep(self.interval)
+ self.run()
except (ValueError, urllib.error.HTTPError) as e:
print('%s: %s' % (self.base_url, e))
@@ -127,6 +129,8 @@ class Updater:
def main():
parser = argparse.ArgumentParser()
+ parser.add_argument('--runonce',
+ help='Run update only once', action='store_true')
parser.add_argument('--threads',
help='How many feeds should be fetched in paralell, defaults to 10',
default=10,