def do(cls, ws, args): '''Executes the rename command.''' if args.old_ws == 'default': raise WSError('cannot rename the default workspace; please use ws ' 'default if you want to change it') old_ws_dir = get_ws_dir(args.root, args.old_ws) if not os.path.exists(old_ws_dir): raise WSError('workspace %s does not exist' % args.old_ws) d = parse_manifest(args.root) for proj in d: build_dir = get_build_dir(old_ws_dir, proj) if os.path.exists(build_dir): raise WSError('cannot rename a workspace that contains build ' 'artifacts, as some builds contain absolute ' 'paths and are thus not relocatable. Please ' 'force-clean this workspace first and then ' 'rename it.') new_ws_dir = get_ws_dir(args.root, args.new_ws) if os.path.exists(new_ws_dir): raise WSError('workspace %s already exists; please delete it ' 'first if you want to do this rename' % args.new_ws) rename(old_ws_dir, new_ws_dir) default_link = get_default_ws_link(args.root) if os.readlink(default_link) == args.old_ws: remove(default_link) symlink(args.new_ws, default_link)
def do(cls, _, args): '''Executes the remove command.''' ws_dir = get_ws_dir(args.root, args.remove_ws) if not os.path.exists(ws_dir): raise WSError('workspace %s does not exist' % args.remove_ws) if args.default is not None: default_ws_dir = get_ws_dir(args.root, args.default) if not os.path.exists(default_ws_dir): raise WSError('workspace %s does not exist' % args.default) default_link = get_default_ws_link(args.root) is_default = (os.readlink(default_link) == args.remove_ws) if is_default: # If the deleted workspace is the default, force the user to choose # a new one. if args.default is None: raise WSError('trying to remove the default workspace; must ' 'specify a new default via -d/--default') elif args.default: raise WSError('-d/--default is not applicable unless you are ' 'removing the default workspace') # We are good to go. rmtree(ws_dir) if is_default: remove(default_link) symlink(args.default, default_link)
def invalidate_checksum(ws, proj): '''Invalidates the current project checksum. This can be used to force a project to rebuild, for example if one of its dependencies rebuilds.''' log('invalidating checksum for %s' % proj) if dry_run(): return try: remove(get_checksum_file(ws, proj)) except OSError as e: if e.errno != errno.ENOENT: raise
def get_ws_config(ws): # noqa: E302 '''Parses the current workspace config, returning a dictionary of the state.''' global _WS_CONFIG if _WS_CONFIG is None: config_path = get_ws_config_path(ws) with open(config_path, 'r') as f: _WS_CONFIG = yaml.safe_load(f) global _ORIG_WS_CONFIG # Save a copy of the config so we know later whether or not to # write it out when someone asks to sync the config. _ORIG_WS_CONFIG = copy.deepcopy(_WS_CONFIG) # Check if projects were added or removed from the manifest. If so, the # config needs to be updated accordingly. d = parse_manifest(get_ws_root(ws)) deletions = [] for proj in _WS_CONFIG['projects']: if proj not in d: deletions.append(proj) for proj in deletions: del _WS_CONFIG['projects'][proj] checksum_file = get_checksum_file(ws, proj) proj_dir = get_proj_dir(ws, proj) log('removing project %s, which is not in the manifest' % proj, logging.INFO) remove(checksum_file, True) rmtree(proj_dir, True) for proj in d: if proj in _WS_CONFIG['projects']: continue # Project is not in the config, so add it in. _WS_CONFIG['projects'][proj] = get_new_config(proj) # Split all project arguments by spaces so that args like '-D something' # turn into ['-D', 'something'], which is what exec requires. We do this # at parse time rather than in the "config" command to allow the user to # hand-edit in a natural way and have the config still work properly. The # next time the config is saved, it will be split by spaces. for proj, proj_map in _WS_CONFIG['projects'].items(): parsed_args = [] args = proj_map['args'] for arg in args: parsed_args.extend(arg.split()) proj_map['args'] = parsed_args return _WS_CONFIG
def do(cls, _, args): '''Executes the default command.''' link = get_default_ws_link(args.root) if args.default_ws is None: # Just report what the default currently is. dest = os.path.basename(os.path.realpath(link)) print(dest) return ws_dir = get_ws_dir(args.root, args.default_ws) remove(link) if not os.path.exists(ws_dir): raise WSError('Cannot make non-existent workspace %s the default' % args.default_ws) symlink(args.default_ws, link)