1 #!/usr/bin/env python2.4
2 # -*- encoding: iso-8859-1 -*-
3 # vim: set et sw=4 sts=4 :
12 from sercom.dbo import *
16 %s objeto comando [opciones]''' % sys.argv[0]
18 def args2dict(l, conn):
19 d = {'connection': conn}
21 key, val = arg.split('=')
22 if val == 'None': val = None
27 conf, conn, log = sercom.init('dbq')
30 log.error('Faltan argumentos!')
34 # Argumentos interesantes
46 if sys.argv[3].isdigit():
47 oid = int(sys.argv[3])
53 if cmd in ('list', 'ls'):
55 objs = [eval(obj).get(oid, connection=conn)]
57 objs = eval(obj).selectBy(**args2dict(args, conn))
59 objs = eval(obj).select(connection=conn)
67 attr = eval('o.' + attr)
69 elif cmd in ('rm', 'remove', 'delete', 'del'):
71 objs = [eval(obj).get(oid, connection=conn)]
73 objs = eval(obj).selectBy(args2dict(args, conn))
77 elif cmd in ('set', 'update'):
79 objs = [eval(obj).get(oid, connection=conn)]
81 where = args[:args.index('--')]
82 args = args[args.index('--')+1:]
83 objs = eval(obj).selectBy(**args2dict(where, conn))
85 print 'Modificando:', o,
86 o.set(**args2dict(args, conn))
88 elif cmd in ('add', 'new', 'insert'):
89 o = eval(obj)(**args2dict(args, conn))
92 log.error('Comando incorrecto (%s)!', cmd)
96 log.error('Argumento inválido!')
99 except Exception, msg: