~crunch.io/ubuntu/precise/codespeak-lib/unstable

« back to all changes in this revision

Viewing changes to py/_cmdline/pycleanup.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-08-01 16:24:01 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100801162401-g37v49d1p148alpm
Tags: 1.3.3-1
* New upstream release.
* Bump Standards-Version to 3.9.1.
* Fix typo in py.test manpage.
* Prefer Breaks: over Conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python 
 
1
#!/usr/bin/env python
2
2
 
3
3
"""\
4
4
py.cleanup [PATH] ...
5
5
 
6
6
Delete typical python development related files recursively under the specified PATH (which defaults to the current working directory). Don't follow links and don't recurse into directories with a dot.  Optionally remove setup.py related files and empty
7
 
directories. 
 
7
directories.
8
8
 
9
9
"""
10
10
import py
12
12
 
13
13
def main():
14
14
    parser = py.std.optparse.OptionParser(usage=__doc__)
15
 
    parser.add_option("-e", metavar="ENDING", 
16
 
        dest="endings", default=[".pyc", "$py.class"], action="append", 
17
 
        help=("(multi) recursively remove files with the given ending." 
 
15
    parser.add_option("-e", metavar="ENDING",
 
16
        dest="endings", default=[".pyc", "$py.class"], action="append",
 
17
        help=("(multi) recursively remove files with the given ending."
18
18
             " '.pyc' and '$py.class' are in the default list."))
19
19
    parser.add_option("-d", action="store_true", dest="removedir",
20
20
                      help="remove empty directories.")
22
22
                      help="remove 'build' and 'dist' directories next to setup.py files")
23
23
    parser.add_option("-a", action="store_true", dest="all",
24
24
                      help="synonym for '-S -d -e pip-log.txt'")
25
 
    parser.add_option("-n", "--dryrun", dest="dryrun", default=False, 
26
 
        action="store_true", 
 
25
    parser.add_option("-n", "--dryrun", dest="dryrun", default=False,
 
26
        action="store_true",
27
27
        help="don't actually delete but display would-be-removed filenames.")
28
28
    (options, args) = parser.parse_args()
29
29
 
44
44
        if self.options.setup:
45
45
            for arg in self.args:
46
46
                self.setupclean(arg)
47
 
        
 
47
 
48
48
        for path in self.args:
49
 
            py.builtin.print_("cleaning path", path, 
 
49
            py.builtin.print_("cleaning path", path,
50
50
                "of extensions", self.options.endings)
51
51
            for x in path.visit(self.shouldremove, self.recursedir):
52
52
                self.remove(x)
78
78
            subprocess.call([sys.executable, str(setup)] + list(args))
79
79
        finally:
80
80
            old.chdir()
81
 
            
 
81
 
82
82
    def setupclean(self, path):
83
83
        for x in path.visit("setup.py", self.recursedir):
84
84
            basepath = x.dirpath()