def link(path, link_path, force = False): u''' 将发布库与源库进行映射 如果库设置了url,则同时使用.package文件进行连接,需要工作区支持,如果没有url,则只进行本地连接。''' publish_path, root_path = StaticPackage.get_roots(path) if not publish_path and not root_path and link_path: publish_path, root_path = StaticPackage.get_roots(link_path) path, link_path = link_path, path if not publish_path: publish_path = os.path.realpath(link_path) else: root_path = os.path.realpath(link_path) if not root_path: ui.error('package not found') package = StaticPackage(root_path, publish_path = publish_path) if not os.path.exists(publish_path): if force: os.makedirs(publish_path) else: ui.msg(u'%s path not exists, run opm link path -f to create it.' % publish_path) return 1 package.link() ui.msg(u'linked publish %s to %s' % (publish_path, root_path))
def status(publish_path): u''' 检查发布库的编译状态 ''' publish_path, root_path = StaticPackage.get_roots(publish_path) if not publish_path: ui.error(u'不是发布库') return 1 package = StaticPackage(root_path, publish_path) files = package.get_publish_files() for filename in files: filetype = os.path.splitext(filename)[1] source, mode = package.parse(filename) try: rfiles = package.get_relation_files(source, all = True) except PackageNotFoundException, e: ui.error(u'%s package not found' % e.url) else: modified, not_exists = package.listener.check(filename, rfiles) if len(modified) or len(not_exists): for modified_file in modified: ui.msg('M ' + modified_file) for not_exists_file in not_exists: ui.msg('! ' + not_exists_file)
def publish(path, publish_path = None, force = False, rebuild = False): u'''将整个发布库进行编译''' do_link = False # 指定了第二个参数,则path一定是一个源库,第二个参数则是发布库,并自动进行link if publish_path: root_path = StaticPackage.get_root(path) path = publish_path # 发布整个库 do_link = True # 没有指定第二个参数,则path一定是一个发布库 else: publish_path, root_path = StaticPackage.get_roots(path) if not publish_path: ui.msg(u'No publish path.') else: package = StaticPackage(root_path, publish_path = publish_path) if not package.publish_path: ui.msg(u'No publish path.') else: ui.msg(u'publish to %s' % (path,) + (' with rebuild' if rebuild else '')) if rebuild: # 遍历磁盘目录,慢 all_files = package.get_publish_files() else: # 只搜索合并索引,快 all_files = package.listener.get_files() for filename in all_files: compile(filename, package = package, force = force, no_build_files = True) buildfiles(package = package) if do_link: package.link()
def compile(filename, package = None, force = False, no_build_files = False): u'编译一个css/js文件' filename = os.path.realpath(filename) if not package: publish_path, root_path = StaticPackage.get_roots(filename) if not root_path: ui.error(u'没有找到源文件') return 1 else: package = StaticPackage(root_path, publish_path) try: modified, not_exists = package.compile(filename, force = force) except IOError, e: ui.error('%s file not found' % e.filename) return 1
def listen(environ, start_response): ''' 监听请求 ''' if environ['DOCUMENT_URI'].endswith('/net.test'): return print_request(environ, start_response) DEBUG = debug filename = os.path.realpath(environ['REQUEST_FILENAME']) url = environ['DOCUMENT_URI'] force = False # 是否强制重新编译 # 没有 referer 时强制重新编译 if not 'HTTP_REFERER' in environ.keys(): force = True try: publish_path, root_path = StaticPackage.get_roots(filename, workspace = workspace) except PackageNotFoundException, e: ui.error(u'%s package not found' % e.url)