Skip to content

Commit

Permalink
Merge pull request #208 from dagalufh/2.3
Browse files Browse the repository at this point in the history
2.3
  • Loading branch information
ukdtom committed Oct 23, 2016
2 parents b227604 + 08acbe8 commit 2686b7b
Show file tree
Hide file tree
Showing 32 changed files with 1,638 additions and 436 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ Icon
*.pyc
debug

#****************
# Ignore Linux copy
#****************
*copy*.*


Binary file modified Contents/Code/Docs/webtools-README_DEVS.odt
Binary file not shown.
41 changes: 16 additions & 25 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,28 @@
######################################################################################################################

#********* Constants used **********
PREFIX = '/applications/webtools'

NAME = 'WebTools'
ICON = 'WebTools.png'
VERSION = '2.2'
AUTHTOKEN = ''
SECRETKEY = ''
DEBUGMODE = False


#********** Imports needed *********
import os, io, time
from subprocess import call
import sys, locale
from webSrv import startWeb, stopWeb
from random import randint
from random import randint #Used for Cookie generation
import uuid #Used for secrectKey


import datetime
import time
from consts import DEBUGMODE, VERSION, PREFIX, NAME, ICON

#********** Initialize *********
def Start():
global SECRETKEY
global VERSION
global DEBUGMODE
# Switch to debug mode if needed
debugFile = Core.storage.join_path(Core.app_support_path, Core.config.bundles_dir_name, NAME + '.bundle', 'debug')
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))

if DEBUGMODE:
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")))
Log.Debug('Locale is: ' + str(locale.getdefaultlocale()))
# TODO: Nasty workaround for issue 189
if (Platform.OS == 'Windows' and locale.getpreferredencoding() == 'cp1251'):
sys.setdefaultencoding("cp1251")
Log.Debug("Default set to cp1251")
HTTP.CacheTime = 0
DirectoryObject.thumb = R(ICON)
ObjectContainer.title1 = NAME + ' V' + VERSION
Expand All @@ -52,7 +42,7 @@ def Start():

# Get the secret key used to access the PMS framework ********** FUTURE USE ***************
SECRETKEY = genSecretKeyAsStr()
startWeb(SECRETKEY, VERSION, DEBUGMODE)
startWeb(SECRETKEY)

####################################################################################################
# Generate secret key
Expand All @@ -68,7 +58,8 @@ def genSecretKeyAsStr():
''' This will generate the default settings in the Dict if missing '''
@route(PREFIX + '/makeSettings')
def makeSettings():
Dict['SharedSecret'] = VERSION + '.' + str(randint(0,9999))
# Used for Cookie generation
Dict['SharedSecret'] = VERSION + '.' + str(randint(0,9999))
# Set default value for http part, if run for the first time
if Dict['options_hide_integrated'] == None:
Dict['options_hide_integrated'] = 'false'
Expand Down
75 changes: 75 additions & 0 deletions Contents/Code/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
######################################################################################################################
# Plex2CSV module unit
#
# Author: dane22, a Plex Community member
#
# This module is for constants used by WebTools and it's modules, as well as to control developer mode
#
# For info about the debug file, see the docs
######################################################################################################################

import io, os, json

DEBUGMODE = False # default for debug mode
WT_AUTH = True # validate password
VERSION = 'ERROR' # version of WebTools
UAS_URL = 'https://github.com/ukdtom/UAS2Res' # USA2 Repo branch
UAS_BRANCH = 'master' # UAS2 branch to check
PREFIX = '/applications/webtools'
NAME = 'WebTools'
ICON = 'WebTools.png'
JSONTIMESTAMP = 0 # timestamp for json export


class consts(object):
init_already = False # Make sure part of init only run once
# Init of the class
def __init__(self):
global DEBUGMODE
global WT_AUTH
global UAS_URL
global UAS_BRANCH
global VERSION
global JSONTIMESTAMP

# Grap version number from the version file
versionFile = Core.storage.join_path(Core.app_support_path, Core.config.bundles_dir_name, NAME + '.bundle', 'VERSION')
with io.open(versionFile, "rb") as version_file:
VERSION = version_file.read().replace('\n','')

# Switch to debug mode if needed
debugFile = Core.storage.join_path(Core.app_support_path, Core.config.bundles_dir_name, NAME + '.bundle', 'debug')
# Do we have a debug file ?
if os.path.isfile(debugFile):
DEBUGMODE = True
VERSION = VERSION + ' ****** WARNING Debug mode on *********'
try:
# Read it for params
json_file = io.open(debugFile, "rb")
debug = json_file.read()
json_file.close()
debugParams = JSON.ObjectFromString(str(debug))
Log.Debug('Override debug params are %s' %str(debugParams))
if 'UAS_Repo' in debugParams:
UAS_URL = debugParams['UAS_Repo']
if 'UAS_RepoBranch' in debugParams:
UAS_BRANCH = debugParams['UAS_RepoBranch']
if 'WT_AUTH' in debugParams:
WT_AUTH = debugParams['WT_AUTH']
if 'JSONTIMESTAMP' in debugParams:
JSONTIMESTAMP = debugParams['JSONTIMESTAMP']
except:
pass
Log.Debug('******** Using the following debug params ***********')
Log.Debug('DEBUGMODE: ' + str(DEBUGMODE))
Log.Debug('UAS_Repo: ' + UAS_URL)
Log.Debug('UAS_RepoBranch: ' + UAS_BRANCH)
Log.Debug('Authenticate: ' + str(WT_AUTH))
Log.Debug('JSON timestamp: ' + str(JSONTIMESTAMP))
Log.Debug('*****************************************************')
else:
DEBUGMODE = False

consts = consts()


Loading

0 comments on commit 2686b7b

Please sign in to comment.