From 31c5fbe1e4628a19d9576576205766f466e2d993 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Mon, 27 Jun 2022 16:46:46 -0400 Subject: [PATCH] [68] #914 Added `non_existing` schedule option --- VERSION | 2 +- docs/metadata/details/schedule.md | 21 +++++++++++---------- modules/builder.py | 8 +++++++- modules/util.py | 11 ++++++++++- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/VERSION b/VERSION index 13ef3052..2e2ace2c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.17.0-develop67 +1.17.0-develop68 diff --git a/docs/metadata/details/schedule.md b/docs/metadata/details/schedule.md index de5c0d43..7cb58cfd 100644 --- a/docs/metadata/details/schedule.md +++ b/docs/metadata/details/schedule.md @@ -68,16 +68,17 @@ collections: The scheduling options are: -| Name | Description | Format | Example | -|:--------|:-------------------------------------------------------------------------------------------------|:----------------------|:----------------------------------| -| Hourly | Update only when the script is run in that hour | hourly(Hour of Day) | `hourly(17)` | -| Daily | Update once a day | daily | `daily` | -| Weekly | Update once a week on the specified day | weekly(Day of Week) | `weekly(sunday)` | -| Monthly | Update once a month on the specified day | monthly(Day of Month) | `monthly(1)` | -| Yearly | Update once a year on the specified day | yearly(MM/DD) | `yearly(01/30)` | -| Range | Updates whenever the date is within the range | range(MM/DD-MM/DD) | `range(12/01-12/31)` | -| Never | Never updates | never | `never` | -| All | Requires that all comma separated scheduling options inside its brackets be meet in order to run | all[Options] | `all[weekly(sunday), hourly(17)]` | +| Name | Description | Format | Example | +|:-------------|:-------------------------------------------------------------------------------------------------|:----------------------|:----------------------------------| +| Hourly | Update only when the script is run in that hour | hourly(Hour of Day) | `hourly(17)` | +| Daily | Update once a day | daily | `daily` | +| Weekly | Update once a week on the specified day | weekly(Day of Week) | `weekly(sunday)` | +| Monthly | Update once a month on the specified day | monthly(Day of Month) | `monthly(1)` | +| Yearly | Update once a year on the specified day | yearly(MM/DD) | `yearly(01/30)` | +| Range | Updates whenever the date is within the range | range(MM/DD-MM/DD) | `range(12/01-12/31)` | +| Never | Never updates | never | `never` | +| Non Existing | Updates if it doesn't exist | non_existing | `non_existing` | +| All | Requires that all comma separated scheduling options inside its brackets be meet in order to run | all[Options] | `all[weekly(sunday), hourly(17)]` | * `daily` is the default when `schedule` isn't specified. * You can run the script multiple times per day but using the `--time` command line argument detailed on the [Run Commands & Environmental Variables Page](../../home/environmental.md#time-to-run). diff --git a/modules/builder.py b/modules/builder.py index 5002f9f8..6d744ddc 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -1,7 +1,7 @@ import os, re, time from datetime import datetime from modules import anidb, anilist, flixpatrol, icheckmovies, imdb, letterboxd, mal, plex, radarr, reciperr, sonarr, tautulli, tmdb, trakt, tvdb, mdblist, util -from modules.util import Failed, NotScheduled, NotScheduledRange, Overlay, Deleted +from modules.util import Failed, NonExisting, NotScheduled, NotScheduledRange, Overlay, Deleted from plexapi.audio import Artist, Album, Track from plexapi.exceptions import BadRequest, NotFound from plexapi.video import Movie, Show, Season, Episode @@ -368,6 +368,7 @@ class CollectionBuilder: self.collection_poster = None self.collection_background = None self.exists = False + self.non_existing = False self.created = False self.deleted = False @@ -396,6 +397,8 @@ class CollectionBuilder: err = None try: util.schedule_check("schedule", self.data[methods["schedule"]], self.current_time, self.config.run_hour) + except NonExisting as e: + self.non_existing = str(e) except NotScheduledRange as e: err = e except NotScheduled as e: @@ -771,6 +774,9 @@ class CollectionBuilder: self.obj = None self.sync = False self.run_again = False + if self.non_existing is not False and self.obj: + raise NotScheduled(self.non_existing) + logger.info("") logger.info("Validation Successful") diff --git a/modules/util.py b/modules/util.py index e05c14d9..01dbef3e 100644 --- a/modules/util.py +++ b/modules/util.py @@ -24,6 +24,9 @@ class Failed(Exception): class Deleted(Exception): pass +class NonExisting(Exception): + pass + class NotScheduled(Exception): pass @@ -526,6 +529,7 @@ def check_day(_m, _d): def schedule_check(attribute, data, current_time, run_hour, is_all=False): range_collection = False + non_existing = False all_check = 0 schedules_run = 0 next_month = current_time.replace(day=28) + timedelta(days=4) @@ -553,6 +557,9 @@ def schedule_check(attribute, data, current_time, run_hour, is_all=False): continue elif run_time.startswith(("day", "daily")): all_check += 1 + elif run_time.startswith("non_existing"): + all_check += 1 + non_existing = True elif run_time == "never": schedule_str += f"\nNever scheduled to run" elif run_time.startswith(("hour", "week", "month", "year", "range")): @@ -624,7 +631,9 @@ def schedule_check(attribute, data, current_time, run_hour, is_all=False): if is_all: schedule_str.replace("\n", "\n\t") if (all_check == 0 and not is_all) or (is_all and schedules_run != all_check): - if range_collection: + if non_existing: + raise NonExisting(schedule_str) + elif range_collection: raise NotScheduledRange(schedule_str) else: raise NotScheduled(schedule_str)