diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..11041c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.egg-info diff --git a/flickrscripts/__init__.py b/flickrscripts/__init__.py new file mode 100644 index 0000000..68d857f --- /dev/null +++ b/flickrscripts/__init__.py @@ -0,0 +1,29 @@ +from __future__ import print_function + +import sys +from os.path import basename + + +__meta__ = dict( + name='flickrscripts', + version='0.1.0', + entry_points={ + 'console_scripts': [ + 'flickrscripts = flickrscripts:route', + ], + }, +) +USAGE = 'Usage: {prog} [args]' + + +def route(sysargs=sys.argv[:]): + try: + subcommand = sysargs.pop(1) + import_name = 'flickrscripts.{}'.format(subcommand) + + module = __import__(import_name, fromlist=[import_name]) + return module.main(sysargs) + except IndexError: + print(USAGE.format(prog=basename(sysargs[0])), file=sys.stderr) + print('You must provide a subcommand', file=sys.stderr) + return 1 diff --git a/flickrscripts.py b/flickrscripts/common.py similarity index 100% rename from flickrscripts.py rename to flickrscripts/common.py diff --git a/timewarp.py b/flickrscripts/timewarp.py similarity index 93% rename from timewarp.py rename to flickrscripts/timewarp.py index 901e782..b76e094 100644 --- a/timewarp.py +++ b/flickrscripts/timewarp.py @@ -5,7 +5,7 @@ import sys from datetime import datetime, timedelta from os.path import expanduser -from flickrscripts import setup_flickr +from flickrscripts.common import setup_flickr class TimeWarper(object): @@ -32,7 +32,7 @@ class TimeWarper(object): return 0 def _set_upload_date_for_photos(self, pagenum, page, set_to_date): - for i, photo in enumerate(page.findall('photos/photo'): + for i, photo in enumerate(page.findall('photos/photo')): setdate_response = self.flickr.photos_setDates( photo_id=photo.attrib['id'], date_posted=set_to_date @@ -54,7 +54,8 @@ class TimeWarper(object): def main(sysargs=sys.argv[:]): parser = argparse.ArgumentParser( - formatter_class=argparse.ArgumentDefaultsHelpFormatter) + formatter_class=argparse.ArgumentDefaultsHelpFormatter, + prog='flickrscripts timewarp') parser.add_argument('set_to_date') parser.add_argument('-q', '--search-query-param', default=[], action='append', help='Add a key=value param to the search query list') diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..84b1a72 --- /dev/null +++ b/setup.py @@ -0,0 +1,10 @@ +import sys + +from setuptools import setup + +from flickrscripts import __meta__ + + +if __name__ == '__main__': + setup(**__meta__) + sys.exit(0)