File: scripts.rst

package info (click to toggle)
cssutils 2.11.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,312 kB
  • sloc: python: 23,625; javascript: 803; sh: 62; makefile: 8
file content (173 lines) | stat: -rw-r--r-- 6,881 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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
====================
scripts
====================


The provided scripts are available as a standalone script which is installed in the default PYTHONHOME/scripts directory. Additionally an API for the functionality of the scripts is provided for use in programs.

``CSSParse``
============
Script version of ``cssutils.parseString()``, ``cssutils.parseFile()`` and ``cssutils.parseUrl()``.

Usage: cssparse-script.py [options] filename1.css [filename2.css ...]
        [>filename_combined.css] [2>parserinfo.log]

Options:
  -h, --help            show this help message and exit
  -s, --string          parse given string
  -u URL, --url=URL     parse given url
  -e ENCODING, --encoding=ENCODING
                        encoding of the file or override encoding found
  -m, --minify          minify parsed CSS
  -d, --debug           activate debugging output


``CSSCapture``
==============
``CSSCapture`` downloads all referenced CSS stylesheets of a given URL and saves them to a given target directory.

programmatic use
----------------
example::

    >>> url = 'http://cthedot.de'
    >>> from cssutils.script import CSSCapture
    >>> capturer = CSSCapture(ua=None, log=None, defaultloglevel=logging.INFO)
    >>> stylesheetlist = capturer.capture(url)
    >>> print stylesheetlist
    [cssutils.css.CSSStyleSheet(href=u'http://cthedot.de/css/default.css', media=None, title=None),
     cssutils.css.CSSStyleSheet(href=u'http://cthedot.de/static/alternate1.css', media=None, title=u'red'),
     cssutils.css.CSSStyleSheet(href=u'http://cthedot.de/static/alternate2.css', media=None, title=u'blue')]

script use
----------
Usage: csscapture-script.py [options] URL

Options:
  -h, --help            show this help message and exit
  -d, --debug           show debug messages during capturing
  -m, --minified        saves minified version of captured files
  -n, --notsave         if given files are NOT saved, only log is written
  -s SAVETO, --saveto=SAVETO
                        saving retrieved files to "saveto", defaults to "_CSSCapture_SAVED"
  -u UA, --useragent=UA
                        useragent to use for request of URL, default is urllib2s default

The following example outputs a list of stylesheets found with title and href of the found stylesheet. (``PYTHONHOME/Scripts`` should be on your ``PATH``.  Additional log output is not shown.)::

    > csscapture http://cthedot.de/static/cssutils/examples/capturefrom.html -n

    1.
        encoding: 'utf-8'
        title: u'html 1: link1'
        href: u'http://cthedot.de/css/default.css'
    2.
        encoding: 'utf-8'
        title: u'html 2: style1'
        href: None
    3.
        encoding: 'utf-8'
        title: u'HTML 2.1: @import'
        href: u'http://cthedot.de/static/cssutils/examples/inlineimport1.css'
    4.
        encoding: 'utf-8'
        title: u'html 3: link2'
        href: u'http://cthedot.de/static/cssutils/examples/link1.css'
    5.
        encoding: 'utf-8'
        title: u'link1: s1'
        href: u'http://cthedot.de/static/cssutils/examples/linkimport1.css'
    6.
        encoding: 'utf-8'
        title: None
        href: u'http://cthedot.de/static/cssutils/examples/css/linkimportimport1.css'
    7.
        encoding: 'utf-8'
        title: None
        href: u'http://cthedot.de/static/cssutils/examples/css/linkimportimport2.css'
    8.
        encoding: 'iso-8859-1'
        title: u'link1: s2'
        href: u'http://cthedot.de/static/cssutils/examples/linkimport2.css'
    9.
        encoding: 'utf-8'
        title: u'html 4: style2'
        href: None
    10.
        encoding: 'utf-8'
        title: None
        href: u'http://cthedot.de/static/cssutils/examples/css/inlineimport2.css'
    11.
        encoding: 'utf-8'
        title: None
        href: u'http://cthedot.de/static/cssutils/examples/css/inlineimportimport1.css'

``CSSCombine``
==============
``csscombine`` may be used to combine several sheets loaded from a main sheet via @import rules. Nested @import rules are resolved from cssutils 0.9.6a1.

The resulting combined sheet (optionally minified) is send to stdout, info and error messages are handled by the normal cssutils log.

``csscombine`` may also be used to change the encoding of the stylesheet if a target encoding is given.

programmatic use
----------------
example::

    >>> from cssutils.script import csscombine
    >>> proxypath = 'sheets/import.css'
    >>> print csscombine(path=proxypath, sourceencoding=None, targetencoding='utf-8', minify=False)
    INFO    Combining files from None
    INFO    Processing @import u'import/import2.css'
    INFO    Processing @import u'../import3.css'
    INFO    @import: Adjusting paths for u'../import3.css'
    INFO    Processing @import u'import-impossible.css'
    INFO    @import: Adjusting paths for u'import-impossible.css'
    WARNING Cannot combine imported sheet with given media as other rules then comments or stylerules found cssutils.css.CSSNamespaceRule(namespaceURI=u'y', prefix=u''), keeping u'@import "import-impossible.css" print;'
    INFO    @import: Adjusting paths for u'import/import2.css'
    INFO    Using target encoding: 'utf-8'
    @charset "utf-8";
    /* START @import "import/import2.css" */
    @import "import-impossible.css" print;
    /* START @import "../import3.css" */
    /* import3 */
    .import3 {
        /* from ./import/../import3.css */
        background: url(images/example3.gif);
        background: url(images/example3.gif);
        background: url(import/images2/example2.gif);
        background: url(import/images2/example2.gif);
        background: url(images/example3.gif)
        }
    /* START @import "import-impossible.css" */
    .import2 {
        /* sheets/import2.css */
        background: url(http://example.com/images/example.gif);
        background: url(//example.com/images/example.gif);
        background: url(/images/example.gif);
        background: url(import/images2/example.gif);
        background: url(import/images2/example.gif);
        background: url(images/example.gif);
        background: url(images/example.gif)
        }
    .import {
        /* ./import.css */
        background-image: url(images/example.gif)
        }


script use
----------
Usage: csscombine-script.py [options] [path]

Options:
  -h, --help            show this help message and exit
  -u URL, --url=URL     URL to parse (path is ignored if URL given)
  -s SOURCEENCODING, --sourceencoding=SOURCEENCODING
                        encoding of input, defaulting to "css". If given
                        overwrites other encoding information like @charset
                        declarations
  -t TARGETENCODING, --targetencoding=TARGETENCODING
                        encoding of output, defaulting to "UTF-8"
  -m, --minify          saves minified version of combined files, defaults to
                        False