예제 #1
0
def workspace(root_path):
    u''' 源库所在工作区 '''
    if StaticPackage.get_root(root_path):
        ui.msg(Workspace.get_workspace(root_path))
    else:
        ui.msg(u'不是一个源库')
        return 1
예제 #2
0
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)
예제 #3
0
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))
예제 #4
0
def main():
    commands = [get, init, compile, publish, link, load, serve, packages, workspace, root, source, status, libs, incs]
    if len(sys.argv) < 2:
        ui.msg(u'使用 opm help 得到用法')
    else:
        command = sys.argv[1]
        if command == 'help':
            subcommand = None
            if len(sys.argv) > 2:
                subcommand = globals()[sys.argv[2]]
            utils.commandline.help(commands, subcommand)
        else:
            all = globals()
            if command in all:
                utils.commandline.call(commands, globals()[command])
            else:
                utils.commandline.help(commands)
예제 #5
0
def packages(workspace_path, show_url = False):
    u''' 本工作区中所有源库 '''

    if os.path.isfile(workspace_path):
        workspace_path = os.path.dirname(workspace_path)

    # 有可能不是workspace跟路径,而是某个子路径
    workspace_path = Workspace.get_workspace(workspace_path)
    if not workspace_path:
        ui.error(u'没有工作区')
        return 1
    else:
        workspace = Workspace(workspace_path)
        if show_url:
            for url in workspace.url_packages.keys():
                ui.msg(url)
        else:
            for local_path in workspace.local_packages.keys():
                ui.msg(os.path.realpath(os.path.join(workspace.root, local_path)))
예제 #6
0
def incs(filename, all = False, reverse = False):
    u''' 某文件所有依赖的文件 '''

    filename = os.path.realpath(filename)
    root_path = StaticPackage.get_root(filename)
    package = StaticPackage(root_path)

    filetype = os.path.splitext(filename)[1]

    if reverse:
        if filetype == '.css':
            ui.error(u'Not support yet, sorry.')
            return 1
        else:
            files = package.get_included(filename, all = all)
    else:
        files = package.get_relation_files(filename, all = all)

    for file in files:
        ui.msg(file)
예제 #7
0
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()
예제 #8
0
def load(workspace):
    u''' 加载本地工作区 '''

    if workspace.__class__ == str:
        workspace_path = Workspace.get_workspace(workspace)
        if not workspace_path:
            workspace_path = workspace

        try:
            workspace = Workspace(workspace_path)
        except ConfigError as e:
            ui.error(u'config error %s' % e.path)
            return 1

    old_count = len(workspace.local_packages)
    workspace.load()
    added_count = len(workspace.local_packages) - old_count

    if len(workspace.useless_packages):
        for package in workspace.useless_packages:
            ui.msg(u'删除无用package %s' % package)

    ui.msg(u'已加入 %s 个源库' % added_count)
예제 #9
0
def buildfiles(package = None):
    files = package.build_files()
    for build_file in files:
        ui.msg(u'Copy File: %s' % build_file)
예제 #10
0
def root(root_path):
    u''' 源库的根路径 '''
    ui.msg(StaticPackage.get_root(root_path))
예제 #11
0
def init(root_path, publish_path = None, force = False):
    u''' 初始化一个新的库
    
初始化一个新的库,建立template-config.xml配置文件及常用的目录,如果指定了 -p 参数,还可以自动建立与发布目录的连接'''

    # 确保不要init了一个工作区
    if Workspace.get_workspace(root_path) == root_path:
        ui.error(u'工作区不能被初始化')
        return 1

    # 确保不要init了一个publish库
    if StaticPackage.get_publish(root_path):
        ui.error(u'发布目录不能被初始化')
        return 1

    ui.msg(u'初始化%s' % root_path)
    try:
        StaticPackage.init(root_path)
        ui.msg(u'创建配置文件')

    except PackageExistsException:
        ui.error(u'已经存在')
        return 1

    pathnames = ['test', 'doc', 'src', 'lib', 'res']
    for name in pathnames:
        path = os.path.join(root_path, name)
        if not os.path.exists(path):
            os.makedirs(path)
            ui.msg(u'生成默认目录 %s' % name)

    workspace_path = Workspace.get_workspace(root_path)
    if not workspace_path:
        ui.msg(u'没有工作区,请参照 opm help load')
    else:
        workspace = Workspace(workspace_path)

        if not workspace.has_package(root_path):
            workspace.add_package(root_path)
            ui.msg(u'加入本地工作区')
        else:
            ui.msg(u'本地工作区中已存在')

    ui.msg(u'成功!')

    if publish_path:
        link(root_path, publish_path, force = force)
예제 #12
0
            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
    except PackageNotFoundException, e:
        ui.error('%s package not found' % e.url)
        return 1

    if modified or (force and modified != None):
        for modified_file in modified:
            ui.msg(u'Modified: %s' % modified_file)

        ui.msg(u'Compiled: %s' % filename)

    # 未被维护的文件
    elif modified == None:
        #ui.msg(u'No Source: %s' % filename)
        pass

    if not no_build_files:
        buildfiles(package = package)

def buildfiles(package = None):
    files = package.build_files()
    for build_file in files:
        ui.msg(u'Copy File: %s' % build_file)