1 #!/usr/bin/env python2.4
2 # -*- encoding: iso-8859-1 -*-
3 # vim: set et sw=4 sts=4 :
13 from sercom.dbo import *
17 %s objeto comando [opciones]''' % sys.argv[0]
19 def args2dict(l, conn):
20 d = {'connection': conn}
22 key, val = arg.split('=')
27 print >>sys.stderr, 'Faltan argumentos!'
28 print >>sys.stderr, ayuda()
32 locale.setlocale(locale.LC_ALL, '')
34 # Obtengo configuración
35 conf = ConfigParser.SafeConfigParser()
36 if not conf.read(('/etc/sercom/sercom.ini', os.path.expanduser('~/.sercom/sercom.ini'), 'sercom.ini')):
37 sys.stderr.write('No se pudo obtener configuración!\n')
41 conn = sqlobject.connectionForURI(conf.get('dbo', 'database'))
43 # Argumentos interesantes
49 if sys.argv[3].isdigit():
50 oid = int(sys.argv[3])
56 if cmd in ('list', 'ls'):
58 objs = [eval(obj).get(oid, connection=conn)]
60 objs = eval(obj).selectBy(**args2dict(args, conn))
62 objs = eval(obj).select(connection=conn)
65 elif cmd in ('rm', 'remove', 'delete', 'del'):
67 objs = [eval(obj).get(oid, connection=conn)]
69 objs = eval(obj).selectBy(args2dict(args, conn))
73 elif cmd in ('set', 'update'):
75 objs = [eval(obj).get(oid, connection=conn)]
77 where = args[:args.index('--')]
78 args = args[args.index('--')+1:]
79 objs = eval(obj).selectBy(**args2dict(where, conn))
81 print 'Modificando:', o,
82 o.set(**args2dict(args))
84 elif cmd in ('add', 'new', 'insert'):
85 o = eval(obj)(**args2dict(args, conn))
88 print >>sys.stderr, 'Comando incorrecto (%s)!' % cmd
89 print >>sys.stderr, ayuda()
92 print >>sys.stderr, 'Argumento inválido!'
93 print >>sys.stderr, ayuda()
95 except Exception, msg:
96 print >>sys.stderr, 'ERROR:', msg