Example #1
0
 def compress(self, jsfiles):
     ts = str(max([os.path.getmtime(fname) for fname in jsfiles]))
     key = '-'.join(jsfiles)
     cpfile = '%s.js' % hashlib.md5(key + ts).hexdigest()
     cppath = self.page.site.getStatic('site').path('_static', '_jslib',
                                                    cpfile)
     jspath = self.page.site.getStatic('site').url('_static', '_jslib',
                                                   cpfile)
     rebuild = True
     if os.path.isfile(cppath):
         cpf = file(cppath, 'r')
         tsf = cpf.readline()
         cpf.close()
         if ts in tsf:
             rebuild = False
     if rebuild:
         path = self.page.site.getStatic('site').path('_static', '_jslib')
         if not os.path.exists(path):
             os.makedirs(path)
         cpf = file(cppath, 'w')
         cpf.write('// %s\n' % ts)
         for fname in jsfiles:
             f = file(fname)
             js = f.read()
             f.close()
             cpf.write(jsmin(js))
             cpf.write('\n\n\n\n')
         cpf.close()
     return jspath
Example #2
0
 def compress(self, jsfiles):
     ts = str(max([os.path.getmtime(fname) for fname in jsfiles]))
     key = '-'.join(jsfiles)
     cpfile = '%s.js' % hashlib.md5(key + ts).hexdigest()
     cppath = self.page.site.getStatic('site').path('_static', '_jslib', cpfile)
     jspath = self.page.site.getStatic('site').url('_static', '_jslib', cpfile)
     rebuild = True
     if os.path.isfile(cppath):
         cpf = file(cppath, 'r')
         tsf = cpf.readline()
         cpf.close()
         if ts in tsf:
             rebuild = False
     if rebuild:
         path = self.page.site.getStatic('site').path('_static', '_jslib')
         if not os.path.exists(path):
             os.makedirs(path)
         cpf = file(cppath, 'w')
         cpf.write('// %s\n' % ts)
         for fname in jsfiles:
             f = file(fname)
             js = f.read()
             f.close()
             cpf.write(jsmin(js))
             cpf.write('\n\n\n\n')
         cpf.close()
     return jspath
Example #3
0
def compress_js(jsfiles, site=None):
    ts = str(max([os.path.getmtime(fname) for fname in jsfiles]))
    key = '-'.join(jsfiles)
    cpfile = '%s.js' % hashlib.md5(key + ts).hexdigest()
    jspath = site.getStatic('site').path('_static', '_jslib', cpfile)
    jsurl = site.getStatic('site').url('_static', '_jslib', cpfile)
    rebuild = True
    if os.path.isfile(jspath):
        #cpf = file(cppath, 'r')
        #tsf = cpf.readline()
        #cpf.close()
        #if ts in tsf:
        #    rebuild = False
        rebuild = False
    if rebuild:
        path = site.getStatic('site').path('_static', '_jslib')
        if not os.path.exists(path):
            os.makedirs(path)
        outfile_handle, outfile_path = tempfile.mkstemp(prefix='gnrcompress',
                                                        suffix='.js')
        with os.fdopen(outfile_handle, "w") as cpf:
            cpf.write('// %s\n' % ts)
            for fname in jsfiles:
                f = file(fname)
                js = f.read()
                f.close()
                cpf.write(jsmin(js))
                cpf.write('\n\n\n\n')
            cpf.flush()
            os.fsync(cpf.fileno())
        shutil.move(outfile_path, jspath)

    return jsurl
Example #4
0
def compress_js(jsfiles, site=None):
    ts = str(max([os.path.getmtime(fname) for fname in jsfiles]))
    key = '-'.join(jsfiles)
    cpfile = '%s.js' % hashlib.md5(key + ts).hexdigest()
    jspath = site.getStatic('site').path('_static', '_jslib', cpfile)
    jsurl = site.getStatic('site').url('_static', '_jslib', cpfile)
    rebuild = True
    if os.path.isfile(jspath):
        #cpf = file(cppath, 'r')
        #tsf = cpf.readline()
        #cpf.close()
        #if ts in tsf:
        #    rebuild = False
        rebuild = False
    if rebuild:
        path = site.getStatic('site').path('_static', '_jslib')
        if not os.path.exists(path):
            os.makedirs(path)
        outfile_handle, outfile_path = tempfile.mkstemp(prefix='gnrcompress',suffix='.js')
        with os.fdopen(outfile_handle, "w") as cpf:
            cpf.write('// %s\n' % ts)
            for fname in jsfiles:
                f = file(fname)
                js = f.read()
                f.close()
                cpf.write(jsmin(js))
                cpf.write('\n\n\n\n')
            cpf.flush()
            os.fsync(cpf.fileno())
        shutil.move(outfile_path, jspath)
        
        
        
    return jsurl
Example #5
0
 def jsmin(self, js):
     return jsmin(js)
Example #6
0
 def jsmin(self, js):
     return jsmin(js)