1359b622 |
#!/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")
|
a0d71cd9 |
parser.add_argument("-l", "--list", action="store_true")
parser.add_argument("name", action="store", nargs='?')
|
1359b622 |
args = parser.parse_args()
GPG = "/usr/bin/gpg"
base = os.path.join(os.environ.get("HOME"), "Dropbox", "secure_notes")
print base
import subprocess
|
907e4c93 |
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))
|
1359b622 |
if args.new:
|
a0d71cd9 |
print args.name
proc = subprocess.call([GPG, "-r", "Fiddlerwoaroof <fiddler.wo.a.roof@gmail.com>", "-o", os.path.join(base, args.name), "-e"])
|
1359b622 |
elif args.read:
|
a0d71cd9 |
print args.name
|
907e4c93 |
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)
|
a0d71cd9 |
proc = subprocess.call([GPG, "-r", "Fiddlerwoaroof <fiddler.wo.a.roof@gmail.com>", "-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]
|
e5360584 |
print ' '.join(item.ljust(max_itm+3) for item in items)
|