File: unbieber.py

package info (click to toggle)
pyqwt3d 0.1.8-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 984 kB
  • sloc: python: 3,932; cpp: 328; makefile: 115; sh: 7
file content (72 lines) | stat: -rwxr-xr-x 1,606 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python

import optparse
import os
import sys

def parse_invokation():
    """Return the parsed options and arguments from the command line
    """

    usage = (
        '%prog [-h] [-t N] directory (one or more file name extensions)'
        )

    parser = optparse.OptionParser(usage=usage)
    parser.add_option(
        '-t', '--tabs', default=2, action='store',
        type='int', metavar='N',
        help='Have tabs N characters apart [default 8]'
        )

    options, arguments = parser.parse_args()

    if len(arguments) < 2:
        parser.print_help()
        sys.exit(1)

    return options, arguments

# parse_invokation()


def process(filename, tabsize):
    """Stolen from Python-X.Y.Z/Tools/scripts/untabify
    """
    try:
        f = open(filename)
        text = f.read()
        f.close()
    except IOError, msg:
        print "%r: I/O error: %s" % (filename, msg)
        return

    newtext = text.replace('\r\n', '\n')
    newtext = newtext.expandtabs(tabsize)
    if newtext == text:
        return
    f = open(filename, "w")
    f.write(newtext)
    f.close()
    print filename

# process()
    
def main():
    options, arguments = parse_invokation()
    top = os.path.abspath(arguments[0])
    extensions = arguments[1:]
    for root, directories, files in os.walk(top):
        for file in files:
            _, extension = os.path.splitext(file)
            if extension in extensions:
                process(os.path.join(root, file), options.tabs)

# main

if __name__ == "__main__":
    main()

# Local Variables: ***
# mode: python ***
# End: ***