Skip to content

Commit

Permalink
add unified update_content method
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-klein committed Apr 25, 2018
1 parent 08b7a82 commit 3e392b9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
10 changes: 5 additions & 5 deletions resources/lib/contentitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def delete(self):

def set_as_staged(self):
''' sets the item status as staged in database '''
db.DB_Handler().update_content_status(self.path, 'staged')
db.DB_Handler().update_content(self.path, status='staged')

def get_title(self):
''' returns title of video as string '''
Expand Down Expand Up @@ -118,7 +118,7 @@ def add_to_library(self):
fs.rm_strm_in_dir(movie_dir)
# add stream file to movie_dir
fs.create_stream_file(self.path, filepath)
db.DB_Handler().update_content_status(self.path, 'managed')
db.DB_Handler().update_content(self.path, status='managed')

@log_decorator
def remove_from_library(self):
Expand Down Expand Up @@ -211,7 +211,7 @@ def add_to_library(self):
fs.softlink_file(landscape_path, managed_thumb_path)
elif os.path.exists(fanart_path):
fs.softlink_file(fanart_path, managed_thumb_path)
db.DB_Handler().update_content_status(self.path, 'managed')
db.DB_Handler().update_content(self.path, status='managed')

@log_decorator
def remove_from_library(self):
Expand Down Expand Up @@ -276,7 +276,7 @@ def create_metadata_item(self):
# refresh item in staged file if name changed
if new_title != self.title:
self.title = new_title
db.DB_Handler().update_content_title(self.path, self.title)
db.DB_Handler().update_content(self.path, title=self.title)

@log_decorator
def rename(self, name):
Expand All @@ -294,7 +294,7 @@ def rename(self, name):
fs.mv_with_type(title_path, '-thumb.jpg', new_title_path)
# rename property and refresh in staged file
self.title = name
db.DB_Handler().update_content_title(self.path, self.title)
db.DB_Handler().update_content(self.path, title=self.title)

@log_decorator
def rename_using_metadata(self):
Expand Down
27 changes: 12 additions & 15 deletions resources/lib/database_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,19 @@ def add_content_item(self, path, title, mediatype, show_title=None):

@utf8_decorator
@log_decorator
def update_content_status(self, path, status):
''' Updates Status for item in Content with specified path '''
# update item
self.c.execute(
"UPDATE Content SET Status=(?) WHERE Directory=?",
(status, path))
self.db.commit()

@utf8_decorator
@log_decorator
def update_content_title(self, path, title):
''' Updates title for item in Content with specified path '''
def update_content(self, path, **kwargs):
''' Updates a single field for item in Content with specified path '''
#TODO: verify there's only one entry in kwargs
sql_comm = "UPDATE Content SET {0}=(?) WHERE Directory=?"
params = (path,)
for k, v in kwargs.iteritems():
if k == 'status':
sql_comm = sql_comm.format('Status')
elif k == 'title':
sql_comm = sql_comm.format('Title')
params = (v,) + params
# update item
self.c.execute(
"UPDATE Content SET Title=(?) WHERE Directory=?",
(title, path))
self.c.execute(sql_comm, params)
self.db.commit()

@utf8_decorator
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/update_pkl.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def update_managed():
elif item.get_mediatype() == 'tvshow':
dbh.add_content_item(item.get_path(), item.get_title(), 'tvshow', \
item.get_show_title())
dbh.update_content_status(item.get_path(), 'managed')
dbh.update_content(item.get_path(), status='managed')
os.remove(managed_file)

@log_decorator
Expand Down

0 comments on commit 3e392b9

Please sign in to comment.