def dirwalk(dirname): base = join(_env.PREFIX, dirname) merge = [] file = [] suffix = '.%s' % dirname for dirpath, dirnames, filenames in walk(base, followlinks=True): for i in filenames: path = abspath(join(dirpath, i)) if i == 'merge.conf': merge.append((path, merge_conf(path, base))) if i.endswith(suffix): file.append(path) elif dirname == 'css': filesuffix = splitext(path)[-1][1:] if filesuffix not in ('py', 'pyc', 'orig', 'swp', 'conf', 'txt', 'rst', 'html'): url = path[len(_env.PREFIX):] with open(path, 'rb') as infile: filemd5 = urlsafe_b64encode( md5(infile.read()).digest()).rstrip('=') CSS_IMG2URL[url] = filemd5 cache_path = join(BULID, filemd5) if not exists(cache_path) and not DEBUG: print 'upload %s > //%s/%s'% (url, _QINIU.HOST, filemd5) r = QINIU.upload( filemd5, path) _hash = r.get('hash', None) if _hash: with open(cache_path, 'w') as c: c.write(_hash) else: print r return file, merge
def dirwalk(dirname): base = join(_env.PREFIX, dirname) merge = [] file = [] suffix = '.%s' % dirname for dirpath, dirnames, filenames in walk(base, followlinks=True): for i in filenames: path = abspath(join(dirpath, i)) if i == 'merge.conf': merge.append((path, merge_conf(path, base))) if i.endswith(suffix): file.append(path) elif dirname == 'css': filesuffix = splitext(path)[-1][1:] if filesuffix not in ('py', 'pyc', 'orig', 'swp', 'conf', 'txt', 'rst', 'html'): url = path[len(_env.PREFIX):] with open(path, 'rb') as infile: filemd5 = urlsafe_b64encode( md5(infile.read()).digest()).rstrip('=') CSS_IMG2URL[url] = filemd5 cache_path = join(BULID, filemd5) if not exists(cache_path) and not DEBUG: print 'upload %s > //%s/%s' % (url, _QINIU.HOST, filemd5) r = QINIU.upload(filemd5, path) _hash = r.get('hash', None) if _hash: with open(cache_path, 'w') as c: c.write(_hash) else: print r return file, merge
def envoy_run(hash, cmd, path, tmp): if DEBUG: return if exists(path): return t = cmd % (path, tmp) print t envoy.run(t) suffix = path.rsplit('.', 1)[-1] if suffix == 'css': content_type = 'text/css' elif suffix == 'js': content_type = 'application/javascript' path = '%s/%s.%s' % (BULID, hash, suffix) if suffix == 'css': with open(path) as css: txt = css.read() remove(path) txt = css_remove_background_url(tmp, txt) with open(path, 'w') as css: css.write(txt) QINIU.upload(hash, path, content_type)