File: precompiler.py

package info (click to toggle)
python-django-compressor 4.5.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,108 kB
  • sloc: python: 4,900; makefile: 123; javascript: 5
file content (45 lines) | stat: -rw-r--r-- 916 bytes parent folder | download
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
#!/usr/bin/env python
import optparse
import sys


def main():
    p = optparse.OptionParser()
    p.add_option(
        "-f",
        "--file",
        action="store",
        type="string",
        dest="filename",
        help="File to read from, defaults to stdin",
        default=None,
    )
    p.add_option(
        "-o",
        "--output",
        action="store",
        type="string",
        dest="outfile",
        help="File to write to, defaults to stdout",
        default=None,
    )

    options, arguments = p.parse_args()

    if options.filename:
        with open(options.filename) as f:
            content = f.read()
    else:
        content = sys.stdin.read()

    content = content.replace("background:", "color:")

    if options.outfile:
        with open(options.outfile, "w") as f:
            f.write(content)
    else:
        print(content)


if __name__ == "__main__":
    main()