Skip to content

Commit

Permalink
V2.3 DEV:
Browse files Browse the repository at this point in the history
	Fix:

		#165  LV:		Fixed issue with spaces in filenames

		#166	UAS:	Removed highlight of All after selecting category

		#172	WT:		Fixed issue with Factory reset

		#176	UAS:	Critical error in updateInstallDict

		#178	WT: 	Fixed issue with intruder detection

	New:

		#170	WT:		Added a user guide from Trumpy81. URL is /manual/WebTools-User-Manual.pdf

		#171	PMS:	Added Search to the backend

		#175	PMS: 	Autodownload Repo if json is missing
  • Loading branch information
dagalufh committed May 22, 2016
1 parent 5e8aaee commit 11b00f4
Show file tree
Hide file tree
Showing 27 changed files with 536 additions and 334 deletions.
Binary file modified Contents/Code/Docs/webtools-README_DEVS.odt
Binary file not shown.
9 changes: 5 additions & 4 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

NAME = 'WebTools'
ICON = 'WebTools.png'
VERSION = '2.2'
VERSION = '2.3 DEV'
AUTHTOKEN = ''
SECRETKEY = ''
DEBUGMODE = False
Expand All @@ -28,8 +28,9 @@
from random import randint
import uuid #Used for secrectKey


import datetime
import time


#********** Initialize *********
def Start():
Expand All @@ -41,8 +42,8 @@ def Start():
DEBUGMODE = os.path.isfile(debugFile)
if DEBUGMODE:
VERSION = VERSION + ' ****** WARNING Debug mode on *********'
print("******** Started %s on %s **********" %(NAME + ' V' + VERSION, Platform.OS))
Log.Debug("******* Started %s on %s ***********" %(NAME + ' V' + VERSION, Platform.OS))
print("******** Started %s on %s at %s **********" %(NAME + ' V' + VERSION, Platform.OS, time.strftime("%Y-%m-%d %H:%M")))
Log.Debug("******* Started %s on %s at %s ***********" %(NAME + ' V' + VERSION, Platform.OS, time.strftime("%Y-%m-%d %H:%M")))
HTTP.CacheTime = 0
DirectoryObject.thumb = R(ICON)
ObjectContainer.title1 = NAME + ' V' + VERSION
Expand Down
16 changes: 8 additions & 8 deletions Contents/Code/findMedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import urllib
import unicodedata
import json
import time
import time, sys

# Consts used here
AmountOfMediasInDatabase = 0 # Int of amount of medias in a database section
Expand Down Expand Up @@ -152,10 +152,10 @@ def setSetting(self, req):
req.clear()
req.set_status(200)
except Exception, e:
Log.Debug('Fatal error in setSetting: ' + str(e))
Log.Debug('Fatal error in setSetting: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.finish("Unknown error happened in findMedia-setSetting: " + str(e))
req.finish("Unknown error happened in findMedia-setSetting: " + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))


# Reset settings to default
Expand Down Expand Up @@ -272,7 +272,7 @@ def scanMedias(sectionNumber, sectionLocations, sectionType, req):
except ValueError:
Log.Info('Aborted in ScanMedias')
except Exception, e:
Log.Critical('Exception happend in scanMedias: ' + str(e))
Log.Critical('Exception happend in scanMedias: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
statusMsg = 'Idle'

# Scan the file system
Expand Down Expand Up @@ -320,7 +320,7 @@ def getFiles(filePath):
runningState = 99
Log.Info('Aborted in getFiles')
except Exception, e:
Log.Critical('Exception happend in getFiles: ' + str(e))
Log.Critical('Exception happend in getFiles: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
runningState = 99

def scanShowDB(sectionNumber=0):
Expand Down Expand Up @@ -397,7 +397,7 @@ def scanShowDB(sectionNumber=0):
runningState = 99
Log.Info('Aborted in ScanShowDB')
except Exception, e:
Log.Debug('Fatal error in scanShowDB: ' + str(e))
Log.Debug('Fatal error in scanShowDB: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
runningState = 99
# End scanShowDB

Expand Down Expand Up @@ -440,7 +440,7 @@ def scanMovieDb(sectionNumber=0):
break
return
except Exception, e:
Log.Debug('Fatal error in scanMovieDb: ' + str(e))
Log.Debug('Fatal error in scanMovieDb: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
runningState = 99
# End scanMovieDb

Expand Down Expand Up @@ -472,7 +472,7 @@ def scanMovieDb(sectionNumber=0):
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Scanning already in progress')
except Exception, ex:
Log.Debug('Fatal error happened in scanSection: ' + str(ex))
Log.Debug('Fatal error happened in scanSection: ' + str(ex) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
Expand Down
119 changes: 71 additions & 48 deletions Contents/Code/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,36 @@

import datetime # Used for a timestamp in the dict
import json
import io, os, shutil
import io, os, shutil, sys
import plistlib
import pms
import tempfile

class git(object):
# Defaults used by the rest of the class
init_already = False # Make sure part of init only run once

# Init of the class
def __init__(self):
Log.Debug('******* Starting git *******')
self.url = ''
self.PLUGIN_DIR = Core.storage.join_path(Core.app_support_path, Core.config.bundles_dir_name)
self.UAS_URL = 'https://github.com/ukdtom/UAS2Res'
self.IGNORE_BUNDLE = ['WebTools.bundle', 'SiteConfigurations.bundle', 'Services.bundle']
self.OFFICIAL_APP_STORE = 'https://nine.plugins.plexapp.com'
Log.Debug("Plugin directory is: %s" %(self.PLUGIN_DIR))

# Only init this part once during the lifetime of this
if not git.init_already:
git.init_already = True
Log.Debug('******* Starting git *******')
Log.Debug("Plugin directory is: %s" %(self.PLUGIN_DIR))
# See a few times, that the json file was missing, so here we check, and if not then force a download
try:
jsonFileName = Core.storage.join_path(self.PLUGIN_DIR, NAME + '.bundle', 'http', 'uas', 'Resources', 'plugin_details.json')
if not os.path.isfile(jsonFileName):
Log.Critical('UAS dir was missing the json, so doing a forced download here')
self.updateUASCache(None, cliForce = True)
except Exception, e:
Log.Critical('Exception happend when trying to force download from UASRes: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))

''' Grap the tornado req, and process it for GET request'''
def reqprocess(self, req):
function = req.get_argument('function', 'missing')
Expand Down Expand Up @@ -143,7 +157,7 @@ def removeEmptyFolders(path, removeRoot=True):
Core.storage.save(path, data)
except Exception, e:
bError = True
Log.Critical('Exception happend in downloadBundle2tmp: ' + str(e))
Log.Critical('Exception happend in downloadBundle2tmp: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
else:
# We got a directory here
Log.Debug(filename.split('/')[-2])
Expand All @@ -155,7 +169,7 @@ def removeEmptyFolders(path, removeRoot=True):
Core.storage.ensure_dirs(path)
except Exception, e:
bError = True
Log.Critical('Exception happend in downloadBundle2tmp: ' + str(e))
Log.Critical('Exception happend in downloadBundle2tmp: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
# Now we need to nuke files that should no longer be there!
for root, dirs, files in os.walk(bundleName):
for fname in files:
Expand All @@ -174,7 +188,7 @@ def removeEmptyFolders(path, removeRoot=True):
except Exception, e:
Log.Critical('***************************************************************')
Log.Critical('Error when updating WebTools')
Log.Critical('The error was: ' + str(e))
Log.Critical('The error was: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
Log.Critical('***************************************************************')
Log.Critical('DARN....When we tried to upgrade WT, we had an error :-(')
Log.Critical('Only option now might be to do a manual install, like you did the first time')
Expand Down Expand Up @@ -212,7 +226,7 @@ def getUpdateList(self, req):
req.clear()
req.set_status(204)
except Exception, e:
Log.Debug('Fatal error happened in getUpdateList: ' + str(e))
Log.Critical('Fatal error happened in getUpdateList: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
Expand All @@ -238,7 +252,7 @@ def getUASCacheList():
results[title] = git
return results
except Exception, e:
Log.Debug('Exception in Migrate/getUASCacheList : ' + str(e))
Log.Critical('Exception in Migrate/getUASCacheList : ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
return ''

# Grap indentifier from plist file and timestamp
Expand Down Expand Up @@ -343,11 +357,11 @@ def getIdentifier(pluginDir):
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish(json.dumps(migratedBundles))
except Exception, e:
Log.Critical('Fatal error happened in migrate: ' + str(e))
Log.Critical('Fatal error happened in migrate: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Fatal error happened in migrate: ' + str(e))
req.finish('Fatal error happened in migrate: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
return req

''' This will return a list of UAS bundle types from the UAS Cache '''
Expand All @@ -359,17 +373,20 @@ def uasTypes(self, req):
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish(json.dumps(Dict['uasTypes']))
except Exception, e:
Log.Critical('Exception in uasTypes: ' + str(e))
Log.Critical('Exception in uasTypes: ' + str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Fatal error happened in uasTypes: ' + str(e))
return req

''' This will update the UAS Cache directory from GitHub '''
def updateUASCache(self, req):
def updateUASCache(self, req, cliForce= False):
Log.Debug('Starting to update the UAS Cache')
debugForce = ('false' != req.get_argument('debugForce', 'false'))
if not cliForce:
Force = ('false' != req.get_argument('Force', 'false'))
else:
Force = True
# Main call
try:
# Start by getting the time stamp for the last update
Expand All @@ -383,38 +400,42 @@ def updateUASCache(self, req):
# Now get the last update time from the UAS repository on GitHub
masterUpdate = datetime.datetime.strptime(self.getLastUpdateTime(req, True, self.UAS_URL), '%Y-%m-%d %H:%M:%S')
# Do we need to update the cache, and add 2 min. tolerance here?
if ((masterUpdate - lastUpdateUAS) > datetime.timedelta(seconds = 120) or debugForce):
if ((masterUpdate - lastUpdateUAS) > datetime.timedelta(seconds = 120) or Force):
# We need to update UAS Cache
# Target Directory
targetDir = Core.storage.join_path(self.PLUGIN_DIR, NAME + '.bundle', 'http', 'uas')
# Force creation, if missing
try:
Core.storage.ensure_dirs(targetDir)
except Exception, e:
errMsg = str(e)
errMsg = str(e) + 'on line {}'.format(sys.exc_info()[-1].tb_lineno)
if 'Errno 13' in errMsg:
errMsg = errMsg + '\n\nLooks like permissions are not correct, cuz we where denied access\n'
errMsg = errMsg + 'to create a needed directory.\n\n'
errMsg = errMsg + 'If running on Linux, you might have to issue:\n'
errMsg = errMsg + 'sudo chown plex:plex ./WebTools.bundle -R\n'
errMsg = errMsg + 'And if on Synology, the command is:\n'
errMsg = errMsg + 'sudo chown plex:users ./WebTools.bundle -R\n'
Log.Critical('Exception in updateUASCache ' + str(e))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Exception in updateUASCache: ' + errMsg)
return req
Log.Critical('Exception in updateUASCache ' + errMsg)
if not cliForce:
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Exception in updateUASCache: ' + errMsg)
return req
else:
return
# Grap file from Github
try:
zipfile = Archive.ZipFromURL(self.UAS_URL+ '/archive/master.zip')
except Exception, e:
Log.Critical('Could not download UAS Repo from GitHub')
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Exception in updateUASCache while downloading UAS repo from Github: ' + str(e))
return req
Log.Critical('Could not download UAS Repo from GitHub' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
if not cliForce:
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Exception in updateUASCache while downloading UAS repo from Github: ' + str(e)+ ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
return req
for filename in zipfile:
# Walk contents of the zip, and extract as needed
data = zipfile[filename]
Expand All @@ -426,7 +447,7 @@ def updateUASCache(self, req):
Core.storage.save(path, data)
except Exception, e:
bError = True
Log.Critical("Unexpected Error " + str(e))
Log.Critical("Unexpected Error " + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
else:
# We got a directory here
Log.Debug(filename.split('/')[-2])
Expand All @@ -438,25 +459,27 @@ def updateUASCache(self, req):
Core.storage.ensure_dirs(path)
except Exception, e:
bError = True
Log.Critical("Unexpected Error " + str(e))
Log.Critical("Unexpected Error " + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
# Update the AllBundleInfo as well
pms.updateAllBundleInfoFromUAS()
pms.updateUASTypesCounters()
else:
Log.Debug('UAS Cache already up to date')
# Set timestamp in the Dict
Dict['UAS'] = datetime.datetime.now()
req.clear()
req.set_status(200)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('UASCache is up to date')
if not cliForce:
req.clear()
req.set_status(200)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('UASCache is up to date')
except Exception, e:
Log.Critical('Exception in updateUASCache ' + str(e))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Exception in updateUASCache ' + str(e))
return req
Log.Critical('Exception in updateUASCache ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
if not cliForce:
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Exception in updateUASCache ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
return req

''' list will return a list of all installed gits from GitHub'''
def list(self, req):
Expand Down Expand Up @@ -581,7 +604,7 @@ def removeEmptyFolders(path, removeRoot=True):
# Grap file from Github
zipfile = Archive.ZipFromURL(zipPath)
except Exception, e:
Log.Critical('Exception in downloadBundle2tmp while downloading from GitHub: ' + str(e))
Log.Critical('Exception in downloadBundle2tmp while downloading from GitHub: ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
return False
# Create base directory
Core.storage.ensure_dirs(Core.storage.join_path(self.PLUGIN_DIR, bundleName))
Expand Down Expand Up @@ -610,7 +633,7 @@ def removeEmptyFolders(path, removeRoot=True):
Log.Debug('Install is an upgrade')
break
except Exception, e:
Log.Critical('Exception in downloadBundle2tmp while walking the downloaded file to find the plist: ' + str(e))
Log.Critical('Exception in downloadBundle2tmp while walking the downloaded file to find the plist: ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
return False
if bUpgrade:
# Since this is an upgrade, we need to check, if the dev wants us to delete the Cache directory
Expand Down Expand Up @@ -661,7 +684,7 @@ def removeEmptyFolders(path, removeRoot=True):
Core.storage.save(path, data)
except Exception, e:
bError = True
Log.Critical('Exception happend in downloadBundle2tmp: ' + str(e))
Log.Critical('Exception happend in downloadBundle2tmp: ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
else:
if cutStr not in filename:
continue
Expand All @@ -676,7 +699,7 @@ def removeEmptyFolders(path, removeRoot=True):
Core.storage.ensure_dirs(path)
except Exception, e:
bError = True
Log.Critical('Exception happend in downloadBundle2tmp: ' + str(e))
Log.Critical('Exception happend in downloadBundle2tmp: ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))

if not bError and bUpgrade:
# Copy files that should be kept between upgrades ("keepFiles")
Expand Down Expand Up @@ -724,7 +747,7 @@ def removeEmptyFolders(path, removeRoot=True):
shutil.move(extractDir, bundleName)
except Exception, e:
bError = True
Log.Critical('Unable to update plugin: ' + str(e))
Log.Critical('Unable to update plugin: ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))

# Delete temporary directory
try:
Expand Down Expand Up @@ -753,7 +776,7 @@ def removeEmptyFolders(path, removeRoot=True):
pass
return True
except Exception, e:
Log.Critical('Exception in downloadBundle2tmp: ' + str(e))
Log.Critical('Exception in downloadBundle2tmp: ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
return False

# Starting install main
Expand Down Expand Up @@ -824,11 +847,11 @@ def getLastUpdateTime(self, req, UAS=False, url=''):
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish(str(response))
except Exception, e:
Log.Critical('Fatal error happened in getLastUpdateTime for :' + url + ' was: ' + str(e))
Log.Critical('Fatal error happened in getLastUpdateTime for :' + url + ' was: ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Fatal error happened in getLastUpdateTime for :' + url + ' was: ' + str(e))
req.finish('Fatal error happened in getLastUpdateTime for :' + url + ' was: ' + str(e) + ' on line {}'.format(sys.exc_info()[-1].tb_lineno))

''' Get list of avail bundles in the UAS '''
def getListofBundles(self, req):
Expand Down
Loading

0 comments on commit 11b00f4

Please sign in to comment.