Skip to content

Commit

Permalink
V2.2-DEV:
Browse files Browse the repository at this point in the history
Internal Note:

	Here we collect stuff that needs to go into the real released changelog, aka acumulated, and only since 2.1 changes here ;-)

BACKEND:

	Fix:

		#115 UAS: Migration fails, if plugin directory contains hidden folder

		#116 UAS: Make UAS work, even if a git is dir levels too low

		#117 UAS and uninstall unknown bundle

		#121 UAS: Cleanup old files/folders when updating

		#122 UAS: bundle migration

		#138 UAS: getAllBundleInfo is reset when UASRepo is updated

	New:

		#129 UAS: Alllow 3.Party devs to clear their stuff

		#135 WT: Tell users, if wrong install path is used

		#137 WT: Add new decorator for auth

		#126 UAS: Allow WebTools to autoupdate

FRONTEND:

	Fix:

		#131 UAS: After changin category, focus is no longer set on inputbox

		#139 UAS: Unknown bundles without url won't be able to be uninstalled or re-installed.

		#140 UAS: Migrate now always goes back to showing ALL available bundles

	New:

		#126 UAS: Allow WebTools to autoupdate

		#142 LogViewer: Search for keywords, highlighting of the same. Jump to top.

		#133 Subtitlemgmt: Added GUI for uploading subtitles

		#112 Subtitlemgmt: Allow delete/view for agent subtitles aswell.
  • Loading branch information
dagalufh committed Mar 3, 2016
1 parent 0100a04 commit 2467ea7
Show file tree
Hide file tree
Showing 10 changed files with 340 additions and 107 deletions.
Binary file modified Contents/Code/Docs/webtools-README_DEVS.odt
Binary file not shown.
13 changes: 9 additions & 4 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ def Start():
DEBUGMODE = os.path.isfile(debugFile)
if DEBUGMODE:
VERSION = VERSION + ' ****** WARNING Debug mode on *********'
PLUGIN_VERSION = VERSION
print("******** Started %s on %s **********" %(NAME + ' V' + PLUGIN_VERSION, Platform.OS))
Log.Debug("******* Started %s on %s ***********" %(NAME + ' V' + PLUGIN_VERSION, Platform.OS))
print("******** Started %s on %s **********" %(NAME + ' V' + VERSION, Platform.OS))
Log.Debug("******* Started %s on %s ***********" %(NAME + ' V' + VERSION, Platform.OS))
HTTP.CacheTime = 0
DirectoryObject.thumb = R(ICON)
ObjectContainer.title1 = NAME + ' V' + PLUGIN_VERSION
ObjectContainer.title1 = NAME + ' V' + VERSION
Plugin.AddViewGroup('List', viewMode='List', mediaType='items')
ObjectContainer.view_group = 'List'
makeSettings()
Expand Down Expand Up @@ -97,6 +96,12 @@ def makeSettings():
# Create the pwdset entry
if Dict['pwdset'] == None:
Dict['pwdset'] = False
# Init the installed dict
if Dict['installed'] == None:
Dict['installed'] = {}
# Init the allBundle Dict
if Dict['PMS-AllBundleInfo'] == None:
Dict['PMS-AllBundleInfo'] = {}
return

####################################################################################################
Expand Down
14 changes: 5 additions & 9 deletions Contents/Code/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,9 @@ def removeEmptyFolders(path, removeRoot=True):
Log.Debug('Removing empty directory: ' + path)
os.rmdir(path)



# Reset dicts
nukeSpecialDicts()


url= req.get_argument('debugURL', 'https://api.github.com/repos/dagalufh/WebTools.bundle/releases/latest')
bundleName = Core.storage.join_path(Core.app_support_path, Core.config.bundles_dir_name, NAME + '.bundle')
Log.Info('WT install dir is: ' + bundleName)
Expand Down Expand Up @@ -174,16 +171,17 @@ def removeEmptyFolders(path, removeRoot=True):
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Upgraded ok')
except Exception, e:
Log.Critical('***************************************************************')
Log.Critical('Error when updating WebTools')
Log.Critical('The error was: ' + str(e))
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')
Log.Critical('The error was: ' + str(e))
Log.Critical('Do NOT FORGET!!!!')
Log.Critical('We NEED this log, so please upload to Plex forums')
Log.Critical('***************************************************************')
return


''' This function will return a list of bundles, where there is an update avail '''
def getUpdateList(self, req):
Log.Debug('Got a call for getUpdateList')
Expand Down Expand Up @@ -218,7 +216,6 @@ def getUpdateList(self, req):
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Fatal error happened in getUpdateList ' + str(e))


''' This function will migrate bundles that has been installed without using our UAS into our UAS '''
def migrate(self, req, silent=False):
Expand Down Expand Up @@ -259,9 +256,6 @@ def getIdentifier(pluginDir):
# Main call
Log.Debug('Migrate function called')
try:
# Init dict, if not already so
if Dict['installed'] == None:
Dict['installed'] = {}
# Let's start by getting a list of known installed bundles
knownBundles = []
for installedBundles in Dict['installed']:
Expand Down Expand Up @@ -307,6 +301,8 @@ def getIdentifier(pluginDir):
Log.Debug('Dict stamped with the following install entry: ' + git + ' - ' + str(targetGit))
# Now update the PMS-AllBundleInfo Dict as well
Dict['PMS-AllBundleInfo'][git] = targetGit
# Update installed dict as well
Dict['installed'][git] = targetGit
# If it existed as unknown as well, we need to remove that
Dict['PMS-AllBundleInfo'].pop(uasListjson[git]['identifier'], None)
Dict['installed'].pop(uasListjson[git]['identifier'], None)
Expand Down
148 changes: 74 additions & 74 deletions Contents/Code/pms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import shutil, os
import time, json
import io
from xml.etree import ElementTree


# Undate uasTypesCounters
Expand Down Expand Up @@ -45,35 +46,39 @@ def updateUASTypesCounters():
# updateAllBundleInfo
def updateAllBundleInfoFromUAS():
def updateInstallDict():
# Start by creating a fast lookup cache for all uas bundles
if Dict['installed'] == None:
Dict['installed'] = {}
if Dict['PMS-AllBundleInfo'] == None:
Dict['PMS-AllBundleInfo'] = {}


uasBundles = {}

# for bundle in Dict['PMS-AllBundleInfo']:
# uasBundles[bundle['identifier']] = bundle


#GED update install dict, so when cache is updated, it checks the unknown
'''
# Debugging stuff
print 'Ged debugging stuff'
Dict['PMS-AllBundleInfo'].pop('https://github.com/ukdtom/plex2csv.bundle', None)
Dict['installed'].clear()
Dict.Save()
#Debug end
'''


# print 'Ged1', uasBundles


# Start by creating a fast lookup cache for all uas bundles
uasBundles = {}
bundles = Dict['PMS-AllBundleInfo']
for bundle in bundles:
uasBundles[bundles[bundle]['identifier']] = bundle
# Now walk the installed ones
for installedBundle in Dict['installed']:
if not installedBundle.startswith('https://'):
print 'Ged44', installedBundle
Log.Info('Checking unknown bundle: ' + installedBundle + ' to see if it is part of UAS now')
if installedBundle in uasBundles:
# Get the installed date of the bundle formerly known as unknown :-)
installedDate = Dict['installed'][installedBundle]['date']
# Add updated stuff to the dicts
Dict['PMS-AllBundleInfo'][uasBundles[installedBundle]]['date'] = installedDate
Dict['installed'][uasBundles[installedBundle]] = Dict['PMS-AllBundleInfo'][uasBundles[installedBundle]]
# Remove old stuff from the Ditcs
Dict['PMS-AllBundleInfo'].pop(installedBundle, None)
Dict['installed'].pop(installedBundle, None)
Dict.Save()
return

try:
# Init the Dict
if Dict['PMS-AllBundleInfo'] == None:
Dict['PMS-AllBundleInfo'] = {}
Dict.Save()
# start by checking if UAS cache has been populated
jsonUAS = Core.storage.join_path(Core.app_support_path, Core.config.bundles_dir_name, NAME + '.bundle', 'http', 'uas', 'Resources', 'plugin_details.json')
if os.path.exists(jsonUAS):
Expand All @@ -87,19 +92,7 @@ def updateInstallDict():
try:
for git in gits:
# Rearrange data
key = git['repo']
if key == 'https://github.com/ukdtom/test':
# This is out test bundle.....Only add if this is running in devmode
# meaning a file named 'devmode' is present in the root of the bundle dir
fname = Core.storage.join_path(Core.app_support_path, Core.config.bundles_dir_name, 'WebTools.bundle', 'devmode')
print 'GED Look here'
if os.path.isfile(fname):
continue

#******************* WORK IN PROGRESS HERE ****************



key = git['repo']
# Check if already present, and if an install date also is there
installDate = ""
if key in Dict['PMS-AllBundleInfo']:
Expand Down Expand Up @@ -196,6 +189,30 @@ def reqprocessPost(self, req):
req.set_status(412)
req.finish("<html><body>Unknown function call</body></html>")

''' Delete from an XML file '''
def DelFromXML(self, fileName, attribute, value):
Log.Debug('Need to delete element with an attribute named "%s" with a value of "%s" from file named "%s"' %(attribute, value, fileName))
with io.open(fileName, 'r') as f:
tree = ElementTree.parse(f)
root = tree.getroot()
mySubtitles = root.findall('.//Subtitle')
for Subtitles in root.findall("Language[Subtitle]"):
for node in Subtitles.findall("Subtitle"):
myValue = node.attrib.get(attribute)

print 'Ged9', myValue

if myValue:
if '_' in myValue:
drop, myValue = myValue.split("_")
if myValue == value:

print 'Ged10', value

Subtitles.remove(node)
tree.write(fileName, encoding='utf-8', xml_declaration=True)
return

# getParts
def getParts(self, req):
Log.Debug('Got a call for getParts')
Expand Down Expand Up @@ -262,15 +279,10 @@ def getAllBundleInfo(self, req):
Log.Debug('Got a call for getAllBundleInfo')
try:
req.clear()
if Dict['PMS-AllBundleInfo'] == None:
Log.Debug('getAllBundleInfo has not been populated yet')
req.set_status(204)
req.finish('getAllBundleInfo has not been populated yet')
else:
Log.Debug('Returning: ' + str(len(Dict['PMS-AllBundleInfo'])) + ' items')
req.set_status(200)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish(json.dumps(Dict['PMS-AllBundleInfo']))
Log.Debug('Returning: ' + str(len(Dict['PMS-AllBundleInfo'])) + ' items')
req.set_status(200)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish(json.dumps(Dict['PMS-AllBundleInfo']))
except Exception, e:
Log.Debug('Fatal error happened in getAllBundleInfo: ' + str(e))
req.clear()
Expand Down Expand Up @@ -421,60 +433,48 @@ def delSub(self, req):
req.finish('Hmmm....This is invalid, and most likely due to trying to delete an embedded sub :-)')
else:
if filePath.startswith('media://'):
'''
Here we look at an agent provided subtitle, so this part of the function
has been crippled on purpose
'''
# Path to symblink
filePath = filePath.replace('media:/', os.path.join(Core.app_support_path, 'Media', 'localhost'))
# Subtitle name
agent, sub = filePath.split('_')
tmp, agent = agent.split('com.')
# Agent used
agent = 'com.' + agent
filePath2 = filePath.replace('Contents', 'Subtitle Contributions')
filePath2 = filePath.replace('Contents', os.path.join('Contents', 'Subtitle Contributions'))
filePath2, language = filePath2.split('Subtitles')
language = language[1:3]
filePath3 = os.path.join(filePath2[:-1], agent, language, sub)

''' This is removed from the code, due to the fact, that Plex will re-download right after the deletion
subtitlesXMLPath, tmp = filePath.split('Contents')
agentXMLPath = os.path.join(subtitlesXMLPath, 'Contents', 'Subtitle Contributions', agent + '.xml')
subtitlesXMLPath = os.path.join(subtitlesXMLPath, 'Contents', 'Subtitles.xml')
self.DelFromXML(agentXMLPath, 'media', sub)
self.DelFromXML(subtitlesXMLPath, 'media', sub)
agentXML = XML.ElementFromURL('"' + agentXMLPath + '"')
#Let's refresh the media
url = 'http://127.0.0.1:32400/library/metadata/' + params['param2'] + '/refresh&force=1'
refresh = HTTP.Request(url, immediate=False)
# Nuke the actual file
try:
# Delete the actual file
os.remove(filePath)
print 'Removing: ' + filePath
# Delete the symb link
os.remove(filePath3)
print 'Removing: ' + filePath3
# Refresh the subtitles in Plex
self.getSubTitles(params)
except:
return 500
'''

#TODO: Refresh is sadly not working for me, so could use some help here :-(
#Let's refresh the media
url = 'http://127.0.0.1:32400/library/metadata/' + key + '/refresh?force=1'
HTTP.Request(url, cacheTime=0, immediate=True, method="PUT")
except Exception, e:
Log.Critical('Exception while deleting an agent based sub: ' + str(e))
req.clear()
req.set_status(404)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Exception while deleting an agent based sub: ' + str(e))
retValues = {}
retValues['FilePath']=filePath3
retValues['SymbLink']=filePath

Log.Debug('Agent subtitle returning %s' %(retValues))
req.clear()
req.set_status(200)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish(json.dumps(retValues))
return req
elif filePath.startswith('file://'):
# We got a sidecar here, so killing time.....YES

filePath = filePath.replace('file://', '')
try:
# Delete the actual file
Expand All @@ -486,26 +486,26 @@ def delSub(self, req):
req.set_status(200)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish(json.dumps(retVal))
except:
except Exception, e:
# Could not find req. subtitle
Log.Debug('Fatal error happened in delSub, when deleting %s' %(filePath))
Log.Debug('Fatal error happened in delSub, when deleting %s : %s' %(filePath, str(e)))
req.clear()
req.set_status(404)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Fatal error happened in delSub, when deleting %s' %(filePath))
req.finish('Fatal error happened in delSub, when deleting %s : %s' %(filePath, str(e)))
else:
# Could not find req. subtitle
Log.Debug('Fatal error happened in delSub, subtitle not found')
req.clear()
req.set_status(404)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Could not find req. subtitle')
except:
Log.Debug('Fatal error happened in delSub')
except Exception, e:
Log.Debug('Fatal error happened in delSub: ' + str(e))
req.clear()
req.set_status(500)
req.set_header('Content-Type', 'application/json; charset=utf-8')
req.finish('Fatal error happened in delSub')
req.finish('Fatal error happened in delSub: ' + str(e))

''' TVShow '''
def TVshow(self, req):
Expand Down
30 changes: 30 additions & 0 deletions http/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
V2.2-DEV:
Internal Note:
Here we collect stuff that needs to go into the real released changelog, aka acumulated, and only since 2.1 changes here ;-)
BACKEND:
Fix:
#115 UAS: Migration fails, if plugin directory contains hidden folder
#116 UAS: Make UAS work, even if a git is dir levels too low
#117 UAS and uninstall unknown bundle
#121 UAS: Cleanup old files/folders when updating
#122 UAS: bundle migration
#138 UAS: getAllBundleInfo is reset when UASRepo is updated
New:
#129 UAS: Alllow 3.Party devs to clear their stuff
#135 WT: Tell users, if wrong install path is used
#137 WT: Add new decorator for auth
#126 UAS: Allow WebTools to autoupdate

FRONTEND:
Fix:
#131 UAS: After changin category, focus is no longer set on inputbox
#139 UAS: Unknown bundles without url won't be able to be uninstalled or re-installed.
#140 UAS: Migrate now always goes back to showing ALL available bundles
New:
#126 UAS: Allow WebTools to autoupdate
#142 LogViewer: Search for keywords, highlighting of the same. Jump to top.
#133 Subtitlemgmt: Added GUI for uploading subtitles
#112 Subtitlemgmt: Allow delete/view for agent subtitles aswell.

####

V2.2-DEV-2016-02-25:
UAS:
The return of the Uninstall-button (Issue #132)
Expand Down
Loading

0 comments on commit 2467ea7

Please sign in to comment.