Exemple #1
0
def compress_web(out_file, input_fnames, level=DEFAULT_LEVEL, verbose=False):
    """
    Compresses files using google's closure web service. It has caveats:
    no big wads of JS, and it has a quota.
    """

    out_file = out_file or OUT_FILE

    p('Compressing %s ...' % out_file, verbose)
    s = StringIO.StringIO()

    # This is a very ghetto way to not compress the entire thing at once.
    # "What if I have big files!?" you say. Well, make them smaller.
    parts = 4
    for i in range(0, len(input_fnames)+1, parts):
        if input_fnames[i:i+parts]:
            compressed = compress(common.concat(input_fnames[i:i+parts]), COMPILATION_LEVELS[level])
            s.write(compressed)

    s = s.getvalue()
    p('Compressed to %d' % (len(s)), verbose)

    out = open(out_file, 'w')
    out.write(s)
    out.close()
    return 0
Exemple #2
0
def clean(src, verbose=False):
    p('Cleaning...', verbose)

    def clean_file(pkg, module, out_file, in_files, base, type, **k):
        path = os.path.join(base, out_file)
        if os.path.exists(path):
            p('Removing %s::%s' % (module, out_file), verbose)
            os.remove(path)

    walk_structure(src, clean_file)
Exemple #3
0
    def compress_module(pkg, module, out_file, in_files, base, type, **k):

        if type in COMPRESS_FNS and (not modules or module in modules):
            found_mods.add(module)
            p('Building %s::%s' % (module, out_file), verbose)
            out, inp = _append_path(base, out_file, in_files)
            dir = os.path.dirname(out)
            if not os.path.exists(dir):
                os.makedirs(dir)
            return COMPRESS_FNS[type](*list(_append_path(base, out_file, in_files)) + [level], pretty=pretty)
        return 0
def compress_local(out_file, input_fnames, type=TYPE_JS, verbose=False, level=None):
    """
    """
    
    out_file = out_file or ('compressed.'+TYPE_JS)
    p('Compressing %s ...' % out_file, verbose)
    
    s = common.concat(input_fnames)
    s = compress(s, type)
    out = open(out_file, 'w')
    out.write(s)
    out.close()
Exemple #5
0
def compress_local(out_file, input_fnames, level=DEFAULT_LEVEL, verbose=False, pretty=False):
    """
    Compresses locally using closure.jar. You need to download it and create an
    environment variable called CLOSURE_PATH which points to the jar.
    """

    out_file = out_file or OUT_FILE

    command = common.java_command(CLOSURE_PATH)

    #java -jar closure.jar --js=in1.js --js=in2.js ... --js_output_file=out.js
    p('Compressing %s at level %s ...' % (out_file, level), verbose)

    fnames = ['--js=%s' % fn for fn in input_fnames]
    outfile = '--js_output_file=%s' % out_file
    complevel = ['--compilation_level=%s' % (COMPILATION_LEVELS[level])]
    if pretty:
        formatting = ['--formatting=PRETTY_PRINT']
    else:
        formatting = []
    #source_map = ['--create_source_map=%s.map' % out_file, '--source_map_format=V3']
    return subprocess.call(command + fnames + [outfile] + complevel + formatting)
Exemple #6
0
def compress(src, modules=None, verbose=False, level=0, pretty=False):
    p('Compressing modules %s' % (modules or '[all]'), verbose)

    found_mods = set()
    def compress_module(pkg, module, out_file, in_files, base, type, **k):

        if type in COMPRESS_FNS and (not modules or module in modules):
            found_mods.add(module)
            p('Building %s::%s' % (module, out_file), verbose)
            out, inp = _append_path(base, out_file, in_files)
            dir = os.path.dirname(out)
            if not os.path.exists(dir):
                os.makedirs(dir)
            return COMPRESS_FNS[type](*list(_append_path(base, out_file, in_files)) + [level], pretty=pretty)
        return 0

    ret = walk_structure(src, compress_module)

    p('Compressed modules: %s' % (list(found_mods) or 'None :('), verbose)
    if not found_mods:
        print 'Nothing found to compress'

    return ret
Exemple #7
0
def mcs():
    'Returns active metacontacts.'
    from pprint import pprint
    pprint( p().blist.meta_contacts )
Exemple #8
0
 def clean_file(pkg, module, out_file, in_files, base, type, **k):
     path = os.path.join(base, out_file)
     if os.path.exists(path):
         p('Removing %s::%s' % (module, out_file), verbose)
         os.remove(path)
Exemple #9
0
def mcs():
    'Returns active metacontacts.'
    from pprint import pprint
    pprint(p().blist.meta_contacts)