1 #!/usr/bin/env python2.4
2 # -*- encoding: iso-8859-1 -*-
3 # vim: set et sw=4 sts=4 :
12 from sercom.sqlo 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
23 elif val == 'True': val = True
24 elif val == 'False': val = False
30 except ValueError: pass
35 conf, conn, log = sercom.init('dbq')
38 log.error('Faltan argumentos!')
42 # Argumentos interesantes
54 if sys.argv[3].isdigit():
55 oid = int(sys.argv[3])
61 if cmd in ('list', 'ls'):
63 objs = [eval(obj).get(oid, connection=conn)]
65 objs = eval(obj).selectBy(**args2dict(args, conn))
67 objs = eval(obj).select(connection=conn)
75 attr = eval('o.' + attr)
77 elif cmd in ('rm', 'remove', 'delete', 'del'):
79 objs = [eval(obj).get(oid, connection=conn)]
81 objs = eval(obj).selectBy(args2dict(args, conn))
85 elif cmd in ('set', 'update'):
87 objs = [eval(obj).get(oid, connection=conn)]
89 where = args[:args.index('--')]
90 args = args[args.index('--')+1:]
91 objs = eval(obj).selectBy(**args2dict(where, conn))
93 print 'Modificando:', o,
94 o.set(**args2dict(args, conn))
96 elif cmd in ('add', 'new', 'insert'):
97 o = eval(obj)(**args2dict(args, conn))
100 log.error('Comando incorrecto (%s)!', cmd)
104 log.error('Argumento inválido!')
107 except Exception, msg: