Package cssutils :: Package scripts :: Module cssparse |
[hide private]
[frames] | no frames]

# Source Code for Module cssutils.scripts.cssparse

     1  #!/usr/bin/env python
     2  """
     3  utility scripts installed as Python scripts
     4  """
     5  __docformat__ = 'restructuredtext'
     6  __author__ = '$LastChangedBy: doerwalter $'
     7  __date__ = '$LastChangedDate: 2007-08-07 12:33:59 +0200 (Di, 07 Aug 2007) $'
     8  __version__ = '0.9.2b3 $LastChangedRevision: 185 $'
     9
    10  import cssutils
    11  import logging
    12  import optparse
    13  import sys
    14
    15 -def main(args=None):
    16      """
    17      Parses given filename(s) (using optional encoding) and prints the content
    18
    19      Redirect stdout to save CSS. Redirect stderr to save parser log infos.
    20      """
    21
    22      usage = """usage: %prog [options] filename1.css [filename2.css ...]
    23          [>filename_combined.css] [2>parserinfo.log] """
    24      p = optparse.OptionParser(usage=usage)
    25      p.add_option('-e', '--encoding', action='store', dest='encoding',
    26          help='encoding of the file')
    27      p.add_option('-d', '--debug', action='store_true', dest='debug',
    28          help='activate debugging output')
    29
    30      (options, filenames) = p.parse_args(args)
    31
    32      if not filenames:
    33          p.error("no filename given")
    34
    35  ##    newlog = logging.getLogger('CSSPARSER')
    36  ##    hdlr = logging.FileHandler('CSSPARSER.log', 'w')
    37  ##    formatter = logging.Formatter('%(levelname)s\t%(message)s')
    38  ##    hdlr.setFormatter(formatter)
    39  ##    newlog.addHandler(hdlr)
    40  ##    newlog.setLevel(logging.DEBUG)
    41  ##    p = CSSParser(log=newlog, loglevel=logging.DEBUG)
    42
    43      if options.debug:
    44          p = cssutils.CSSParser(loglevel=logging.DEBUG)
    45      else:
    46          p = cssutils.CSSParser()
    47
    48      for filename in filenames:
    49          sys.stderr.write('=== CSS FILE: "%s" ===\n' % filename)
    50          sheet = p.parse(filename, encoding=options.encoding)
    51          print sheet.cssText
    52          print
    53          sys.stderr.write('\n')
    54
    55
    56  if __name__ == "__main__":
    57          sys.exit(main())
    58