def main(opts): try: # Load a context with initialization ctx = Context.load(opts.workspace) if not ctx.initialized(): print("A catkin workspace must be initialized before profiles can be managed.") return 1 profiles = get_profile_names(ctx.workspace) active_profile = get_active_profile(ctx.workspace) if opts.subcommand == 'list': print(list_profiles(profiles, active_profile, unformatted=opts.unformatted)) elif opts.subcommand == 'add': if opts.name in profiles: if opts.force: print(clr('[profile] @{yf}Warning:@| Overwriting existing profile named @{cf}%s@|' % (opts.name))) else: print(clr('catkin profile: error: A profile named ' '@{cf}%s@| already exists. Use `--force` to ' 'overwrite.' % (opts.name))) return 1 if opts.copy_active: ctx.profile = opts.name Context.save(ctx) print(clr('[profile] Created a new profile named @{cf}%s@| ' 'based on active profile @{cf}%s@|' % (opts.name, active_profile))) elif opts.copy: if opts.copy in profiles: new_ctx = Context.load(opts.workspace, profile=opts.copy) new_ctx.profile = opts.name Context.save(new_ctx) print(clr('[profile] Created a new profile named @{cf}%s@| ' 'based on profile @{cf}%s@|' % (opts.name, opts.copy))) else: print(clr('[profile] @{rf}A profile with this name does not exist: %s@|' % opts.copy)) else: new_ctx = Context(workspace=ctx.workspace, profile=opts.name) Context.save(new_ctx) print(clr('[profile] Created a new profile named @{cf}%s@| with default settings.' % (opts.name))) profiles = get_profile_names(ctx.workspace) active_profile = get_active_profile(ctx.workspace) print(list_profiles(profiles, active_profile)) elif opts.subcommand == 'set': if opts.name in profiles: set_active_profile(ctx.workspace, opts.name) active_profile = get_active_profile(ctx.workspace) print(clr('[profile] Activated catkin metadata profile: @{cf}%s@|' % active_profile)) else: print('catkin profile: error: Profile `%s` does not exist in workspace `%s`.' % (opts.name[0], ctx.workspace)) return 1 profiles = get_profile_names(ctx.workspace) active_profile = get_active_profile(ctx.workspace) print(list_profiles(profiles, active_profile)) elif opts.subcommand == 'rename': if opts.current_name in profiles: if opts.new_name in profiles: if opts.force: print(clr('[profile] @{yf}Warning:@| Overwriting ' 'existing profile named @{cf}%s@|' % (opts.new_name))) else: print(clr('catkin profile: error: A profile named ' '@{cf}%s@| already exists. Use `--force` to ' 'overwrite.' % (opts.new_name))) return 1 ctx.profile = opts.new_name Context.save(ctx) remove_profile(ctx.workspace, opts.current_name) if opts.current_name == active_profile: set_active_profile(ctx.workspace, opts.new_name) print(clr('[profile] Renamed profile @{cf}%s@| to @{cf}%s@|' % (opts.current_name, opts.new_name))) else: print('catkin profile: error: Profile `%s` does not exist in workspace `%s`.' % (opts.current_name, ctx.workspace)) return 1 profiles = get_profile_names(ctx.workspace) active_profile = get_active_profile(ctx.workspace) print(list_profiles(profiles, active_profile)) elif opts.subcommand == 'remove': for name in opts.name: if name == active_profile: print('Profile `%s` is currently active. Re-setting active profile to `%s`.' % (name, DEFAULT_PROFILE_NAME)) set_active_profile(ctx.workspace, DEFAULT_PROFILE_NAME) if name in profiles: remove_profile(ctx.workspace, name) else: print('catkin profile: error: Profile `%s` does not exist in workspace `%s`.' % (name, ctx.workspace)) return 1 print(clr('[profile] Removed profile: @{rf}%s@|' % name)) profiles = get_profile_names(ctx.workspace) active_profile = get_active_profile(ctx.workspace) print(list_profiles(profiles, active_profile)) except IOError as exc: # Usually happens if workspace is already underneath another catkin_tools workspace print('error: could not %s catkin profile: %s' % (opts.subcommand, exc.message)) return 1 return 0
def main(opts): try: # Load a context with initialization ctx = Context.load(opts.workspace, load_env=False) if not ctx.initialized(): print( "A catkin workspace must be initialized before profiles can be managed." ) return 1 profiles = get_profile_names(ctx.workspace) active_profile = get_active_profile(ctx.workspace) if opts.subcommand == 'list': print( list_profiles(profiles, active_profile, unformatted=opts.unformatted, active=opts.active)) elif opts.subcommand == 'add': if opts.name in profiles: if opts.force: print( clr('[profile] @{yf}Warning:@| Overwriting existing profile named @{cf}%s@|' % (opts.name))) else: print( clr('catkin profile: error: A profile named ' '@{cf}%s@| already exists. Use `--force` to ' 'overwrite.' % (opts.name))) return 1 if opts.copy_active: ctx.profile = opts.name Context.save(ctx) print( clr('[profile] Created a new profile named @{cf}%s@| ' 'based on active profile @{cf}%s@|' % (opts.name, active_profile))) elif opts.copy: if opts.copy in profiles: new_ctx = Context.load(opts.workspace, profile=opts.copy) new_ctx.profile = opts.name Context.save(new_ctx) print( clr('[profile] Created a new profile named @{cf}%s@| ' 'based on profile @{cf}%s@|' % (opts.name, opts.copy))) else: print( clr('[profile] @{rf}A profile with this name does not exist: %s@|' % opts.copy)) else: new_ctx = Context(workspace=ctx.workspace, profile=opts.name) Context.save(new_ctx) print( clr('[profile] Created a new profile named @{cf}%s@| with default settings.' % (opts.name))) profiles = get_profile_names(ctx.workspace) active_profile = get_active_profile(ctx.workspace) print(list_profiles(profiles, active_profile)) elif opts.subcommand == 'set': if opts.name in profiles: set_active_profile(ctx.workspace, opts.name) active_profile = get_active_profile(ctx.workspace) print( clr('[profile] Activated catkin metadata profile: @{cf}%s@|' % active_profile)) else: print( 'catkin profile: error: Profile `%s` does not exist in workspace `%s`.' % (opts.name, ctx.workspace)) return 1 profiles = get_profile_names(ctx.workspace) active_profile = get_active_profile(ctx.workspace) print(list_profiles(profiles, active_profile)) elif opts.subcommand == 'rename': if opts.current_name in profiles: if opts.new_name in profiles: if opts.force: print( clr('[profile] @{yf}Warning:@| Overwriting ' 'existing profile named @{cf}%s@|' % (opts.new_name))) else: print( clr('catkin profile: error: A profile named ' '@{cf}%s@| already exists. Use `--force` to ' 'overwrite.' % (opts.new_name))) return 1 ctx.profile = opts.new_name Context.save(ctx) remove_profile(ctx.workspace, opts.current_name) if opts.current_name == active_profile: set_active_profile(ctx.workspace, opts.new_name) print( clr('[profile] Renamed profile @{cf}%s@| to @{cf}%s@|' % (opts.current_name, opts.new_name))) else: print( 'catkin profile: error: Profile `%s` does not exist in workspace `%s`.' % (opts.current_name, ctx.workspace)) return 1 profiles = get_profile_names(ctx.workspace) active_profile = get_active_profile(ctx.workspace) print(list_profiles(profiles, active_profile)) elif opts.subcommand == 'remove': for name in opts.name: if name == active_profile: print( 'Profile `%s` is currently active. Re-setting active profile to `%s`.' % (name, DEFAULT_PROFILE_NAME)) set_active_profile(ctx.workspace, DEFAULT_PROFILE_NAME) if name in profiles: remove_profile(ctx.workspace, name) else: print( 'catkin profile: error: Profile `%s` does not exist in workspace `%s`.' % (name, ctx.workspace)) return 1 print(clr('[profile] Removed profile: @{rf}%s@|' % name)) profiles = get_profile_names(ctx.workspace) active_profile = get_active_profile(ctx.workspace) print(list_profiles(profiles, active_profile)) except IOError as exc: # Usually happens if workspace is already underneath another catkin_tools workspace print('error: could not %s catkin profile: %s' % (opts.subcommand, exc.message)) return 1 return 0
def main(opts): # Check for exclusivity full_options = opts.deinit space_options = opts.logs or opts.build or opts.devel or opts.install package_options = len(opts.packages) > 0 or opts.orphans advanced_options = opts.setup_files if full_options: if space_options or package_options or advanced_options: log("[clean] Error: Using `--deinit` will remove all spaces, so" " additional partial cleaning options will be ignored.") elif space_options: if package_options: log("[clean] Error: Package arguments are not allowed with space" " arguments (--build, --devel, --install, --logs). See usage.") elif advanced_options: log("[clean] Error: Advanced arguments are not allowed with space" " arguments (--build, --devel, --install, --logs). See usage.") # Check for all profiles option if opts.all_profiles: profiles = get_profile_names(opts.workspace or os.getcwd()) else: profiles = [opts.profile] # Initialize job server job_server.initialize( max_jobs=1, max_load=None, gnu_make_enabled=False) # Clean the requested profiles retcode = 0 for profile in profiles: if not clean_profile(opts, profile): retcode = 1 # Warn before nuking .catkin_tools if retcode == 0: if opts.deinit and not opts.yes: log("") log(clr("[clean] @!@{yf}Warning:@| If you deinitialize this workspace" " you will lose all profiles and all saved build" " configuration. (Use `--yes` to skip this check)")) try: opts.deinit = yes_no_loop("\n[clean] Are you sure you want to deinitialize this workspace?") if not opts.deinit: log(clr("[clean] Not deinitializing workspace.")) except KeyboardInterrupt: log("\n[clean] No actions performed.") sys.exit(0) # Nuke .catkin_tools if opts.deinit: ctx = Context.load(opts.workspace, profile, opts, strict=True, load_env=False) metadata_dir = os.path.join(ctx.workspace, METADATA_DIR_NAME) log("[clean] Deinitializing workspace by removing catkin_tools config: %s" % metadata_dir) if not opts.dry_run: safe_rmtree(metadata_dir, ctx.workspace, opts.force) return retcode