[16] update delete_collections operation

pull/1179/head
meisnate12 2 years ago
parent c43f410e78
commit e7f7cfcff4

@ -1 +1 @@
1.18.0-develop15 1.18.0-develop16

@ -58,12 +58,10 @@ Deletes collections based on a set of given attributes. The Collection must matc
**Values:** There are a few different options to determine how the `delete_collections` works. **Values:** There are a few different options to determine how the `delete_collections` works.
| Attribute | Description | | Attribute | Description |
|:---------------|:----------------------------------------------------------------------------------------------------------------------------------------------------| |:---------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `managed` | Matches with a Collection Managed by PMM (the collection has the `PMM` label).<br>**Default:** `false`<br>**Values:** `true` or `false` | | `managed` | Collection must be a Managed (the collection has the `PMM` label) or Unmanaged (the collection does not have the `PMM` label) Collection.<br>**Values:** `true` (Managed) or `false` (Unmanged) |
| `unmanaged` | Matches with a Collection Unmanaged by PMM (the collection does not have the `PMM` label).<br>**Default:** `false`<br>**Values:** `true` or `false` | | `configured` | Collection must be a Configured (collection is in the specific PMM run) or Unconfigured (collection is not in the specific PMM run) Collection.<br>**Values:** `true` (Configured) or `false` (Unconfigured) |
| `configured` | Matches with a Collection Configured in the specific PMM run.<br>**Default:** `false`<br>**Values:** `true` or `false` | | `less` | Collection must contain less then the given number of items.<br>**Default:** ` `<br>**Values:** Number Greater then 0 |
| `unconfigured` | Matches with a Collection Not Configured in the specific PMM run.<br>**Default:** `false`<br>**Values:** `true` or `false` |
| `less` | Matches with a Collection that contains less then the given number of items.<br>**Default:** ` `<br>**Values:** Number Greater then 0 |
**Example:** **Example:**
@ -74,7 +72,7 @@ library:
Movies: Movies:
operations: operations:
delete_collections: delete_collections:
unconfigured: true configured: false
managed: true managed: true
``` ```

@ -2738,7 +2738,7 @@ class CollectionBuilder:
logger.info(f"Moving {util.item_title(item)} {text}") logger.info(f"Moving {util.item_title(item)} {text}")
previous = item previous = item
except Failed: except Failed:
logger.error(f"Moving {util.item_title(item)} Failed") logger.error(f"Failed to Move {util.item_title(item)}")
def sync_trakt_list(self): def sync_trakt_list(self):
logger.info("") logger.info("")

@ -277,8 +277,9 @@ class ConfigFile:
if isinstance(data[attribute], bool): return data[attribute] if isinstance(data[attribute], bool): return data[attribute]
else: message = f"{text} must be either true or false" else: message = f"{text} must be either true or false"
elif var_type == "int": elif var_type == "int":
if isinstance(data[attribute], int) and data[attribute] >= int_min: return data[attribute] if isinstance(data[attribute], bool): message = f"{text} must an integer >= {int_min}"
else: message = f"{text} must an integer >= 0" elif isinstance(data[attribute], int) and data[attribute] >= int_min: return data[attribute]
else: message = f"{text} must an integer >= {int_min}"
elif var_type == "path": elif var_type == "path":
if os.path.exists(os.path.abspath(data[attribute])): return data[attribute] if os.path.exists(os.path.abspath(data[attribute])): return data[attribute]
else: message = f"Path {os.path.abspath(data[attribute])} does not exist" else: message = f"Path {os.path.abspath(data[attribute])} does not exist"
@ -733,10 +734,8 @@ class ConfigFile:
params[op][old_value] = new_value if new_value else None params[op][old_value] = new_value if new_value else None
if data_type == "delete_collections": if data_type == "delete_collections":
params[op] = { params[op] = {
"managed": check_for_attribute(lib["operations"][op], "managed", var_type="bool", default=False, save=False), "managed": check_for_attribute(lib["operations"][op], "managed", var_type="bool", default_is_none=True, save=False),
"unmanaged": check_for_attribute(lib["operations"][op], "unmanaged", var_type="bool", default=False, save=False), "configured": check_for_attribute(lib["operations"][op], "configured", var_type="bool", default_is_none=True, save=False),
"configured": check_for_attribute(lib["operations"][op], "configured", var_type="bool", default=False, save=False),
"unconfigured": check_for_attribute(lib["operations"][op], "unconfigured", var_type="bool", default=False, save=False),
"less": check_for_attribute(lib["operations"][op], "less", var_type="int", default_is_none=True, save=False, int_min=1), "less": check_for_attribute(lib["operations"][op], "less", var_type="int", default_is_none=True, save=False, int_min=1),
} }
else: else:

@ -234,7 +234,7 @@ class Operations:
def update_rating(attribute, item_attr, display): def update_rating(attribute, item_attr, display):
current = getattr(item, item_attr) current = getattr(item, item_attr)
if attribute in ["remove", "reset"] and current: if attribute in ["remove", "reset"] and current is not None:
item.editField(item_attr, None, locked=attribute == "remove") item.editField(item_attr, None, locked=attribute == "remove")
return f"\n{display} | None" return f"\n{display} | None"
elif attribute in ["unlock", "reset"] and item_attr in locked_fields: elif attribute in ["unlock", "reset"] and item_attr in locked_fields:
@ -514,7 +514,8 @@ class Operations:
logger.info(f"Background | No Reset Image Found") logger.info(f"Background | No Reset Image Found")
if self.library.is_show: if self.library.is_show:
tmdb_seasons = {s.season_number: s for s in tmdb_item.seasons} if tmdb_item else {} real_show = tmdb_item.load_show() if tmdb_item else None
tmdb_seasons = {s.season_number: s for s in real_show.seasons} if real_show else {}
for season in self.library.query(item.seasons): for season in self.library.query(item.seasons):
try: try:
season_poster, season_background, _, _ = self.library.find_item_assets(season, item_asset_directory=item_dir, folder_name=name) season_poster, season_background, _, _ = self.library.find_item_assets(season, item_asset_directory=item_dir, folder_name=name)
@ -704,26 +705,26 @@ class Operations:
if self.library.delete_collections: if self.library.delete_collections:
logger.info("") logger.info("")
logger.separator(f"Deleting All Collections", space=False, border=False) logger.separator(f"Deleting Collections", space=False, border=False)
logger.info("") logger.info("")
less = self.library.delete_collections["less"] if self.library.delete_collections and self.library.delete_collections["less"] is not None else None less = self.library.delete_collections["less"] if self.library.delete_collections and self.library.delete_collections["less"] is not None else None
managed = self.library.delete_collections["managed"] if self.library.delete_collections else False managed = self.library.delete_collections["managed"] if self.library.delete_collections else False
unmanaged = self.library.delete_collections["unmanaged"] if self.library.delete_collections else False
configured = self.library.delete_collections["configured"] if self.library.delete_collections else False configured = self.library.delete_collections["configured"] if self.library.delete_collections else False
unconfigured = self.library.delete_collections["unconfigured"] if self.library.delete_collections else False
unmanaged_collections = [] unmanaged_collections = []
unconfigured_collections = [] unconfigured_collections = []
all_collections = self.library.get_all_collections() all_collections = self.library.get_all_collections()
for i, col in enumerate(all_collections, 1): for i, col in enumerate(all_collections, 1):
logger.ghost(f"Reading Collection: {i}/{len(all_collections)} {col.title}") logger.ghost(f"Reading Collection: {i}/{len(all_collections)} {col.title}")
labels = [la.tag for la in self.library.item_labels(col)] labels = [la.tag for la in self.library.item_labels(col)]
if (less is not None or unmanaged or managed or unconfigured or configured) \ if (less is not None or managed is not None or configured is not None) \
and (less is None or col.childCount < less) \ and (less is None or col.childCount < less) \
and (unmanaged is False or "PMM" not in labels) \ and (managed is None
and (managed is False or "PMM" in labels) \ or (managed is True and "PMM" in labels)
and (unconfigured is False or col.title not in self.library.collections) \ or (managed is False and "PMM" not in labels)) \
and (configured is False or col.title in self.library.collections): and (configured is None
or (configured is True and col.title in self.library.collections)
or (configured is False and col.title not in self.library.collections)):
self.library.query(col.delete) self.library.query(col.delete)
logger.info(f"{col.title} Deleted") logger.info(f"{col.title} Deleted")
else: else:

Loading…
Cancel
Save