Mercurial > hg > decoupage
diff decoupage/create_index.py @ 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 | create_index_ini.sh@55719bcdc2c2 |
children | 450aff4c97e3 |
line wrap: on
line diff
--- /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()