diff --git a/resources/lib/blocked.py b/resources/lib/blocked.py index 4a86540..6bfd43c 100644 --- a/resources/lib/blocked.py +++ b/resources/lib/blocked.py @@ -9,6 +9,7 @@ import xbmcaddon from database_handler import DB_Handler +from utils import log_decorator class Blocked(object): ''' @@ -22,6 +23,7 @@ def __init__(self, mainmenu): self.mainmenu = mainmenu self.dbh = DB_Handler() + @log_decorator def view(self): ''' displays all blocked items, which are selectable and lead to options. @@ -52,6 +54,7 @@ def view(self): return self.mainmenu.view() return self.mainmenu.view() + @log_decorator def options(self, item): ''' provides options for a single blocked item in a dialog window ''' STR_REMOVE = self.addon.getLocalizedString(32017) diff --git a/resources/lib/contentitem.py b/resources/lib/contentitem.py index 3ff4b31..e3dbe96 100644 --- a/resources/lib/contentitem.py +++ b/resources/lib/contentitem.py @@ -15,7 +15,7 @@ import xbmcaddon import database_handler as db -from utils import clean_name, log_msg +from utils import log_msg, log_decorator, clean_name # get tools depending on platform if os.name == 'posix': @@ -103,6 +103,7 @@ class MovieItem(ContentItem): def __init__(self, path, title, mediatype): super(MovieItem, self).__init__(path, title, mediatype) + @log_decorator def add_to_library(self): # parse and fix file/dir names safe_title = clean_name(self.title) @@ -119,11 +120,13 @@ def add_to_library(self): fs.create_stream_file(self.path, filepath) db.DB_Handler().update_content_status(self.path, 'managed') + @log_decorator def remove_from_library(self): safe_title = clean_name(self.title) movie_dir = os.path.join(MANAGED_FOLDER, 'ManagedMovies', safe_title) fs.remove_dir(movie_dir) + @log_decorator def remove_and_block(self): dbh = db.DB_Handler() # add title to blocked @@ -135,6 +138,7 @@ def remove_and_block(self): # remove from db dbh.remove_content_item(self.path) + @log_decorator def create_metadata_item(self): safe_title = clean_name(self.title) movie_dir = os.path.join(MANAGED_FOLDER, 'Metadata', 'Movies', safe_title) @@ -156,6 +160,7 @@ def __init__(self, path, title, mediatype, show_title): def __str__(self): return '[B]%s[/B] - [I]%s[/I]' % (self.title, self.path) + @log_decorator def add_to_library(self): #TODO: add a return value so Staged will know if episode wasn't added # and can display a relevant notification @@ -209,6 +214,7 @@ def add_to_library(self): fs.softlink_file(fanart_path, managed_thumb_path) db.DB_Handler().update_content_status(self.path, 'managed') + @log_decorator def remove_from_library(self): # delete stream & episode metadata safe_title = clean_name(self.title) @@ -223,6 +229,7 @@ def remove_from_library(self): else: fs.remove_dir(show_dir) + @log_decorator def remove_and_block(self): dbh = db.DB_Handler() # add episode title to blocked @@ -235,6 +242,7 @@ def remove_and_block(self): # remove from db dbh.remove_content_item(self.path) + @log_decorator def create_metadata_item(self): #TODO: automatically call this when staging #TODO: actually create basic nfo file with name and episode number, and thumb if possible @@ -271,6 +279,7 @@ def create_metadata_item(self): self.title = new_title db.DB_Handler().update_content_title(self.path, self.title) + @log_decorator def rename(self, name): # rename files if they exist safe_showtitle = clean_name(self.show_title) @@ -288,6 +297,7 @@ def rename(self, name): self.title = name db.DB_Handler().update_content_title(self.path, self.title) + @log_decorator def rename_using_metadata(self): #TODO?: rename show_title too #TODO: recognize old episodes with epid like create_metadata_item diff --git a/resources/lib/main.py b/resources/lib/main.py index 8a29c30..48a66a4 100644 --- a/resources/lib/main.py +++ b/resources/lib/main.py @@ -15,7 +15,7 @@ from staged import StagedMovies, StagedTV from synced import Synced from blocked import Blocked -from utils import log_msg, notification +from utils import log_msg, log_decorator, notification # get tools depending on platform if os.name == 'posix': @@ -77,6 +77,7 @@ def __init__(self): # Open main menu self.view() + @log_decorator def view(self): ''' displays main menu and leads to other modules ''' #TODO: fix update library to only update path diff --git a/resources/lib/managed.py b/resources/lib/managed.py index fbe58b8..cd1b9d7 100644 --- a/resources/lib/managed.py +++ b/resources/lib/managed.py @@ -10,7 +10,7 @@ import xbmcaddon from database_handler import DB_Handler -from utils import notification +from utils import log_decorator, notification class ManagedMovies(object): ''' @@ -25,6 +25,7 @@ def __init__(self, mainmenu): self.mainmenu = mainmenu self.dbh = DB_Handler() + @log_decorator def view_all(self): ''' displays all managed movies, which are selectable and lead to options. @@ -58,9 +59,9 @@ def view_all(self): return self.mainmenu.view() return self.mainmenu.view() + @log_decorator def remove_all(self, items): ''' removes all managed movies from library ''' - #TODO: get managed_movies from previous call STR_REMOVING_ALL_MOVIES = self.addon.getLocalizedString(32013) STR_ALL_MOVIES_REMOVED = self.addon.getLocalizedString(32014) pDialog = xbmcgui.DialogProgress() @@ -72,6 +73,7 @@ def remove_all(self, items): pDialog.close() notification(STR_ALL_MOVIES_REMOVED) + @log_decorator def move_all_to_staged(self, items): ''' removes all managed movies from library, and adds them to staged ''' STR_MOVING_ALL_MOVIES_BACK_TO_STAGED = self.addon.getLocalizedString(32015) @@ -85,6 +87,7 @@ def move_all_to_staged(self, items): pDialog.close() notification(STR_ALL_MOVIES_MOVED_TO_STAGED) + @log_decorator def options(self, item): ''' provides options for a single managed movie in a dialog window ''' # TODO: add rename option @@ -121,6 +124,7 @@ def __init__(self, mainmenu): self.mainmenu = mainmenu self.dbh = DB_Handler() + @log_decorator def view_shows(self): ''' displays all managed tvshows, which are selectable and lead to options. @@ -154,6 +158,7 @@ def view_shows(self): return self.mainmenu.view() return self.mainmenu.view() + @log_decorator def remove_all(self): ''' removes all managed tvshow items from library ''' STR_REMOVING_ALL_TV_SHOWS = self.addon.getLocalizedString(32024) @@ -168,6 +173,7 @@ def remove_all(self): pDialog.close() notification(STR_ALL_TV_SHOWS_REMOVED) + @log_decorator def move_all_to_staged(self): ''' removes all managed tvshow items from library, and adds them to staged ''' STR_MOVING_ALL_TV_SHOWS_BACK_TO_STAGED = self.addon.getLocalizedString(32026) @@ -182,6 +188,7 @@ def move_all_to_staged(self): pDialog.close() notification(STR_ALL_TV_SHOWS_MOVED_TO_STAGED) + @log_decorator def view_episodes(self, show_title): ''' displays all managed episodes in the specified show, @@ -216,6 +223,7 @@ def view_episodes(self, show_title): return self.view_shows() return self.view_shows() + @log_decorator def remove_episodes(self, items): ''' removes all episodes in specified show from library ''' STR_REMOVING_ALL_x_EPISODES = self.addon.getLocalizedString(32032) % show_title @@ -229,6 +237,7 @@ def remove_episodes(self, items): pDialog.close() notification(STR_ALL_x_EPISODES_REMOVED) + @log_decorator def move_episodes_to_staged(self, items): ''' removes all managed episodes in specified show from library, and adds them to staged ''' STR_MOVING_ALL_x_EPISODES_BACK_TO_STAGED = self.addon.getLocalizedString(32034) % show_title @@ -242,6 +251,7 @@ def move_episodes_to_staged(self, items): pDialog.close() notification(STR_ALL_x_EPISODES_MOVED_TO_STAGED) + @log_decorator def episode_options(self, item): ''' provides options for a single managed episode in a dialog window ''' STR_REMOVE = self.addon.getLocalizedString(32017) diff --git a/resources/lib/staged.py b/resources/lib/staged.py index 016be5e..a26e071 100644 --- a/resources/lib/staged.py +++ b/resources/lib/staged.py @@ -10,8 +10,8 @@ import xbmcgui import xbmcaddon -from utils import clean_name, notification from database_handler import DB_Handler +from utils import log_decorator, clean_name, notification # get tools depending on platform if os.name == 'posix': @@ -36,6 +36,7 @@ def __init__(self, mainmenu): self.mainmenu = mainmenu self.dbh = DB_Handler() + @log_decorator def view_all(self): ''' displays all staged movies, which are selectable and lead to options. @@ -79,6 +80,7 @@ def view_all(self): return self.mainmenu.view() return self.mainmenu.view() + @log_decorator def add_all(self, items): ''' adds all staged movies to library ''' STR_ADDING_ALL_MOVIES = self.addon.getLocalizedString(32042) @@ -91,6 +93,7 @@ def add_all(self, items): pDialog.close() notification(STR_ALL_MOVIES_ADDED) + @log_decorator def add_all_with_metadata(self, items): ''' adds all movies with nfo files to the library ''' STR_ADDING_ALL_MOVIES_WITH_METADATA = self.addon.getLocalizedString(32044) @@ -108,6 +111,7 @@ def add_all_with_metadata(self, items): pDialog.close() notification(STR_ALL_MOVIES_WITH_METADTA_ADDED) + @log_decorator def remove_all(self): ''' removes all staged movies ''' STR_REMOVING_ALL_MOVIES = self.addon.getLocalizedString(32013) @@ -118,6 +122,7 @@ def remove_all(self): pDialog.close() notification(STR_ALL_MOVIES_REMOVED) + @log_decorator def generate_all_metadata(self, items): ''' generates metadata items for all staged movies ''' STR_GENERATING_ALL_MOVIE_METADATA = self.addon.getLocalizedString(32046) @@ -130,6 +135,7 @@ def generate_all_metadata(self, items): pDialog.close() notification(STR_ALL_MOVIE_METADTA_CREATED) + @log_decorator def options(self, item): ''' provides options for a single staged movie in a dialog window ''' #TODO: add a back button @@ -186,6 +192,7 @@ def __init__(self, mainmenu): self.mainmenu = mainmenu self.dbh = DB_Handler() + @log_decorator def view_shows(self): ''' displays all managed tvshows, which are selectable and lead to options. @@ -228,6 +235,7 @@ def view_shows(self): return self.mainmenu.view() return self.mainmenu.view() + @log_decorator def add_all_shows(self): ''' adds all tvshow items to library ''' STR_ADDING_ALL_TV_SHOWS = self.addon.getLocalizedString(32059) @@ -241,6 +249,7 @@ def add_all_shows(self): pDialog.close() notification(STR_ALL_TV_SHOWS_ADDED) + @log_decorator def add_all_with_metadata(self): ''' adds all tvshow items with nfo file to library''' STR_ADDING_ALL_TV_SHOW_ITEMS_WITH_METADATA = self.addon.getLocalizedString(32061) @@ -260,6 +269,7 @@ def add_all_with_metadata(self): pDialog.close() notification(STR_ALL_TV_SHOW_ITEMS_WITH_METADATA_ADDED) + @log_decorator def remove_all(self): ''' removes all staged tvshow items ''' STR_REMOVING_ALL_TV_SHOWS = self.addon.getLocalizedString(32024) @@ -270,6 +280,7 @@ def remove_all(self): pDialog.close() notification(STR_ALL_TV_SHOW_REMOVED) + @log_decorator def generate_all_metadata(self): ''' creates metadata for all staged tvshow items ''' STR_GENERATING_ALL_TV_SHOW_METADATA = self.addon.getLocalizedString(32063) @@ -283,6 +294,7 @@ def generate_all_metadata(self): pDialog.close() notification(STR_ALL_TV_SHOW_METADATA_CREATED) + @log_decorator def view_episodes(self, show_title): ''' displays all staged episodes in the specified show, @@ -336,6 +348,7 @@ def view_episodes(self, show_title): return self.view_shows() return self.view_shows() + @log_decorator def add_all_episodes(self, items): ''' adds all episodes from specified show to library ''' STR_ADDING_ALL_x_EPISODES = self.addon.getLocalizedString(32071) % show_title @@ -348,6 +361,7 @@ def add_all_episodes(self, items): pDialog.close() notification(STR_ALL_x_EPISODES_ADDED) + @log_decorator def add_all_episodes_with_metadata(self, items): ''' adds all episodes in the specified show with metadata to the library ''' STR_ADDING_ALL_x_EPISODES_WITH_METADATA = self.addon.getLocalizedString(32073) % show_title @@ -366,6 +380,7 @@ def add_all_episodes_with_metadata(self, items): pDialog.close() notification(STR_ALL_x_EPISODES_WITH_METADATA_ADDED) + @log_decorator def remove_all_episodes(self, show_title): ''' removes all episodes from the specified show ''' STR_REMOVING_ALL_x_EPISODES = self.addon.getLocalizedString(32032) % show_title @@ -376,6 +391,7 @@ def remove_all_episodes(self, show_title): pDialog.close() notification(STR_ALL_x_EPISODES_REMOVED) + @log_decorator def remove_and_block_show(self, show_title): ''' removes all episodes from specified show from the library, @@ -390,6 +406,7 @@ def remove_and_block_show(self, show_title): # add show title to blocked self.dbh.add_blocked_item(show_title, 'tvshow') + @log_decorator def rename_episodes_using_metadata(self, items): ''' automatically renames all episodes in show using nfo files ''' STR_RENAMING_x_EPISODES_USING_METADATA = self.addon.getLocalizedString(32075) % show_title @@ -402,6 +419,7 @@ def rename_episodes_using_metadata(self, items): pDialog.close() notification(STR_x_EPISODES_RENAMED_USING_METADATA) + @log_decorator def generate_all_episodes_metadata(self, items): ''' generates metadata items for all episodes in show ''' STR_GENERATING_ALL_x_METADATA = self.addon.getLocalizedString(32077) % show_title @@ -414,6 +432,7 @@ def generate_all_episodes_metadata(self, items): pDialog.close() notification(STR_ALL_x_METADATA_CREATED) + @log_decorator def episode_options(self, item): ''' provides options for a single staged episode in a dialog window ''' #TODO: rename associated metadata when renaming diff --git a/resources/lib/synced.py b/resources/lib/synced.py index cc12671..265d511 100644 --- a/resources/lib/synced.py +++ b/resources/lib/synced.py @@ -11,7 +11,7 @@ import xbmcgui import xbmcaddon -from utils import notification, log_msg +from utils import log_decorator, notification from database_handler import DB_Handler class Synced(object): @@ -32,8 +32,6 @@ def view(self): also provides additional options at bottom of menu ''' #TODO: update only movies or tvshows - #TODO: sort - #TODO: show title for single movie or tvshow STR_UPDATE_ALL = self.addon.getLocalizedString(32081) STR_REMOVE_ALL = self.addon.getLocalizedString(32082) STR_BACK = self.addon.getLocalizedString(32011) @@ -254,7 +252,6 @@ def update_all(self): for path in paths_to_remove: item = self.dbh.load_item(path) pDialog.update(0, line2=item.get_title()) - log_msg('Removing from library: %s' % item.get_title(), xbmc.LOGNOTICE) item.remove_from_library() item.delete() pDialog.update(0, line2=' ') diff --git a/resources/lib/update_pkl.py b/resources/lib/update_pkl.py index c6a88a2..c07762a 100644 --- a/resources/lib/update_pkl.py +++ b/resources/lib/update_pkl.py @@ -9,13 +9,14 @@ import xbmcaddon import xbmcgui -from utils import log_msg +from utils import log_decorator from database_handler import DB_Handler addon = xbmcaddon.Addon() STR_ADDON_NAME = addon.getAddonInfo('name') MANAGED_FOLDER = addon.getSetting('managed_folder') +@log_decorator def update_managed(): ''' Converts managed.pkl items to SQLite entries ''' managed_file = os.path.join(MANAGED_FOLDER, 'managed.pkl') @@ -31,6 +32,7 @@ def update_managed(): dbh.update_content_status(item.get_path(), 'managed') os.remove(managed_file) +@log_decorator def update_staged(): ''' Converts staged.pkl items to SQLite entries ''' staged_file = os.path.join(MANAGED_FOLDER, 'staged.pkl') @@ -45,6 +47,7 @@ def update_staged(): item.get_show_title()) os.remove(staged_file) +@log_decorator def update_synced(): ''' Converts managed.pkl items to SQLite entries ''' synced_file = os.path.join(MANAGED_FOLDER, 'synced.pkl') @@ -55,6 +58,7 @@ def update_synced(): dbh.add_synced_dir('NULL', item['dir'], item['mediatype']) os.remove(synced_file) +@log_decorator def update_blocked(): ''' Converts blocked.pkl items to SQLite entries ''' blocked_file = os.path.join(MANAGED_FOLDER, 'blocked.pkl') @@ -66,29 +70,25 @@ def update_blocked(): dbh.add_blocked_item(item['label'], item['type']) os.remove(blocked_file) +@log_decorator def main(): ''' main entrypoint for module updates log and progress, and calls all other functions ''' STR_UPDATING = addon.getLocalizedString(32133) - log_msg('Updating .pkl files...', xbmc.LOGNOTICE) pDialog = xbmcgui.DialogProgress() pDialog.create(STR_ADDON_NAME, STR_UPDATING) pDialog.update(0, line2='managed.pkl') update_managed() - log_msg('managed.pkl updated.', xbmc.LOGNOTICE) pDialog.update(25, line2='staged.pkl') update_staged() - log_msg('staged.pkl updated.', xbmc.LOGNOTICE) pDialog.update(50, line2='synced.pkl') update_synced() - log_msg('synced.pkl updated.', xbmc.LOGNOTICE) pDialog.update(75, line2='blocked.pkl') update_blocked() - log_msg('blocked.pkl updated.', xbmc.LOGNOTICE) pDialog.close() diff --git a/resources/lib/utils.py b/resources/lib/utils.py index 2ff5917..f1c9e95 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -44,10 +44,9 @@ def wrapper(*args, **kwargs): ret = func(*args, **kwargs) # define the string for the function call (include class name for methods) is_method = hasattr(args[0].__class__, func.__name__) - if is_method: - func_str = '{0}.{1}'.format(args[0].__class__.__name__, func.__name__) - else: - func_str = '{0}.{1}'.format(func.__module__.replace('resources.lib.', ''), func.__name__) + parent = args[0].__class__.__name__ if is_method \ + else func.__module__.replace('resources.lib.', '') + func_str = '{0}.{1}'.format(parent, func.__name__) # pretty formating for argument string arg_list = list() for arg in args[1 if is_method else 0:]: @@ -92,6 +91,7 @@ def clean_name(s): s = s.replace(k, v) return s +@log_decorator def notification(msg): ''' provides shorthand for xbmc builtin notification with addon name ''' xbmc.executebuiltin('Notification("{0}", "{1}")'.format(STR_ADDON_NAME, msg))