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 if val == 'True': val = True
24 if val == 'False': val = False
29 conf, conn, log = sercom.init('dbq')
32 log.error('Faltan argumentos!')
36 # Argumentos interesantes
48 if sys.argv[3].isdigit():
49 oid = int(sys.argv[3])
55 if cmd in ('list', 'ls'):
57 objs = [eval(obj).get(oid, connection=conn)]
59 objs = eval(obj).selectBy(**args2dict(args, conn))
61 objs = eval(obj).select(connection=conn)
69 attr = eval('o.' + attr)
71 elif cmd in ('rm', 'remove', 'delete', 'del'):
73 objs = [eval(obj).get(oid, connection=conn)]
75 objs = eval(obj).selectBy(args2dict(args, conn))
79 elif cmd in ('set', 'update'):
81 objs = [eval(obj).get(oid, connection=conn)]
83 where = args[:args.index('--')]
84 args = args[args.index('--')+1:]
85 objs = eval(obj).selectBy(**args2dict(where, conn))
87 print 'Modificando:', o,
88 o.set(**args2dict(args, conn))
90 elif cmd in ('add', 'new', 'insert'):
91 o = eval(obj)(**args2dict(args, conn))
94 log.error('Comando incorrecto (%s)!', cmd)
98 log.error('Argumento inválido!')
101 except Exception, msg: