forked from shopwiki/pyxie
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding the pyxie script and some support for the pyxie script
- Loading branch information
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
"""pyxie command line tool""" | ||
|
||
import sys | ||
import glob | ||
import os | ||
import optparse | ||
from pyxie import sprite | ||
|
||
white, black, red, green, yellow, blue, purple = range(89, 96) | ||
def color(string, color=green, bold=True): | ||
return '\033[%s%sm' % ('01;' if bold else '', color) + str(string) + '\033[0m' | ||
|
||
def err(string): | ||
sys.stderr.write(color("Error:", red) + str(string)) | ||
sys.exit(-1) | ||
|
||
def main(): | ||
opts, args = parse_args() | ||
spritepath, paths = args[0], args[1:] | ||
s = sprite.sprite_from_paths(*paths) | ||
s.write(spritepath) | ||
if opts.css: | ||
open(opts.css, 'w').write(s.css()) | ||
else: | ||
print s.css() | ||
if opts.html: | ||
open(opts.html, 'w').write(s.html()) | ||
return 0 | ||
|
||
def parse_args(): | ||
parser = optparse.OptionParser(version='0.1', usage='%prog [opts] spritefile <images>') | ||
parser.set_conflict_handler("resolve") | ||
parser.add_option('-c', '--css', help='css output file (default stdout)') | ||
parser.add_option('', '--sprite-url', help='url to the sprite') | ||
parser.add_option('-h', '--html', help='html output file (default none)') | ||
# parser.add_option('', '--class-prefix', help='css class prefix') | ||
opts, args = parser.parse_args() | ||
if not args: | ||
err("You must provide a path for the sprite-file") | ||
if len(args) < 2: | ||
err("You can't make a sprite without images") | ||
return opts, args | ||
|
||
if __name__ == '__main__': | ||
try: | ||
sys.exit(main()) | ||
except KeyboardInterrupt: | ||
pass | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters