Skip to content

Commit

Permalink
#1341: minify javascript and css on the fly during install (can be di…
Browse files Browse the repository at this point in the history
…sabled on the command line)

git-svn-id: https://xpra.org/svn/Xpra/trunk@14199 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Oct 19, 2016
1 parent 48678bc commit 96de3fc
Showing 1 changed file with 54 additions and 12 deletions.
66 changes: 54 additions & 12 deletions src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def is_msvc():
gtk3_ENABLED = DEFAULT and client_ENABLED and PYTHON3
opengl_ENABLED = DEFAULT and client_ENABLED
html5_ENABLED = DEFAULT
minify_ENABLED = html5_ENABLED
pam_ENABLED = DEFAULT and (server_ENABLED or proxy_ENABLED) and os.name=="posix" and not OSX and (os.path.exists("/usr/include/pam/pam_misc.h") or os.path.exists("/usr/include/security/pam_misc.h"))

vsock_ENABLED = sys.platform.startswith("linux") and os.path.exists("/usr/include/linux/vm_sockets.h")
Expand Down Expand Up @@ -222,7 +223,9 @@ def is_msvc():
"bencode", "cython_bencode", "vsock", "mdns",
"clipboard",
"server", "client", "dbus", "x11", "gtk_x11",
"gtk2", "gtk3", "html5", "pam",
"gtk2", "gtk3",
"html5", "minify",
"pam",
"sound", "opengl", "printing",
"rebuild",
"annotate", "warn", "strict",
Expand Down Expand Up @@ -312,6 +315,13 @@ def is_msvc():
if memoryview_ENABLED and sys.version<"2.7":
print("Error: memoryview support requires Python version 2.7 or greater")
exit(1)
if minify_ENABLED:
try:
import yuicompressor
assert yuicompressor
except ImportError as e:
print("Warning: yuicompressor module not found, cannot minify")
minify_ENABLED = False
if not enc_x264_ENABLED and not vpx_ENABLED:
print("Warning: no x264 and no vpx support!")
print(" you should enable at least one of these two video encodings")
Expand Down Expand Up @@ -991,6 +1001,47 @@ def glob_recurse(srcdir):
m.setdefault(dirname, []).append(filename)
return m


def install_html5(install_dir):
if OSX or WIN32:
#win32:
#OSX: Xpra.app/Contents/Resources/www/
html5_dir = "www"
else:
html5_dir = "share/xpra/www"
for k,files in glob_recurse("html5").items():
if (k!=""):
k = os.sep+k
for f in files:
src = f
parts = f.split(os.path.sep)
if parts[0]=="html5":
f = os.path.join(*parts[1:])
dst = os.path.join(install_dir, html5_dir, f)
ddir = os.path.split(dst)[0]
if ddir and not os.path.exists(ddir):
os.makedirs(ddir, 0o755)
ftype = os.path.splitext(f)[1].lstrip(".")
if minify_ENABLED and ftype in ("js", "css"):
jar = yuicompressor.get_jar_filename()
minify_cmd = ["java", "-jar", jar,
src,
"--nomunge",
"--line-break", "400",
"--type", ftype,
"-o", dst]
r = get_status_output(minify_cmd)[0]
if r!=0:
print("Error: minify for '%s' returned %i" % (f, r))
else:
print("minified %s" % (f, ))
else:
r = -1
if r!=0:
shutil.copyfile(src, dst)
os.chmod(dst, 0o644)


#*******************************************************************************
if WIN32:
add_packages("xpra.platform.win32")
Expand Down Expand Up @@ -1484,6 +1535,7 @@ def add_gui_exe(*args):
print("calling build_xpra_conf in-place")
#building etc files in-place:
build_xpra_conf(".")
install_html5(".")
add_data_files('etc/xpra', glob.glob("etc/xpra/*conf"))
add_data_files('etc/xpra', glob.glob("etc/xpra/nvenc*.keys"))
add_data_files('etc/xpra/conf.d', glob.glob("etc/xpra/conf.d/*conf"))
Expand Down Expand Up @@ -1720,8 +1772,6 @@ def add_keywords(path_dirs=[], inc_dirs=[], lib_dirs=[], libs=[], noref=True, no
if not isinstance(e, WindowsError) or (not "already exists" in str(e)): #@UndefinedVariable
raise

html5_dir = 'www'

#END OF win32
#*******************************************************************************
else:
Expand All @@ -1734,11 +1784,6 @@ def add_keywords(path_dirs=[], inc_dirs=[], lib_dirs=[], libs=[], noref=True, no
add_data_files("share/mime/packages", ["xdg/application-x-xpraconfig.xml"])
add_data_files("share/icons", ["xdg/xpra.png"])
add_data_files("share/appdata", ["xdg/xpra.appdata.xml"])
if OSX:
#Xpra.app/Contents/Resources/www/
html5_dir = "www"
else:
html5_dir = "share/xpra/www"

#here, we override build and install so we can
#generate our /etc/xpra/xpra.conf
Expand All @@ -1758,6 +1803,7 @@ def run(self):
class install_data_override(install_data):
def run(self):
print("install_data_override: install_dir=%s" % self.install_dir)
install_html5(self.install_dir)
install_data.run(self)

etc_prefix = self.install_dir
Expand Down Expand Up @@ -1893,10 +1939,6 @@ def osx_pkgconfig(*pkgs_options, **ekw):


if html5_ENABLED:
for k,v in glob_recurse("html5").items():
if (k!=""):
k = os.sep+k
add_data_files(html5_dir+k, v)
if WIN32 or OSX:
external_includes.append("websockify")
external_includes.append("numpy")
Expand Down

0 comments on commit 96de3fc

Please sign in to comment.