X-Git-Url: https://git.llucax.com/z.facultad/75.10/miklolife.git/blobdiff_plain/419f78898bac8d6ff8a228777b29a87ab5697686..b09a1b5d2559dd4da2f8460ddd4fe459fedba79e:/carpeta/scripts/clases2spec.py?ds=inline
diff --git a/carpeta/scripts/clases2spec.py b/carpeta/scripts/clases2spec.py
index 818d1dd..c6961b3 100755
--- a/carpeta/scripts/clases2spec.py
+++ b/carpeta/scripts/clases2spec.py
@@ -4,132 +4,290 @@
from xml.sax import saxutils
# Estados
-E_CLASS = 1
-E_CLASS_NAME = 2
-E_CLASS_COMMENT = 3
-E_ATTRS = 4
-E_ATTR = 5
-E_ATTR_NAME = 6
-E_ATTR_COMMENT = 7
-E_ATTR_TYPE = 8
-E_OPS = 9
-E_OP = 10
-E_OP_NAME = 11
-E_OP_COMMENT = 12
-E_OP_TYPE = 13
+E_CLASS = 1
+E_CLASS_NAME = 2
+E_CLASS_COMMENT = 3
+E_ATTRS = 4
+E_ATTR = 5
+E_ATTR_NAME = 6
+E_ATTR_COMMENT = 7
+E_ATTR_TYPE = 8
+E_OPS = 9
+E_OP = 10
+E_OP_NAME = 11
+E_OP_COMMENT = 12
+E_OP_TYPE = 13
+E_OP_PARAMS = 14
+E_OP_PARAM = 15
+E_OP_PARAM_NAME = 16
+E_OP_PARAM_COMMENT = 17
+E_OP_PARAM_TYPE = 18
# Caracteres a eliminar
STRIPCHARS = '#\t\n '
+DEBUG = 0
+
+def dprint(s):
+ if DEBUG: print >>sys.stderr, s.encode('iso-8859-1', 'replace')
+
class ObjFinder(saxutils.DefaultHandler):
def __init__(self):
self.estado = None
self.clases = []
self.curr = None
self.curr_attr = None
+ self.curr_op = None
+ self.curr_param = None
def startElement(self, name, attrs):
- #print " #### Start <%s %s>" % (name, dict(attrs))
if name == 'dia:object': # Comienzo de una clase
if attrs.get('type', None) == 'UML - Class':
self.curr = {}
self.estado = E_CLASS
+ dprint("E_CLASS (encontrado dia:object)")
elif name == 'dia:attribute':
name = attrs.get('name', None)
if self.estado == E_CLASS: # Datos de la clase
if name == 'name': # Nombre de la clase
self.curr['name'] = ''
self.estado = E_CLASS_NAME
+ dprint("E_CLASS -> E_CLASS_NAME (encontrado dia:attribute con name)")
elif name == 'comment': # Es la descripción de la clase
self.curr['comment'] = ''
self.estado = E_CLASS_COMMENT
- elif name == 'attributes': # Paso empezó a encontrar atributos
+ dprint("E_CLASS -> E_CLASS_COMMENT (encontrado dia:attribute con comment)")
+ elif name == 'attributes': # Paso a encontrar atributos
self.curr['attrs'] = []
self.estado = E_ATTRS
- elif name == 'operations': # Paso empezó a encontrar operaciones
+ dprint("E_CLASS -> E_ATTRS (encontrado dia:attribute con attributes)")
+ elif name == 'operations': # Paso a encontrar operaciones
self.curr['ops'] = []
self.estado = E_OPS
+ dprint("E_CLASS -> E_OPS (encontrado dia:attribute con operations)")
elif self.estado == E_ATTR: # Datos del atributo
if name == 'name': # Nombre del atributo
self.curr_attr['name'] = ''
self.estado = E_ATTR_NAME
+ dprint("E_ATTR -> E_ATTR_NAME (encontrado dia:attribute con name)")
elif name == 'type': # Es el tipo del atributo
self.curr_attr['type'] = ''
self.estado = E_ATTR_TYPE
+ dprint("E_ATTR -> E_ATTR_TYPE (encontrado dia:attribute con type)")
elif name == 'comment': # Es la descripción del atributo
self.curr_attr['comment'] = ''
self.estado = E_ATTR_COMMENT
+ dprint("E_ATTR -> E_ATTR_COMMENT (encontrado dia:attribute con comment)")
elif self.estado == E_OP: # Datos del atributo
if name == 'name': # Nombre del atributo
self.curr_op['name'] = ''
self.estado = E_OP_NAME
+ dprint("E_OP -> E_OP_NAME (encontrado dia:attribute con name)")
elif name == 'type': # Es el tipo del atributo
self.curr_op['type'] = ''
self.estado = E_OP_TYPE
+ dprint("E_OP -> E_OP_TYPE (encontrado dia:attribute con type)")
elif name == 'comment': # Es la descripción del atributo
self.curr_op['comment'] = ''
self.estado = E_OP_COMMENT
- elif name == 'dia:composite': # Comienzo de attributos de clase
- if self.estado == E_ATTRS: # Si estoy en una clase
+ dprint("E_OP -> E_OP_COMMENT (encontrado dia:attribute con comment)")
+ elif name == 'parameters': # Paso a encontrar parámetros de operaciones
+ self.curr_op['params'] = []
+ self.estado = E_OP_PARAMS
+ dprint("E_OP -> E_OP_PARAMS (encontrado dia:attribute con parameters)")
+ elif self.estado == E_OP_PARAM: # Datos del parametro
+ if name == 'name': # Nombre del parametro
+ self.curr_param['name'] = ''
+ self.estado = E_OP_PARAM_NAME
+ dprint("E_OP_PARAM -> E_OP_PARAM_NAME (encontrado dia:attribute con name)")
+ elif name == 'type': # Es el tipo del parametro
+ self.curr_param['type'] = ''
+ self.estado = E_OP_PARAM_TYPE
+ dprint("E_OP_PARAM -> E_OP_PARAM_TYPE (encontrado dia:attribute con type)")
+ elif name == 'comment': # Es la descripción del parametro
+ self.curr_param['comment'] = ''
+ self.estado = E_OP_PARAM_COMMENT
+ dprint("E_OP_PARAM -> E_OP_PARAM_COMMENT (encontrado dia:attribute con comment)")
+ elif name == 'dia:composite': # Comienza composite
+ if self.estado == E_ATTRS: # Si estoy en atributos
self.curr_attr = {}
- self.estado = E_ATTR # Paso a buscar sus operaciones
- elif self.estado == E_OPS: # Si estoy en una clase
+ self.estado = E_ATTR # Paso a buscar sus atributos
+ dprint("E_ATTRS -> E_ATTR (encontrado dia:composite)")
+ elif self.estado == E_OPS: # Si estoy en operaciones
self.curr_op = {}
- self.estado = E_OP # Paso a buscar sus atributos
+ self.estado = E_OP # Paso a buscar sus operaciones
+ dprint("E_OPS -> E_OP (encontrado dia:composite)")
+ elif self.estado == E_OP_PARAMS: # Si estoy en parametros de operaciones
+ self.curr_param = {}
+ self.estado = E_OP_PARAM # Paso a buscar sus parametros
+ dprint("E_OP_PARAMS -> E_OP_PARAM (encontrado dia:composite)")
def characters(self, data):
if self.estado == E_CLASS_NAME:
self.curr['name'] += data.strip(STRIPCHARS)
+ dprint("E_CLASS_NAME: %s" % data.strip(STRIPCHARS))
elif self.estado == E_CLASS_COMMENT:
self.curr['comment'] += data.strip(STRIPCHARS)
+ dprint("E_CLASS_COMMENT: %s" % data.strip(STRIPCHARS))
elif self.estado == E_ATTR_NAME:
self.curr_attr['name'] += data.strip(STRIPCHARS)
+ dprint("E_ATTR_NAME: %s" % data.strip(STRIPCHARS))
elif self.estado == E_ATTR_TYPE:
self.curr_attr['type'] += data.strip(STRIPCHARS)
+ dprint("E_ATTR_TYPE: %s" % data.strip(STRIPCHARS))
elif self.estado == E_ATTR_COMMENT:
self.curr_attr['comment'] += data.strip(STRIPCHARS)
+ dprint("E_ATTR_COMMENT: %s" % data.strip(STRIPCHARS))
elif self.estado == E_OP_NAME:
self.curr_op['name'] += data.strip(STRIPCHARS)
+ dprint("E_OP_NAME: %s" % data.strip(STRIPCHARS))
elif self.estado == E_OP_TYPE:
self.curr_op['type'] += data.strip(STRIPCHARS)
+ dprint("E_OP_TYPE: %s" % data.strip(STRIPCHARS))
elif self.estado == E_OP_COMMENT:
self.curr_op['comment'] += data.strip(STRIPCHARS)
+ dprint("E_OP_COMMENT: %s" % data.strip(STRIPCHARS))
+ elif self.estado == E_OP_PARAM_NAME:
+ self.curr_param['name'] += data.strip(STRIPCHARS)
+ dprint("E_OP_PARAM_NAME: %s" % data.strip(STRIPCHARS))
+ elif self.estado == E_OP_PARAM_TYPE:
+ self.curr_param['type'] += data.strip(STRIPCHARS)
+ dprint("E_OP_PARAM_TYPE: %s" % data.strip(STRIPCHARS))
+ elif self.estado == E_OP_PARAM_COMMENT:
+ self.curr_param['comment'] += data.strip(STRIPCHARS)
+ dprint("E_OP_PARAM_COMMENT: %s" % data.strip(STRIPCHARS))
def endElement(self, name):
- #print " #### Endt %s>" % name
if name == 'dia:object':
if self.estado == E_CLASS:
self.clases.append(self.curr)
self.estado = None
self.curr = None
+ dprint("E_CLASS -> None")
elif name == 'dia:attribute':
if self.estado == E_CLASS_NAME:
self.estado = E_CLASS
+ dprint("E_CLASS_NAME -> E_CLASS")
elif self.estado == E_CLASS_COMMENT:
self.estado = E_CLASS
+ dprint("E_CLASS_COMMENT -> E_CLASS")
elif self.estado == E_ATTR_NAME:
self.estado = E_ATTR
+ dprint("E_ATTR_NAME -> E_ATTR")
elif self.estado == E_ATTR_TYPE:
self.estado = E_ATTR
+ dprint("E_ATTR_TYPE -> E_ATTR")
elif self.estado == E_ATTR_COMMENT:
self.estado = E_ATTR
+ dprint("E_ATTR_COMMENT -> E_ATTR")
elif self.estado == E_ATTRS:
self.estado = E_CLASS
+ dprint("E_ATTRS -> E_CLASS")
elif self.estado == E_OP_NAME:
self.estado = E_OP
+ dprint("E_OP_NAME -> E_OP")
elif self.estado == E_OP_TYPE:
self.estado = E_OP
+ dprint("E_OP_TYPE -> E_OP")
elif self.estado == E_OP_COMMENT:
self.estado = E_OP
+ dprint("E_OP_COMMENT -> E_OP")
elif self.estado == E_OPS:
self.estado = E_CLASS
+ dprint("E_OPS -> E_CLASS")
+ elif self.estado == E_OP_PARAM_NAME:
+ self.estado = E_OP_PARAM
+ dprint("E_OP_PARAM_NAME -> E_OP_PARAM")
+ elif self.estado == E_OP_PARAM_TYPE:
+ self.estado = E_OP_PARAM
+ dprint("E_OP_PARAM_TYPE -> E_OP_PARAM")
+ elif self.estado == E_OP_PARAM_COMMENT:
+ self.estado = E_OP_PARAM
+ dprint("E_OP_PARAM_COMMENT -> E_OP_PARAM")
+ elif self.estado == E_OP_PARAMS:
+ self.estado = E_OP
+ dprint("E_OP_PARAMS -> E_OP")
elif name == 'dia:composite':
if self.estado == E_ATTR:
self.curr['attrs'].append(self.curr_attr)
self.curr_attr = None
self.estado = E_ATTRS
+ dprint("E_ATTR -> E_ATTRS")
elif self.estado == E_OP:
self.curr['ops'].append(self.curr_op)
self.curr_op = None
self.estado = E_OPS
+ dprint("E_OP -> E_OPS")
+ elif self.estado == E_OP_PARAM:
+ self.curr_op['params'].append(self.curr_param)
+ self.curr_param = None
+ self.estado = E_OP_PARAMS
+ dprint("E_OP_PARAM -> E_OP_PARAMS")
+
+def param2str(params):
+ ret = []
+ for p in params:
+ ret.append('%s: %s' \
+ % (p['name'].encode('iso-8859-1', 'replace'),
+ p['type'].encode('iso-8859-1', 'replace')))
+ return ', '.join(ret)
+
+def to_text(clases):
+ # Recorro clases
+ for c in clases:
+ print c['name'].encode('iso-8859-1', 'replace')
+ print c['comment'].encode('iso-8859-1', 'replace')
+ print 'Atributo\tTipo\tDescripción'
+ for a in c['attrs']:
+ print '%s\t%s\t%s' \
+ % (a['name'].encode('iso-8859-1', 'replace'),
+ a['type'].encode('iso-8859-1', 'replace'),
+ a['comment'].encode('iso-8859-1', 'replace'))
+ if metodos and c['ops']:
+ for o in c['ops']:
+ print 'Método %s(%s): %s' \
+ % (o['name'].encode('iso-8859-1', 'replace'),
+ param2str(o['params']),
+ o['type'].encode('iso-8859-1', 'replace'))
+ print o['comment'].encode('iso-8859-1', 'replace')
+ if o['params']:
+ print 'Parámetro\tTipo\tDescripción'
+ for p in o['params']:
+ print '%s\t%s\t%s' \
+ % (p['name'].encode('iso-8859-1', 'replace'),
+ p['type'].encode('iso-8859-1', 'replace'),
+ p['comment'].encode('iso-8859-1', 'replace'))
+def to_html(clases):
+ print ''
+ print '
Especificación'
+ # Recorro clases obtenidas
+ for c in dh.clases:
+ print '' \
+ % c['name'].encode('iso-8859-1', 'replace')
+ print '%s |
' % c['name'].encode('iso-8859-1', 'replace')
+ print '%s |
' % c['comment'].encode('iso-8859-1', 'replace')
+ print 'Atributo | Tipo | Descripción |
'
+ for a in c['attrs']:
+ print '%s | %s | %s |
' \
+ % (a['name'].encode('iso-8859-1', 'replace'),
+ a['type'].encode('iso-8859-1', 'replace'),
+ a['comment'].encode('iso-8859-1', 'replace'))
+ if metodos and c['ops']:
+ for o in c['ops']:
+ print 'Método |
'
+ print '%s(%s): %s |
' \
+ % (o['name'].encode('iso-8859-1', 'replace'),
+ param2str(o['params']),
+ o['type'].encode('iso-8859-1', 'replace'))
+ print '%s |
' % \
+ o['comment'].encode('iso-8859-1', 'replace')
+ if o['params']:
+ print 'Parámetro | Tipo | Descripción |
'
+ for p in o['params']:
+ print '%s | %s | %s |
' \
+ % (p['name'].encode('iso-8859-1', 'replace'),
+ p['type'].encode('iso-8859-1', 'replace'),
+ p['comment'].encode('iso-8859-1', 'replace'))
+ print '
'
+ print ''
if __name__ == '__main__':
import sys
@@ -162,29 +320,8 @@ if __name__ == '__main__':
if len(sys.argv) > 2 and sys.argv[2] == '-n':
metodos = False
- print ''
- print 'Especificación'
- # Recorro clases obtenidas
- for c in dh.clases:
- print '' \
- % c['name'].encode('iso-8859-1', 'replace')
- print '%s |
' % c['name'].encode('iso-8859-1', 'replace')
- print '%s |
' % c['comment'].encode('iso-8859-1', 'replace')
- print 'Atributo | Tipo | Descripción |
'
- for a in c['attrs']:
- print '%s | %s | %s |
' \
- % (a['name'].encode('iso-8859-1', 'replace'),
- a['type'].encode('iso-8859-1', 'replace'),
- a['comment'].encode('iso-8859-1', 'replace'))
- if metodos:
- print 'Método | Retorno | Descripción |
'
- for o in c['ops']:
- print '%s | %s | %s |
' \
- % (o['name'].encode('iso-8859-1', 'replace'),
- o['type'].encode('iso-8859-1', 'replace'),
- o['comment'].encode('iso-8859-1', 'replace'))
- print '
'
- print ''
-
+ # Imprimo como txt feo para convertir a RTF
+ to_text(dh.clases)
+ #to_html(dh.clases)
# vim: set et sw=4 sts=4 :