def workspace(root_path): u''' 源库所在工作区 ''' if StaticPackage.get_root(root_path): ui.msg(Workspace.get_workspace(root_path)) else: ui.msg(u'不是一个源库') return 1
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)
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)))
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)