Skip to content
This repository has been archived by the owner on Jul 9, 2020. It is now read-only.

Commit

Permalink
Migrate to argparse
Browse files Browse the repository at this point in the history
  • Loading branch information
klen committed Mar 10, 2011
1 parent c65145f commit b123943
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 32 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## 2011-03-10 0.3.94
-------------------
* Migrate to argparse

## 2011-02-25 0.3.93
-------------------
* Fix js require regexp

## 2011-02-25 0.3.92
Expand Down
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from zetalibrary import VERSION, AUTHOR
from zetalibrary import version, AUTHOR


# If extensions (or modules to document with autodoc) are in another directory,
Expand Down Expand Up @@ -53,9 +53,9 @@
# built documents.
#
# The short X.Y version.
version = VERSION
version = version
# The full version, including alpha/beta/rc tags.
release = VERSION
release = version

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
11 changes: 8 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python
import os
from sys import version_info

from setuptools import setup, find_packages

from zetalibrary import VERSION, PROJECT, LICENSE
from zetalibrary import version, PROJECT, LICENSE


def read( fname ):
Expand All @@ -18,9 +19,13 @@ def read( fname ):
for filename in files:
PACKAGE_DATA.append("%s/%s" % ( root[len(PROJECT)+1:], filename ))

install_requires = [ 'scss' ]
if version_info < (2, 7):
install_requires.append('argparse')

META_DATA = dict(
name=PROJECT,
version=VERSION,
version=version,
license=LICENSE,
description=read('DESCRIPTION'),
long_description=read('README.rst'),
Expand Down Expand Up @@ -50,7 +55,7 @@ def read( fname ):
]
},

install_requires = [ 'scss' ]
install_requires = install_requires,
)

if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions zetalibrary/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python
import os.path

VERSION_INFO = (0, 3, 93)
version_info = (0, 3, 94)

__version__ = version = '.'.join(map(str, version_info))
__project__ = PROJECT = __name__
__version__ = VERSION = '.'.join(str(i) for i in VERSION_INFO)
__author__ = AUTHOR = "Kirill Klenov <horneds@gmail.com>"
__license__ = LICENSE = "GNU LGPL"

Expand Down
41 changes: 18 additions & 23 deletions zetalibrary/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import optparse
import argparse
import os.path
import sys

Expand Down Expand Up @@ -126,55 +126,50 @@ def test_file( filepath ):
def main():
""" Parse arguments.
"""
p = optparse.OptionParser(
usage="%prog [--prefix PREFIX] FILENAME or DIRNAME",
description="Parse file or dir, import css, js code and save with prefix.")
p = argparse.ArgumentParser(
description="Parse file or dir, import css, js code and save with prefix.")

p.add_option(
p.add_argument('source', help="filename or dirname")

p.add_argument(
'-p', '--prefix', default='_', dest='prefix',
help="Save result with prefix. Default is '_'.")

p.add_option(
'-f', '--format', dest='format',
help="Force use this format.")
p.add_argument(
'-f', '--format', dest='format', help="Force use this format.")

p.add_option(
p.add_argument(
'-n', '--no-comments', action='store_true', dest='no_comments',
help="Clear comments.")

p.add_option(
p.add_argument(
'-w', '--show-frameworks', action='store_true', dest='frameworks',
help="Show available frameworks.")

p.add_option(
p.add_argument(
'-z', '--show-blocks', action='store_true', dest='zeta',
help="Show available zeta blocks.")

options, args = p.parse_args()
args = p.parse_args()

if options.frameworks:
if args.frameworks:
for framework in get_frameworks():
sys.stdout.write('%s%s%s %s%s\n' % ( COLORS['okgreen'], framework[0], COLORS['endc'], framework[1], framework[2]))
sys.exit()

if options.zeta:
if args.zeta:
for block in get_blocks():
sys.stdout.write('%s%s%s%s\n' % ( COLORS['okgreen'], block[0], COLORS['endc'], block[1],))
sys.exit()

if len(args) != 1:
p.print_help(sys.stdout)
return

path = args[0]
try:
assert os.path.exists(path)
assert os.path.exists(args.source)
except AssertionError:
p.error("%s'%s' does not exist.%s" % (args[0], COLORS['fail'], COLORS['endc']))
p.error("%s'%s' does not exist.%s" % (args.source, COLORS['fail'], COLORS['endc']))

for path in route(path, options.prefix):
for path in route(args.source, args.prefix):
try:
linker = Linker(path, prefix=options.prefix, no_comments=options.no_comments, format=options.format)
linker = Linker(path, prefix=args.prefix, no_comments=args.no_comments, format=args.format)
linker.link()
except ZetaError, ex:
p.error("%s%s%s" % (ex, COLORS['fail'], COLORS['warning']))
2 changes: 1 addition & 1 deletion zetalibrary/tests/zeta/_main.css
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ Zeta is a static framework.


/* ============================== */
/* Zeta import: '/home/klen/Projects/github.com/zeta-library/zetalibrary/tests/zeta/test_helpers.scss' */
/* Zeta import: '/home/klen/Projects/zeta-library/zetalibrary/tests/zeta/test_helpers.scss' */
/* From: 'zeta://zeta.css' */
.test {
float: left;
Expand Down

0 comments on commit b123943

Please sign in to comment.