forked from jaraco/cssutils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.html
More file actions
360 lines (347 loc) · 18.3 KB
/
scripts.html
File metadata and controls
360 lines (347 loc) · 18.3 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>scripts — cssutils 0.9.8 documentation</title>
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '0.9.8',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="cssutils 0.9.8 documentation" href="../index.html" />
<link rel="next" title="CSS codec" href="codec.html" />
<link rel="prev" title="logging" href="logging.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="codec.html" title="CSS codec"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="logging.html" title="logging"
accesskey="P">previous</a> |</li>
<li><a href="../index.html">cssutils 0.9.8 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="scripts">
<h1>scripts<a class="headerlink" href="#scripts" title="Permalink to this headline">¶</a></h1>
<p>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.</p>
<div class="section" id="cssparse">
<h2><tt class="docutils literal"><span class="pre">CSSParse</span></tt><a class="headerlink" href="#cssparse" title="Permalink to this headline">¶</a></h2>
<p>Script version of <tt class="docutils literal"><span class="pre">cssutils.parseString()</span></tt>, <tt class="docutils literal"><span class="pre">cssutils.parseFile()</span></tt> and <tt class="docutils literal"><span class="pre">cssutils.parseUrl()</span></tt>.</p>
<dl class="docutils">
<dt>Usage: cssparse-script.py [options] filename1.css [filename2.css ...]</dt>
<dd>[>filename_combined.css] [2>parserinfo.log]</dd>
<dt>Options:</dt>
<dd><table class="first last docutils option-list" frame="void" rules="none">
<col class="option" />
<col class="description" />
<tbody valign="top">
<tr><td class="option-group">
<kbd><span class="option">-h</span>, <span class="option">--help</span></kbd></td>
<td>show this help message and exit</td></tr>
<tr><td class="option-group">
<kbd><span class="option">-s</span>, <span class="option">--string</span></kbd></td>
<td>parse given string</td></tr>
<tr><td class="option-group" colspan="2">
<kbd><span class="option">-u <var>URL</var></span>, <span class="option">--url=<var>URL</var></span></kbd></td>
</tr>
<tr><td> </td><td>parse given url</td></tr>
<tr><td class="option-group" colspan="2">
<kbd><span class="option">-e <var>ENCODING</var></span>, <span class="option">--encoding=<var>ENCODING</var></span></kbd></td>
</tr>
<tr><td> </td><td>encoding of the file or override encoding found</td></tr>
<tr><td class="option-group">
<kbd><span class="option">-m</span>, <span class="option">--minify</span></kbd></td>
<td>minify parsed CSS</td></tr>
<tr><td class="option-group">
<kbd><span class="option">-d</span>, <span class="option">--debug</span></kbd></td>
<td>activate debugging output</td></tr>
</tbody>
</table>
</dd>
</dl>
</div>
<div class="section" id="csscapture">
<h2><tt class="docutils literal"><span class="pre">CSSCapture</span></tt><a class="headerlink" href="#csscapture" title="Permalink to this headline">¶</a></h2>
<p><tt class="docutils literal"><span class="pre">CSSCapture</span></tt> downloads all referenced CSS stylesheets of a given URL and saves them to a given target directory.</p>
<div class="section" id="programmatic-use">
<h3>programmatic use<a class="headerlink" href="#programmatic-use" title="Permalink to this headline">¶</a></h3>
<p>example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">url</span> <span class="o">=</span> <span class="s">'http://cthedot.de'</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">cssutils.script</span> <span class="kn">import</span> <span class="n">CSSCapture</span>
<span class="gp">>>> </span><span class="n">capturer</span> <span class="o">=</span> <span class="n">CSSCapture</span><span class="p">(</span><span class="n">ua</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">log</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">defaultloglevel</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">stylesheetlist</span> <span class="o">=</span> <span class="n">capturer</span><span class="o">.</span><span class="n">capture</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">print</span> <span class="n">stylesheetlist</span>
<span class="go">[cssutils.css.CSSStyleSheet(href=u'http://cthedot.de/css/default.css', media=None, title=None),</span>
<span class="go"> cssutils.css.CSSStyleSheet(href=u'http://cthedot.de/static/alternate1.css', media=None, title=u'red'),</span>
<span class="go"> cssutils.css.CSSStyleSheet(href=u'http://cthedot.de/static/alternate2.css', media=None, title=u'blue')]</span>
</pre></div>
</div>
</div>
<div class="section" id="script-use">
<h3>script use<a class="headerlink" href="#script-use" title="Permalink to this headline">¶</a></h3>
<p>Usage: csscapture-script.py [options] URL</p>
<dl class="docutils">
<dt>Options:</dt>
<dd><table class="first last docutils option-list" frame="void" rules="none">
<col class="option" />
<col class="description" />
<tbody valign="top">
<tr><td class="option-group">
<kbd><span class="option">-h</span>, <span class="option">--help</span></kbd></td>
<td>show this help message and exit</td></tr>
<tr><td class="option-group">
<kbd><span class="option">-d</span>, <span class="option">--debug</span></kbd></td>
<td>show debug messages during capturing</td></tr>
<tr><td class="option-group">
<kbd><span class="option">-m</span>, <span class="option">--minified</span></kbd></td>
<td>saves minified version of captured files</td></tr>
<tr><td class="option-group">
<kbd><span class="option">-n</span>, <span class="option">--notsave</span></kbd></td>
<td>if given files are NOT saved, only log is written</td></tr>
<tr><td class="option-group" colspan="2">
<kbd><span class="option">-s <var>SAVETO</var></span>, <span class="option">--saveto=<var>SAVETO</var></span></kbd></td>
</tr>
<tr><td> </td><td>saving retrieved files to “saveto”, defaults to “_CSSCapture_SAVED”</td></tr>
<tr><td class="option-group" colspan="2">
<kbd><span class="option">-u <var>UA</var></span>, <span class="option">--useragent=<var>UA</var></span></kbd></td>
</tr>
<tr><td> </td><td>useragent to use for request of URL, default is urllib2s default</td></tr>
</tbody>
</table>
</dd>
</dl>
<p>The following example outputs a list of stylesheets found with title and href of the found stylesheet. (<tt class="docutils literal"><span class="pre">PYTHONHOME/Scripts</span></tt> should be on your <tt class="docutils literal"><span class="pre">PATH</span></tt>. Additional log output is not shown.):</p>
<div class="highlight-python"><pre>> 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'</pre>
</div>
</div>
</div>
<div class="section" id="csscombine">
<h2><tt class="docutils literal"><span class="pre">CSSCombine</span></tt><a class="headerlink" href="#csscombine" title="Permalink to this headline">¶</a></h2>
<p><tt class="docutils literal"><span class="pre">csscombine</span></tt> 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.</p>
<p>The resulting combined sheet (optionally minified) is send to stdout, info and error messages are handled by the normal cssutils log.</p>
<p><tt class="docutils literal"><span class="pre">csscombine</span></tt> may also be used to change the encoding of the stylesheet if a target encoding is given.</p>
<div class="section" id="id1">
<h3>programmatic use<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
<p>example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">cssutils.script</span> <span class="kn">import</span> <span class="n">csscombine</span>
<span class="gp">>>> </span><span class="n">proxypath</span> <span class="o">=</span> <span class="s">'sheets/import.css'</span>
<span class="gp">>>> </span><span class="k">print</span> <span class="n">csscombine</span><span class="p">(</span><span class="n">path</span><span class="o">=</span><span class="n">proxypath</span><span class="p">,</span> <span class="n">sourceencoding</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">targetencoding</span><span class="o">=</span><span class="s">'utf-8'</span><span class="p">,</span> <span class="n">minify</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="go">INFO Combining files from None</span>
<span class="go">INFO Processing @import u'import/import2.css'</span>
<span class="go">INFO Processing @import u'../import3.css'</span>
<span class="go">INFO @import: Adjusting paths for u'../import3.css'</span>
<span class="go">INFO Processing @import u'import-impossible.css'</span>
<span class="go">INFO @import: Adjusting paths for u'import-impossible.css'</span>
<span class="go">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;'</span>
<span class="go">INFO @import: Adjusting paths for u'import/import2.css'</span>
<span class="go">INFO Using target encoding: 'utf-8'</span>
<span class="go">@charset "utf-8";</span>
<span class="go">/* START @import "import/import2.css" */</span>
<span class="go">@import "import-impossible.css" print;</span>
<span class="go">/* START @import "../import3.css" */</span>
<span class="go">/* import3 */</span>
<span class="go">.import3 {</span>
<span class="go"> /* from ./import/../import3.css */</span>
<span class="go"> background: url(images/example3.gif);</span>
<span class="go"> background: url(images/example3.gif);</span>
<span class="go"> background: url(import/images2/example2.gif);</span>
<span class="go"> background: url(import/images2/example2.gif);</span>
<span class="go"> background: url(images/example3.gif)</span>
<span class="go"> }</span>
<span class="go">/* START @import "import-impossible.css" */</span>
<span class="go">.import2 {</span>
<span class="go"> /* sheets/import2.css */</span>
<span class="go"> background: url(http://example.com/images/example.gif);</span>
<span class="go"> background: url(//example.com/images/example.gif);</span>
<span class="go"> background: url(/images/example.gif);</span>
<span class="go"> background: url(import/images2/example.gif);</span>
<span class="go"> background: url(import/images2/example.gif);</span>
<span class="go"> background: url(images/example.gif);</span>
<span class="go"> background: url(images/example.gif)</span>
<span class="go"> }</span>
<span class="go">.import {</span>
<span class="go"> /* ./import.css */</span>
<span class="go"> background-image: url(images/example.gif)</span>
<span class="go"> }</span>
</pre></div>
</div>
</div>
<div class="section" id="id2">
<h3>script use<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3>
<p>Usage: csscombine-script.py [options] [path]</p>
<dl class="docutils">
<dt>Options:</dt>
<dd><table class="first last docutils option-list" frame="void" rules="none">
<col class="option" />
<col class="description" />
<tbody valign="top">
<tr><td class="option-group">
<kbd><span class="option">-h</span>, <span class="option">--help</span></kbd></td>
<td>show this help message and exit</td></tr>
<tr><td class="option-group" colspan="2">
<kbd><span class="option">-u <var>URL</var></span>, <span class="option">--url=<var>URL</var></span></kbd></td>
</tr>
<tr><td> </td><td>URL to parse (path is ignored if URL given)</td></tr>
<tr><td class="option-group" colspan="2">
<kbd><span class="option">-s <var>SOURCEENCODING</var></span>, <span class="option">--sourceencoding=<var>SOURCEENCODING</var></span></kbd></td>
</tr>
<tr><td> </td><td>encoding of input, defaulting to “css”. If given
overwrites other encoding information like @charset
declarations</td></tr>
<tr><td class="option-group" colspan="2">
<kbd><span class="option">-t <var>TARGETENCODING</var></span>, <span class="option">--targetencoding=<var>TARGETENCODING</var></span></kbd></td>
</tr>
<tr><td> </td><td>encoding of output, defaulting to “UTF-8”</td></tr>
<tr><td class="option-group">
<kbd><span class="option">-m</span>, <span class="option">--minify</span></kbd></td>
<td>saves minified version of combined files, defaults to
False</td></tr>
</tbody>
</table>
</dd>
</dl>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">scripts</a><ul>
<li><a class="reference internal" href="#cssparse"><tt class="docutils literal"><span class="pre">CSSParse</span></tt></a></li>
<li><a class="reference internal" href="#csscapture"><tt class="docutils literal"><span class="pre">CSSCapture</span></tt></a><ul>
<li><a class="reference internal" href="#programmatic-use">programmatic use</a></li>
<li><a class="reference internal" href="#script-use">script use</a></li>
</ul>
</li>
<li><a class="reference internal" href="#csscombine"><tt class="docutils literal"><span class="pre">CSSCombine</span></tt></a><ul>
<li><a class="reference internal" href="#id1">programmatic use</a></li>
<li><a class="reference internal" href="#id2">script use</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="logging.html"
title="previous chapter">logging</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="codec.html"
title="next chapter">CSS codec</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/docs/scripts.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="codec.html" title="CSS codec"
>next</a> |</li>
<li class="right" >
<a href="logging.html" title="logging"
>previous</a> |</li>
<li><a href="../index.html">cssutils 0.9.8 documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2004-2011, Christof Höke.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
</div>
</body>
</html>