Skip to content

Commit

Permalink
Use @log_decorator for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-klein committed Apr 16, 2018
1 parent 089abe2 commit 8c39416
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 19 deletions.
3 changes: 3 additions & 0 deletions resources/lib/blocked.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import xbmcaddon

from database_handler import DB_Handler
from utils import log_decorator

class Blocked(object):
'''
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion resources/lib/contentitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion resources/lib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions resources/lib/managed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
'''
Expand All @@ -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.
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
21 changes: 20 additions & 1 deletion resources/lib/staged.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 8c39416

Please sign in to comment.