#!/home/jcgregorio/bin/python2.5 import os, sys from model import model create_usage = """ The value of 'dname' is either a domain name or email address that the creator owns on this date. The database will be created with a URI template for the atom:id tag:dname,date:dir:{key} Where {key} is the database id for each atom entry stored. """ usage = """usage: ats [options] [args] AtomStore command-line client, version 1.0.0 ats list Print out a list of all the id's of the entrys in the store ats del Delete the entry with the given id from the store. ats get Get the entry with . Stores it in the local file with the same name as the id. ats put Update the collection with the entry in . ats post Adds the entry in to the collection. ats search Search for all entries that contain 'value' ats info Get info about the collection we are bound to. """ if sys.argv[0].find("draft") >= 0: collection = model.draft else: collection = model.entry class AtomStoreExp(Exception): def __init__(self, args=None): self.args = args def perror(s): raise AtomStoreExp, s def help(args): print usage def search_(args): if len(args) < 1: perror("Missing the keyword.") #index = store.search(args[0]) #for i in index: # print store.get(i['id']), "\f", def del_(args): if len(args) < 1: perror("Missing the entry id.") collection.delete(args[0]) print "ok" def list_(args): print "\n".join(collection.id_list()) def get(args): if len(args) < 1: perror("Missing the required argument , which is the id of the Entry to export, and the directory of the store.") id = args[0] if id in collection: if os.path.exists(id): perror("File with that name already exists") sys.exit(1) print collection.dir, id msg = collection._msg_from_dict(collection.get(id), id, remove_old_index=False) f = file(id, "w") f.write(msg) f.close() else: perror("No member with that id exists") def put(args): if len(args) < 1: perror("Missing the required arguments , which is the id of the Entry to export, and the directory of the store.") id = args[0] if not id in collection: perror("No member with that id exists") if not os.path.exists(id): perror("No file with that name exists") # The _get operates on a file name d = collection._get(id, False) collection.put(id, d) def create(args): if len(args) < 1: perror("Missing the required arguments , which is the id of the Entry to export, and the directory of the store.") filename = args[0] d = collection._get(filename, False) id = collection.create(d) print "Created entry with id = %s" % id def reindex(args): collection.reindex() commands = { 'create': create, 'help': help, 'get': get, 'put': put, 'search': search_, 'list': list_, 'del': del_, 'reindex': reindex, } if __name__ == "__main__": args = sys.argv[1:] if len(args) and ( args[0] in commands.keys()) : #try: commands[args[0]](args[1:]) #except Exception, val: # sys.stderr.write(str(val)) # sys.stderr.write("\n") # sys.exit(1) else: commands['help'](args)