mirror of
https://github.com/morpheus65535/bazarr
synced 2024-12-25 17:17:12 +00:00
Rework of tasks listing to avoid parsing of string.
This commit is contained in:
parent
f47f107433
commit
98567c4a1c
1 changed files with 31 additions and 46 deletions
|
@ -1558,56 +1558,35 @@ def check_update():
|
||||||
def system():
|
def system():
|
||||||
authorize()
|
authorize()
|
||||||
|
|
||||||
def get_time_from_interval(interval):
|
def get_time_from_interval(td_object):
|
||||||
interval_clean = interval.split('[')
|
seconds = int(td_object.total_seconds())
|
||||||
interval_clean = interval_clean[1][:-1]
|
periods = [
|
||||||
interval_split = interval_clean.split(':')
|
('year', 60 * 60 * 24 * 365),
|
||||||
|
('month', 60 * 60 * 24 * 30),
|
||||||
|
('day', 60 * 60 * 24),
|
||||||
|
('hour', 60 * 60),
|
||||||
|
('minute', 60),
|
||||||
|
('second', 1)
|
||||||
|
]
|
||||||
|
|
||||||
hour = interval_split[0]
|
strings = []
|
||||||
minute = interval_split[1].lstrip("0")
|
for period_name, period_seconds in periods:
|
||||||
second = interval_split[2].lstrip("0")
|
if seconds > period_seconds:
|
||||||
|
period_value, seconds = divmod(seconds, period_seconds)
|
||||||
|
has_s = 's' if period_value > 1 else ''
|
||||||
|
strings.append("%s %s%s" % (period_value, period_name, has_s))
|
||||||
|
|
||||||
text = "every "
|
return ", ".join(strings)
|
||||||
if hour != "0":
|
|
||||||
text = text + hour
|
|
||||||
if hour == "1":
|
|
||||||
text = text + " hour"
|
|
||||||
else:
|
|
||||||
text = text + " hours"
|
|
||||||
|
|
||||||
if minute != "" and second != "":
|
|
||||||
text = text + ", "
|
|
||||||
elif minute == "" and second != "":
|
|
||||||
text = text + " and "
|
|
||||||
elif minute != "" and second == "":
|
|
||||||
text = text + " and "
|
|
||||||
if minute != "":
|
|
||||||
text = text + minute
|
|
||||||
if minute == "1":
|
|
||||||
text = text + " minute"
|
|
||||||
else:
|
|
||||||
text = text + " minutes"
|
|
||||||
|
|
||||||
if second != "":
|
|
||||||
text = text + " and "
|
|
||||||
if second != "":
|
|
||||||
text = text + second
|
|
||||||
if second == "1":
|
|
||||||
text = text + " second"
|
|
||||||
else:
|
|
||||||
text = text + " seconds"
|
|
||||||
|
|
||||||
return text
|
|
||||||
|
|
||||||
def get_time_from_cron(cron):
|
def get_time_from_cron(cron):
|
||||||
text = "at "
|
text = ""
|
||||||
sun = str(cron[4])
|
sun = str(cron[4])
|
||||||
hour = str(cron[5])
|
hour = str(cron[5])
|
||||||
minute = str(cron[6])
|
minute = str(cron[6])
|
||||||
second = str(cron[7])
|
second = str(cron[7])
|
||||||
|
|
||||||
if sun != "*":
|
if sun != "*":
|
||||||
text = "Sunday " + text
|
text = "Sunday at "
|
||||||
|
|
||||||
if hour != "0" and hour != "*":
|
if hour != "0" and hour != "*":
|
||||||
text = text + hour
|
text = text + hour
|
||||||
|
@ -1639,19 +1618,25 @@ def system():
|
||||||
text = text + " second"
|
text = text + " second"
|
||||||
else:
|
else:
|
||||||
text = text + " seconds"
|
text = text + " seconds"
|
||||||
|
if text != "" and sun == "*":
|
||||||
|
text = "everyday at " + text
|
||||||
|
elif text == "":
|
||||||
|
text = "Never"
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
task_list = []
|
task_list = []
|
||||||
for job in scheduler.get_jobs():
|
for job in scheduler.get_jobs():
|
||||||
if job.next_run_time is not None:
|
if isinstance(job.trigger, CronTrigger):
|
||||||
next_run = pretty.date(job.next_run_time.replace(tzinfo=None))
|
if str(job.trigger.__getstate__()['fields'][0]) == "2100":
|
||||||
|
next_run = 'Never'
|
||||||
else:
|
else:
|
||||||
next_run = "Never"
|
next_run = pretty.date(job.next_run_time.replace(tzinfo=None))
|
||||||
|
|
||||||
if job.trigger.__str__().startswith('interval'):
|
if isinstance(job.trigger, IntervalTrigger):
|
||||||
task_list.append([job.name, get_time_from_interval(str(job.trigger)), next_run, job.id])
|
interval = "every " + get_time_from_interval(job.trigger.__getstate__()['interval'])
|
||||||
elif job.trigger.__str__().startswith('cron'):
|
task_list.append([job.name, interval, next_run, job.id])
|
||||||
|
elif isinstance(job.trigger, CronTrigger):
|
||||||
task_list.append([job.name, get_time_from_cron(job.trigger.fields), next_run, job.id])
|
task_list.append([job.name, get_time_from_cron(job.trigger.fields), next_run, job.id])
|
||||||
|
|
||||||
throttled_providers = list_throttled_providers()
|
throttled_providers = list_throttled_providers()
|
||||||
|
|
Loading…
Reference in a new issue