From bf2e372c304be2333dc97256d53f632e995a5d9d Mon Sep 17 00:00:00 2001 From: Marcus Huewe Date: Thu, 12 Sep 2013 16:13:18 +0200 Subject: [PATCH] - added new "osc clean" command "osc clean" removes all untracked files from a package working copy. --- osc/commandline.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/osc/commandline.py b/osc/commandline.py index 0a587622..e159ba75 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -7977,6 +7977,35 @@ Please submit there instead, or use --nodevelproject to force direct submission. else: print('osc: working copy \'%s\' is not inconsistent' % i, file=sys.stderr) + @cmdln.option('-n', '--dry-run', action='store_true', + help='print the results without actually removing a file') + def do_clean(self, subcmd, opts, *args): + """${cmd_name}: removes all untracked files from the package working copy + + Examples: + osc clean + + Note: if is omitted it defaults to '.' ( has to + be a package working copy) + + Warning: This command removes all files with status '?'. + + ${cmd_usage} + ${cmd_option_list} + """ + pacs = parseargs(args) + # do a sanity check first + for pac in pacs: + if not is_package_dir(pac): + raise oscerr.WrongArgs('\'%s\' is no package working copy' % pac) + for pdir in pacs: + p = Package(pdir) + pdir = getTransActPath(pdir) + for filename in (fname for st, fname in p.get_status() if st == '?'): + print('Removing: %s' % os.path.join(pdir, filename)) + if not opts.dry_run: + os.unlink(os.path.join(p.absdir, filename)) + def _load_plugins(self): plugin_dirs = [ '/usr/lib/osc-plugins',