10713.1.1
by Gary Poster
use new version of z3c.recipe.filetemplate and zc.buildout fork to use relative paths. |
1 |
#!${buildout:executable} -S
|
7675.507.16
by Edwin Grubbs
Refactored into spriteutils.py |
2 |
|
3 |
import os |
|
4 |
import sys |
|
5 |
||
10713.1.1
by Gary Poster
use new version of z3c.recipe.filetemplate and zc.buildout fork to use relative paths. |
6 |
# Initialize our paths.
|
7 |
${python-relative-path-setup} |
|
8 |
sys.path.insert(0, ${scripts:parts-directory|path-repr}) |
|
9 |
import site |
|
10 |
||
7675.507.30
by Edwin Grubbs
Added tests. Moved to lp.services. |
11 |
from lp.services.spriteutils import SpriteUtil |
12 |
||
13 |
command_options = ('create-image', 'create-css') |
|
7675.507.16
by Edwin Grubbs
Refactored into spriteutils.py |
14 |
|
7675.507.33
by Edwin Grubbs
Addressed reviewer comments. |
15 |
def usage(): |
16 |
return " Usage: %s %s" % (sys.argv[0], '|'.join(command_options)) |
|
17 |
||
7675.507.16
by Edwin Grubbs
Refactored into spriteutils.py |
18 |
if len(sys.argv) != 2: |
7675.507.30
by Edwin Grubbs
Added tests. Moved to lp.services. |
19 |
print >> sys.stderr, "Expected a single argument." |
7675.507.33
by Edwin Grubbs
Addressed reviewer comments. |
20 |
print >> sys.stderr, usage() |
7675.507.30
by Edwin Grubbs
Added tests. Moved to lp.services. |
21 |
sys.exit(1) |
7675.507.16
by Edwin Grubbs
Refactored into spriteutils.py |
22 |
else: |
23 |
command = sys.argv[1] |
|
7675.507.30
by Edwin Grubbs
Added tests. Moved to lp.services. |
24 |
if command not in command_options: |
25 |
print >> sys.stderr, "Unknown argument: %s" % command |
|
7675.507.33
by Edwin Grubbs
Addressed reviewer comments. |
26 |
print >> sys.stderr, usage() |
7675.507.30
by Edwin Grubbs
Added tests. Moved to lp.services. |
27 |
sys.exit(2) |
7675.507.16
by Edwin Grubbs
Refactored into spriteutils.py |
28 |
|
10713.1.1
by Gary Poster
use new version of z3c.recipe.filetemplate and zc.buildout fork to use relative paths. |
29 |
icing = ${buildout:directory/lib/canonical/launchpad/icing|path-repr} |
7675.507.16
by Edwin Grubbs
Refactored into spriteutils.py |
30 |
combined_image_file = os.path.join(icing, 'icon-sprites') |
31 |
positioning_file = os.path.join(icing, 'icon-sprites.positioning') |
|
12622.4.1
by Curtis Hovey
Extracted sprite css to sprite.css. |
32 |
css_template_file = os.path.join(icing, 'sprite.css.in') |
33 |
css_file = os.path.join(icing, 'build/sprite.css') |
|
7675.507.16
by Edwin Grubbs
Refactored into spriteutils.py |
34 |
|
7675.507.29
by Edwin Grubbs
Added docstrings and moved more code into SpriteUtil.__init__(). |
35 |
sprite_util = SpriteUtil( |
7675.507.19
by Edwin Grubbs
More progress. |
36 |
css_template_file, 'icon-sprites', |
37 |
url_prefix_substitutions={'/@@/': '../images/'}) |
|
7675.507.16
by Edwin Grubbs
Refactored into spriteutils.py |
38 |
|
39 |
if command == 'create-image': |
|
7675.507.19
by Edwin Grubbs
More progress. |
40 |
sprite_util.combineImages(icing) |
7675.507.16
by Edwin Grubbs
Refactored into spriteutils.py |
41 |
sprite_util.savePNG(combined_image_file) |
42 |
sprite_util.savePositioning(positioning_file) |
|
43 |
elif command == 'create-css': |
|
44 |
sprite_util.loadPositioning(positioning_file) |
|
7675.507.33
by Edwin Grubbs
Addressed reviewer comments. |
45 |
# The icing/icon-sprites file is relative to the css file
|
46 |
# in the icing/build/ directory.
|
|
7675.507.23
by Edwin Grubbs
Completely working. |
47 |
sprite_util.saveConvertedCSS(css_file, '../icon-sprites') |