Mercurial > hg > decoupage
changeset 93:bdb9e39abd84
make a proper python script for discovery and extension
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 21 Aug 2016 19:27:10 -0700 |
parents | c5895d87c65e |
children | 50dafcaa588d |
files | create_index_ini.sh decoupage/create_index.py setup.py |
diffstat | 3 files changed, 47 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/create_index_ini.sh Sat Dec 27 10:49:58 2014 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -#!/bin/bash - -# create index.ini file from directory listings -# TODO: -> python - -ls -1 | while read line; do echo "${line} = ${line}"; done > index.ini
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/decoupage/create_index.py Sun Aug 21 19:27:10 2016 -0700 @@ -0,0 +1,46 @@ +#!/usr/bin/env python + +""" +create index.ini file from directory listings +""" + +#ls -1 | while read line; do echo "${line} = ${line}"; done > index.ini + +# imports +import argparse +import os +import sys + + +class CreateIndex(object): + """ + decoupage directory index .ini creation + """ + # TODO: maybe this should inherit or otherwise extend + # some more abstract Index class + + def __init__(self, directory): + assert os.path.isdir(directory) + self.directory = directory + + def __str__(self): + lines = ['{item}={item}'.format(item=item) + for item in sorted(os.listdir(self.directory))] + return '\n'.join(lines) + '\n' + + +def main(args=sys.argv[1:]): + """CLI""" + + # parse command line + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('-d', '--directory', + default=os.getcwd(), + help="directory to create index for (current working directory by default)") + options = parser.parse_args(args) + + print CreateIndex(options.directory) + + +if __name__ == '__main__': + main()
--- a/setup.py Sat Dec 27 10:49:58 2014 -0800 +++ b/setup.py Sun Aug 21 19:27:10 2016 -0700 @@ -32,8 +32,8 @@ ], dependency_links=['http://www.dalkescientific.com/Python/PyRSS2Gen-1.0.0.tar.gz#egg=PyRSS2Gen'], entry_points=""" - # -*- Entry points: -*- [console_scripts] + create-decoupage-index = decoupage.create_index:main decoupage-templates = decoupage.templates:main decoupage-formatters = decoupage.formatters:main decoupage = decoupage.cli:main