Add library agent to database

This commit is contained in:
JonnyWong16 2018-10-13 17:23:36 -07:00
parent 16733bbe04
commit c70cc535e5
3 changed files with 16 additions and 3 deletions

View file

@ -645,7 +645,7 @@ def dbcheck():
# library_sections table :: This table keeps record of the servers library sections # library_sections table :: This table keeps record of the servers library sections
c_db.execute( c_db.execute(
'CREATE TABLE IF NOT EXISTS library_sections (id INTEGER PRIMARY KEY AUTOINCREMENT, ' 'CREATE TABLE IF NOT EXISTS library_sections (id INTEGER PRIMARY KEY AUTOINCREMENT, '
'server_id TEXT, section_id INTEGER, section_name TEXT, section_type TEXT, ' 'server_id TEXT, section_id INTEGER, section_name TEXT, section_type TEXT, agent TEXT, '
'thumb TEXT, custom_thumb_url TEXT, art TEXT, count INTEGER, parent_count INTEGER, child_count INTEGER, ' 'thumb TEXT, custom_thumb_url TEXT, art TEXT, count INTEGER, parent_count INTEGER, child_count INTEGER, '
'do_notify INTEGER DEFAULT 1, do_notify_created INTEGER DEFAULT 1, keep_history INTEGER DEFAULT 1, ' 'do_notify INTEGER DEFAULT 1, do_notify_created INTEGER DEFAULT 1, keep_history INTEGER DEFAULT 1, '
'deleted_section INTEGER DEFAULT 0, UNIQUE(server_id, section_id))' 'deleted_section INTEGER DEFAULT 0, UNIQUE(server_id, section_id))'
@ -1663,6 +1663,15 @@ def dbcheck():
except sqlite3.OperationalError: except sqlite3.OperationalError:
logger.warn(u"Unable to remove duplicate libraries from library_sections table.") logger.warn(u"Unable to remove duplicate libraries from library_sections table.")
# Upgrade library_sections table from earlier versions
try:
c_db.execute('SELECT agent FROM library_sections')
except sqlite3.OperationalError:
logger.debug(u"Altering database. Updating database table library_sections.")
c_db.execute(
'ALTER TABLE library_sections ADD COLUMN agent TEXT'
)
# Upgrade users table from earlier versions (remove UNIQUE constraint on username) # Upgrade users table from earlier versions (remove UNIQUE constraint on username)
try: try:
result = c_db.execute('SELECT SQL FROM sqlite_master WHERE type="table" AND name="users"').fetchone() result = c_db.execute('SELECT SQL FROM sqlite_master WHERE type="table" AND name="users"').fetchone()

View file

@ -50,6 +50,7 @@ def refresh_libraries():
'section_id': section['section_id'], 'section_id': section['section_id'],
'section_name': section['section_name'], 'section_name': section['section_name'],
'section_type': section['section_type'], 'section_type': section['section_type'],
'agent': section['agent'],
'thumb': section['thumb'], 'thumb': section['thumb'],
'art': section['art'], 'art': section['art'],
'count': section['count'], 'count': section['count'],
@ -923,7 +924,7 @@ class Libraries(object):
monitor_db = database.MonitorDatabase() monitor_db = database.MonitorDatabase()
try: try:
query = 'SELECT section_id, section_name, section_type FROM library_sections WHERE deleted_section = 0' query = 'SELECT section_id, section_name, section_type, agent FROM library_sections WHERE deleted_section = 0'
result = monitor_db.select(query=query) result = monitor_db.select(query=query)
except Exception as e: except Exception as e:
logger.warn(u"Tautulli Libraries :: Unable to execute database query for get_sections: %s." % e) logger.warn(u"Tautulli Libraries :: Unable to execute database query for get_sections: %s." % e)
@ -933,7 +934,8 @@ class Libraries(object):
for item in result: for item in result:
library = {'section_id': item['section_id'], library = {'section_id': item['section_id'],
'section_name': item['section_name'], 'section_name': item['section_name'],
'section_type': item['section_type'] 'section_type': item['section_type'],
'agent': item['agent']
} }
libraries.append(library) libraries.append(library)

View file

@ -2290,6 +2290,7 @@ class PmsConnect(object):
libraries_output = {'section_id': helpers.get_xml_attr(result, 'key'), libraries_output = {'section_id': helpers.get_xml_attr(result, 'key'),
'section_type': helpers.get_xml_attr(result, 'type'), 'section_type': helpers.get_xml_attr(result, 'type'),
'section_name': helpers.get_xml_attr(result, 'title'), 'section_name': helpers.get_xml_attr(result, 'title'),
'agent': helpers.get_xml_attr(result, 'agent'),
'thumb': helpers.get_xml_attr(result, 'thumb'), 'thumb': helpers.get_xml_attr(result, 'thumb'),
'art': helpers.get_xml_attr(result, 'art') 'art': helpers.get_xml_attr(result, 'art')
} }
@ -2450,6 +2451,7 @@ class PmsConnect(object):
library_stats = {'section_id': section_id, library_stats = {'section_id': section_id,
'section_name': library['section_name'], 'section_name': library['section_name'],
'section_type': section_type, 'section_type': section_type,
'agent': library['agent'],
'thumb': library['thumb'], 'thumb': library['thumb'],
'art': library['art'], 'art': library['art'],
'count': children_list['library_count'] 'count': children_list['library_count']