def run(args):
    wsdir = get_workspace_location(args.workspace)
    config = Config(wsdir)
    cache = Cache(wsdir)
    ros_rootdir = find_ros_root(config.get('ros_root', None))
    if (ros_rootdir is None):
        fatal('cannot detect ROS distribution. Have you sourced your setup.bash?\n')
    if args.this:
        if (args.offline is None):
            args.offline = config.get('offline_mode', False)
            if args.offline:
                warning("offline mode. Run 'rosrepo config --online' to disable\n")
        ws_state = get_workspace_state(wsdir, config, cache, offline_mode=args.offline)
        args.packages = resolve_this(wsdir, ws_state)
    elif (args.vanished or args.unused):
        if (args.offline is None):
            args.offline = config.get('offline_mode', False)
            if args.offline:
                warning("offline mode. Run 'rosrepo config --online' to disable\n")
        ws_state = get_workspace_state(wsdir, config, cache, offline_mode=args.offline)
        args.packages = []
        for d in scandir(os.path.join(wsdir, 'build')):
            if (d.is_dir() and (d.name not in ws_state.ws_packages) and (not (d.name == 'catkin_tools_prebuild'))):
                args.packages.append(d.name)
        if args.unused:
            (depends, _, conflicts) = find_dependees((config['pinned_build'] + config['default_build']), ws_state, ignore_missing=True)
            show_conflicts(conflicts)
            if conflicts:
                fatal('cannot resolve dependencies\n')
            unused_packages = (set(ws_state.ws_packages) - set(depends.keys()))
            args.packages += [p for p in unused_packages if os.path.isdir(os.path.join(wsdir, 'build', p))]
        if (not args.packages):
            msg('Nothing to clean\n')
            return 0
    if (not args.dry_run):
        invoke = ['catkin', 'config', '--extend', ros_rootdir]
        call_process(invoke, stdout=PIPE, stderr=PIPE)
        config['last_ros_root'] = ros_rootdir
        config.write()
    catkin_clean = ['catkin', 'clean', '--workspace', wsdir, '--yes']
    if args.dry_run:
        catkin_clean.append('--dry-run')
    catkin_clean += (args.packages or ['--all'])
    return call_process(catkin_clean)
def run(args):
    wsdir = get_workspace_location(args.workspace)
    config = Config(wsdir)
    cache = Cache(wsdir)
    ros_rootdir = find_ros_root(config.get('ros_root', None))
    if (ros_rootdir is None):
        fatal('cannot detect ROS distribution. Have you sourced your setup.bash?\n')
    if args.this:
        if (args.offline is None):
            args.offline = config.get('offline_mode', False)
            if args.offline:
                warning("offline mode. Run 'rosrepo config --online' to disable\n")
        ws_state = get_workspace_state(wsdir, config, cache, offline_mode=args.offline)
        args.packages = resolve_this(wsdir, ws_state)
    elif (args.vanished or args.unused):
        if (args.offline is None):
            args.offline = config.get('offline_mode', False)
            if args.offline:
                warning("offline mode. Run 'rosrepo config --online' to disable\n")
        ws_state = get_workspace_state(wsdir, config, cache, offline_mode=args.offline)
        args.packages = []
        for d in scandir(os.path.join(wsdir, 'build')):
            if (d.is_dir() and (d.name not in ws_state.ws_packages) and (not (d.name == 'catkin_tools_prebuild'))):
                args.packages.append(d.name)
        if args.unused:
            (depends, _, conflicts) = find_dependees((config['pinned_build'] + config['default_build']), ws_state, ignore_missing=True)
            show_conflicts(conflicts)
            if conflicts:
                fatal('cannot resolve dependencies\n')
            unused_packages = (set(ws_state.ws_packages) - set(depends.keys()))
            args.packages += [p for p in unused_packages if os.path.isdir(os.path.join(wsdir, 'build', p))]
        if (not args.packages):
            msg('Nothing to clean\n')
            return 0
    if (not args.dry_run):
        invoke = ['catkin', 'config', '--extend', ros_rootdir]
        call_process(invoke, stdout=PIPE, stderr=PIPE)
        config['last_ros_root'] = ros_rootdir
        config.write()
    catkin_clean = ['catkin', 'clean', '--workspace', wsdir, '--yes']
    if args.dry_run:
        catkin_clean.append('--dry-run')
    catkin_clean += (args.packages or ['--all'])
    return call_process(catkin_clean)