From 4bbd093a5622451bfe5140e43dcc77a0bc692c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Fri, 15 Oct 2010 20:46:17 +0200 Subject: [PATCH] Added dedupestore "console script" --- .gitignore | 1 + dedupestore/helpers.py | 51 ++++++++++++++++++++++++++++++++++++++++++ setup.py | 12 ++++++---- 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 dedupestore/helpers.py diff --git a/.gitignore b/.gitignore index 898aef0f5..ff3743a60 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build +*.egg-info *.pyc *.pyo diff --git a/dedupestore/helpers.py b/dedupestore/helpers.py new file mode 100644 index 000000000..ea88efc66 --- /dev/null +++ b/dedupestore/helpers.py @@ -0,0 +1,51 @@ +import argparse +import re + + +class Location(object): + + loc_re = re.compile(r'^((?:(?P[^@]+)@)?(?P[^:]+):)?' + r'(?P[^:]*)(?:::(?P[^:]+))?$') + + def __init__(self, text): + loc = self.loc_re.match(text) + loc = loc and loc.groupdict() + if not loc: + raise ValueError + self.user = loc['user'] + self.host = loc['host'] + self.path = loc['path'] + if not self.host and not self.path: + raise ValueError + self.archive = loc['archive'] + + def __str__(self): + text = '' + if self.user: + text += '%s@' % self.user + if self.host: + text += '%s::' % self.host + if self.path: + text += self.path + if self.archive: + text += ':%s' % self.archive + return text + + def __repr__(self): + return "Location('%s')" % self + + +def location_validator(archive=None): + def validator(text): + try: + loc = Location(text) + except ValueError: + raise argparse.ArgumentTypeError('Invalid location format: "%s"' % text) + if archive is True and not loc.archive: + raise argparse.ArgumentTypeError('"%s": No archive specified' % text) + elif archive is False and loc.archive: + raise argparse.ArgumentTypeError('"%s" No archive can be specified' % text) + return loc + return validator + + diff --git a/setup.py b/setup.py index a7b021bab..4c789f6ba 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,17 @@ # -*- encoding: utf-8 *-* #!/usr/bin/env python -from distutils.core import setup, Extension +from setuptools import setup, Extension setup(name='Dedupestore', - version='1.0', - author='Jonas Borgström', + version='0.1', + author=u'Jonas Borgström', author_email='jonas@borgstrom.se', packages=['dedupestore'], ext_modules=[Extension('_speedups', ['dedupestore/_speedups.c'])], - ) + entry_points = { + 'console_scripts': [ + 'dedupestore = dedupestore.archiver:main', + ] + })