#!/usr/bin/python import argparse import os.path import os parser = argparse.ArgumentParser() parser.add_argument("-n", "--new", action="store_true") parser.add_argument("-r", "--read", action="store_true") parser.add_argument("-l", "--list", action="store_true") parser.add_argument("name", action="store", nargs='?') args = parser.parse_args() GPG = "/usr/bin/gpg" base = os.path.join(os.environ.get("HOME"), "Dropbox", "secure_notes") print base import subprocess class Menu(object): def __init__(self, choices): self.choices = sorted(choices) def choose(self, choice): choice = int(choice) return self.choices[choice-1] def __str__(self): return '\n'.join('%4d) %s' % x for x in enumerate(self.choices, 1)) if args.new: print args.name proc = subprocess.call([GPG, "-r", "Fiddlerwoaroof ", "-o", os.path.join(base, args.name), "-e"]) elif args.read: print args.name if args.name is None: menu = Menu(os.listdir(base)) print menu choice = raw_input('choice? ').strip() if choice.isdigit(): args.name = menu.choose(choice) proc = subprocess.call([GPG, "-r", "Fiddlerwoaroof ", "-d", os.path.join(base, args.name)]) elif args.list: files = os.listdir(base) max_itm = max(len(x) for x in files) for x in range(len(files)/3 + 1): items = files[x*3:(x+1)*3] print ' '.join(item.ljust(max_itm+3) for item in items)