[Setup] Refactor BuildWebUI class
This commit is contained in:
parent
14a5156e15
commit
9cefbc6e5d
67
setup.py
67
setup.py
|
@ -100,42 +100,60 @@ class CleanDocs(cmd.Command):
|
||||||
|
|
||||||
class BuildWebUI(cmd.Command):
|
class BuildWebUI(cmd.Command):
|
||||||
description = 'Minify WebUI files'
|
description = 'Minify WebUI files'
|
||||||
|
user_options = []
|
||||||
|
|
||||||
user_options = [
|
JS_DIR = os.path.join('deluge', 'ui', 'web', 'js')
|
||||||
('build-lib', None, 'build folder containing javascript files'),
|
JS_SRC_DIRS = ('deluge-all', os.path.join('extjs', 'ext-extensions'))
|
||||||
('develop', 'D', 'build javascript files in develop mode')
|
|
||||||
]
|
|
||||||
boolean_options = ['develop']
|
|
||||||
|
|
||||||
def initialize_options(self):
|
def initialize_options(self):
|
||||||
self.build_lib = None
|
pass
|
||||||
self.develop = False
|
|
||||||
|
|
||||||
def finalize_options(self):
|
def finalize_options(self):
|
||||||
self.set_undefined_options('build', ('build_lib', 'build_lib'))
|
pass
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.develop:
|
js_basedir = os.path.join(os.path.dirname(__file__), self.JS_DIR)
|
||||||
js_basedir = os.path.join(os.path.dirname(__file__), 'deluge', 'ui', 'web', 'js')
|
|
||||||
else:
|
|
||||||
js_basedir = os.path.join(self.build_lib, 'deluge', 'ui', 'web', 'js')
|
|
||||||
|
|
||||||
js_source_dirs = [os.path.join(js_basedir, 'deluge-all'),
|
|
||||||
os.path.join(js_basedir, 'extjs', 'ext-extensions')]
|
|
||||||
|
|
||||||
import_error = ''
|
|
||||||
try:
|
try:
|
||||||
from minify_web_js import minify_js_dir
|
from minify_web_js import minify_js_dir
|
||||||
|
import_error = ''
|
||||||
except ImportError as err:
|
except ImportError as err:
|
||||||
import_error = err
|
import_error = err
|
||||||
|
|
||||||
for source_dir in js_source_dirs:
|
for js_src_dir in self.JS_SRC_DIRS:
|
||||||
# If unable to import minify script and there is no existing minified file, raise error.
|
source_dir = os.path.join(js_basedir, js_src_dir)
|
||||||
if import_error:
|
try:
|
||||||
js_file = os.path.join(os.path.dirname(source_dir), os.path.basename(source_dir)) + '.js'
|
minify_js_dir(source_dir)
|
||||||
if not os.path.exists(js_file):
|
except NameError:
|
||||||
raise ImportError(import_error)
|
js_file = source_dir + '.js'
|
||||||
minify_js_dir(source_dir)
|
if os.path.is_file(js_file):
|
||||||
|
print('Unable to minify but found existing minified: {}'.format(js_file))
|
||||||
|
else:
|
||||||
|
# Unable to minify and no existing minified file found so exiting.
|
||||||
|
print('Import error: %s' % import_error)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
class CleanWebUI(cmd.Command):
|
||||||
|
description = 'Clean the documentation build and rst files'
|
||||||
|
user_options = []
|
||||||
|
|
||||||
|
def initialize_options(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def finalize_options(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
js_basedir = os.path.join(os.path.dirname(__file__), BuildWebUI.JS_DIR)
|
||||||
|
for js_src_dir in BuildWebUI.JS_SRC_DIRS:
|
||||||
|
for file_type in ('.js', '-debug.js'):
|
||||||
|
js_file = os.path.join(js_basedir, js_src_dir + file_type)
|
||||||
|
print('Deleting {}'.format(js_file))
|
||||||
|
try:
|
||||||
|
os.remove(js_file)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class BuildTranslations(cmd.Command):
|
class BuildTranslations(cmd.Command):
|
||||||
|
@ -347,7 +365,7 @@ class Clean(_clean):
|
||||||
sub_commands = _clean.sub_commands + [
|
sub_commands = _clean.sub_commands + [
|
||||||
('clean_plugins', None),
|
('clean_plugins', None),
|
||||||
('clean_trans', None),
|
('clean_trans', None),
|
||||||
]
|
('clean_webui', None)]
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# Remove deluge egg-info.
|
# Remove deluge egg-info.
|
||||||
|
@ -374,6 +392,7 @@ cmdclass = {
|
||||||
'clean_plugins': CleanPlugins,
|
'clean_plugins': CleanPlugins,
|
||||||
'clean_trans': CleanTranslations,
|
'clean_trans': CleanTranslations,
|
||||||
'clean_docs': CleanDocs,
|
'clean_docs': CleanDocs,
|
||||||
|
'clean_webui': CleanWebUI,
|
||||||
'clean': Clean,
|
'clean': Clean,
|
||||||
'egg_info_plugins': EggInfoPlugins,
|
'egg_info_plugins': EggInfoPlugins,
|
||||||
'test': PyTest,
|
'test': PyTest,
|
||||||
|
|
Loading…
Reference in New Issue