1
2 """
3 utility scripts installed as Python scripts
4 """
5 __docformat__ = 'restructuredtext'
6 __version__ = '$Id: cssparse.py 1116 2008-03-05 13:52:23Z cthedot $'
7
8 import cssutils
9 import logging
10 import optparse
11 import sys
12
14 """
15 Parses given filename(s) (using optional encoding) and prints the content
16
17 Redirect stdout to save CSS. Redirect stderr to save parser log infos.
18 """
19
20 usage = """usage: %prog [options] filename1.css [filename2.css ...]
21 [>filename_combined.css] [2>parserinfo.log] """
22 p = optparse.OptionParser(usage=usage)
23 p.add_option('-e', '--encoding', action='store', dest='encoding',
24 help='encoding of the file')
25 p.add_option('-d', '--debug', action='store_true', dest='debug',
26 help='activate debugging output')
27
28 (options, filenames) = p.parse_args(args)
29
30 if not filenames:
31 p.error("no filename given")
32
33
34
35
36
37
38
39
40
41 if options.debug:
42 p = cssutils.CSSParser(loglevel=logging.DEBUG)
43 else:
44 p = cssutils.CSSParser()
45
46 for filename in filenames:
47 sys.stderr.write('=== CSS FILE: "%s" ===\n' % filename)
48 sheet = p.parse(filename, encoding=options.encoding)
49 print sheet.cssText
50 print
51 sys.stderr.write('\n')
52
53
54 if __name__ == "__main__":
55 sys.exit(main())
56