File: closure.py

package info (click to toggle)
openlayers 2.11%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 60,144 kB
  • ctags: 10,906
  • sloc: xml: 7,435; python: 778; sh: 68; makefile: 30
file content (22 lines) | stat: -rw-r--r-- 568 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import sys
import os
import tempfile

path = "../tools/closure-compiler.jar"
if not os.path.exists(path):
    raise Exception("No closure-compiler.jar at %s; read README.txt!" % path)

def minimize(code):
    ntf = tempfile.NamedTemporaryFile(delete=False)
    ntf.write(code)
    ntf.flush()

    ntf2 = tempfile.NamedTemporaryFile(delete=False)
    ntf.close()
    ntf2.close()

    os.system("java -jar %s --js %s --js_output_file %s" % (path, ntf.name, ntf2.name))
    data = open(ntf2.name).read()
    os.unlink(ntf.name)
    os.unlink(ntf2.name)
    return data