[WebUI] Keep debug js in packaging and fix script lookup

Packaging:

- Decided that the debug files are useful for end-user so keep them in
  package installation. For debug script_type to be usable all debug
  file need to be avaialble so extjs debug files also included.

Script type selection:

- Fixed dev and debug request args to be properly decoded on Python 3,
  otherwise comparison would fail and allowed any case for values.

- Modified the choosing of the script type to pick debug if specified
  as previously always choosing dev type if dev version was True. A rare
  scenario but useful but now debug is used if specified otherwise use dev.

- Changed the order when looking for alternative script types to start
  with dev so that if debug is specified but missing it uses a similar
  script type as previously would fallback to normal which is likely
  undesired.
This commit is contained in:
Calum Lind 2018-10-14 21:14:48 +01:00
commit ee354eb107
2 changed files with 17 additions and 9 deletions

View file

@ -564,15 +564,15 @@ class TopLevel(resource.Resource):
def render(self, request): def render(self, request):
uri_true = ('true', 'yes', '1') uri_true = ('true', 'yes', '1')
debug_arg = request.args.get('debug', [''])[-1] in uri_true debug_arg = request.args.get('debug', [b''])[-1].decode().lower() in uri_true
dev_arg = request.args.get('dev', [''])[-1] in uri_true dev_arg = request.args.get('dev', [b''])[-1].decode().lower() in uri_true
dev_ver = 'dev' in common.get_version() dev_ver = 'dev' in common.get_version()
script_type = 'normal' script_type = 'normal'
if debug_arg: if debug_arg:
script_type = 'debug' script_type = 'debug'
# Override debug if dev arg or version. elif dev_arg or dev_ver:
if dev_arg or dev_ver: # Also use dev files if development version.
script_type = 'dev' script_type = 'dev'
if not self.js.has_script_type_files(script_type): if not self.js.has_script_type_files(script_type):
@ -581,9 +581,10 @@ class TopLevel(resource.Resource):
'Failed to enable WebUI "%s" mode, script files are missing!', 'Failed to enable WebUI "%s" mode, script files are missing!',
script_type, script_type,
) )
# Fallback to checking other types in order and selecting first with files available. # Fallback to checking other types in order and selecting first with
# files available. Ordered to start with dev files lookup.
for alt_script_type in [ for alt_script_type in [
x for x in ['normal', 'debug', 'dev'] if x != script_type x for x in ['dev', 'debug', 'normal'] if x != script_type
]: ]:
if self.js.has_script_type_files(alt_script_type): if self.js.has_script_type_files(alt_script_type):
script_type = alt_script_type script_type = alt_script_type

View file

@ -162,6 +162,8 @@ class CleanWebUI(cmd.Command):
def run(self): def run(self):
js_basedir = os.path.join(os.path.dirname(__file__), BuildWebUI.JS_DIR) js_basedir = os.path.join(os.path.dirname(__file__), BuildWebUI.JS_DIR)
# Remove files generated by minify script.
for js_src_dir in BuildWebUI.JS_SRC_DIRS: for js_src_dir in BuildWebUI.JS_SRC_DIRS:
for file_type in ('.js', '-debug.js'): for file_type in ('.js', '-debug.js'):
js_file = os.path.join(js_basedir, js_src_dir + file_type) js_file = os.path.join(js_basedir, js_src_dir + file_type)
@ -171,6 +173,14 @@ class CleanWebUI(cmd.Command):
except OSError: except OSError:
pass pass
# Remove generated gettext.js
js_file = os.path.join(js_basedir, 'gettext.js')
print('Deleting {}'.format(js_file))
try:
os.remove(js_file)
except OSError:
pass
class BuildTranslations(cmd.Command): class BuildTranslations(cmd.Command):
description = 'Compile .po files into .mo files & create .desktop file' description = 'Compile .po files into .mo files & create .desktop file'
@ -532,9 +542,6 @@ _package_data['deluge.ui.web'] = [
] ]
_package_data['deluge.ui.gtkui'] = ['glade/*.ui'] _package_data['deluge.ui.gtkui'] = ['glade/*.ui']
if 'dev' not in _version:
_exclude_package_data['deluge.ui.web'] = ['*-debug.js', '*-debug.css']
docs_require = ['sphinx', 'recommonmark', 'sphinx-rtd-theme'] docs_require = ['sphinx', 'recommonmark', 'sphinx-rtd-theme']
tests_require = [ tests_require = [
'coverage', 'coverage',