Use same print in all the printer classes
Use a single print method to print to the output stream instead of specifying it in every print command. Change-Id: Iba5ca966a64edd02725d764d12a6e93b571af692 Partial-Bug: #1734146
This commit is contained in:
parent
9d8146e54d
commit
7d56e9c7d9
|
@ -31,6 +31,9 @@ class ModelsPrinter(object):
|
||||||
def __init__(self, fh):
|
def __init__(self, fh):
|
||||||
self._output = fh
|
self._output = fh
|
||||||
|
|
||||||
|
def _print(self, *args, **kwargs):
|
||||||
|
print(*args, file=self._output, **kwargs)
|
||||||
|
|
||||||
def output_start(self):
|
def output_start(self):
|
||||||
"""
|
"""
|
||||||
Called once on the beginning of the processing.
|
Called once on the beginning of the processing.
|
||||||
|
@ -125,16 +128,16 @@ class PlaintextPrinter(ModelsPrinter):
|
||||||
super(PlaintextPrinter, self).__init__(fh)
|
super(PlaintextPrinter, self).__init__(fh)
|
||||||
|
|
||||||
def model_start(self, model_name):
|
def model_start(self, model_name):
|
||||||
print('-------------', file=self._output)
|
self._print('-------------')
|
||||||
print('{}'.format(model_name), file=self._output)
|
self._print('{}'.format(model_name))
|
||||||
print('-------------', file=self._output)
|
self._print('-------------')
|
||||||
|
|
||||||
def model_end(self, model_name):
|
def model_end(self, model_name):
|
||||||
print('', file=self._output)
|
self._print('')
|
||||||
|
|
||||||
def fields_start(self):
|
def fields_start(self):
|
||||||
print('Fields', file=self._output)
|
self._print('Fields')
|
||||||
print('------', file=self._output)
|
self._print('------')
|
||||||
|
|
||||||
def handle_field(self, field_name, field_type, is_required, is_embedded,
|
def handle_field(self, field_name, field_type, is_required, is_embedded,
|
||||||
is_single, restrictions):
|
is_single, restrictions):
|
||||||
|
@ -143,26 +146,26 @@ class PlaintextPrinter(ModelsPrinter):
|
||||||
name=field_name, type=field_type,
|
name=field_name, type=field_type,
|
||||||
restriction=restriction_str,
|
restriction=restriction_str,
|
||||||
required=', Required' if is_required else '',
|
required=', Required' if is_required else '',
|
||||||
to_many=', One' if is_single else ', Many',
|
to_many=', Multi' if not is_single else '',
|
||||||
embedded=', Embedded' if is_embedded else ''),
|
embedded=', Embedded' if is_embedded else ''))
|
||||||
file=self._output)
|
|
||||||
|
|
||||||
def indexes_start(self):
|
def indexes_start(self):
|
||||||
print('Indexes', file=self._output)
|
self._print('Indexes')
|
||||||
print('-------', file=self._output)
|
self._print('-------')
|
||||||
|
|
||||||
def handle_index(self, index_name):
|
def handle_index(self, index_name):
|
||||||
print('{}'.format(index_name), file=self._output)
|
self._print('{}'.format(index_name))
|
||||||
|
|
||||||
def events_start(self):
|
def events_start(self):
|
||||||
print('Events', file=self._output)
|
self._print('Events')
|
||||||
print('------', file=self._output)
|
self._print('------')
|
||||||
|
|
||||||
def handle_event(self, event_name):
|
def handle_event(self, event_name):
|
||||||
print('{}'.format(event_name), file=self._output)
|
self._print('{}'.format(event_name))
|
||||||
|
|
||||||
|
|
||||||
class UMLPrinter(ModelsPrinter):
|
class UMLPrinter(ModelsPrinter):
|
||||||
|
"""PlantUML format printer"""
|
||||||
def __init__(self, fh):
|
def __init__(self, fh):
|
||||||
super(UMLPrinter, self).__init__(fh)
|
super(UMLPrinter, self).__init__(fh)
|
||||||
self._model = ''
|
self._model = ''
|
||||||
|
@ -170,8 +173,8 @@ class UMLPrinter(ModelsPrinter):
|
||||||
self._dependencies = set()
|
self._dependencies = set()
|
||||||
|
|
||||||
def output_start(self):
|
def output_start(self):
|
||||||
print('@startuml', file=self._output)
|
self._print('@startuml')
|
||||||
print('hide circle', file=self._output)
|
self._print('hide circle')
|
||||||
|
|
||||||
def _output_relations(self):
|
def _output_relations(self):
|
||||||
for (dst, src, name, is_single, is_embedded) in self._dependencies:
|
for (dst, src, name, is_single, is_embedded) in self._dependencies:
|
||||||
|
@ -180,21 +183,20 @@ class UMLPrinter(ModelsPrinter):
|
||||||
connector_str = ' *-- ' if is_single else '"1" *-- "*"'
|
connector_str = ' *-- ' if is_single else '"1" *-- "*"'
|
||||||
else:
|
else:
|
||||||
connector_str = ' o-- ' if is_single else ' o-- "*"'
|
connector_str = ' o-- ' if is_single else ' o-- "*"'
|
||||||
print('{dest} {connector} {src} : {field_name}'.format(
|
self._print('{dest} {connector} {src} : {field_name}'.format(
|
||||||
dest=dst, connector=connector_str, src=src,
|
dest=dst, connector=connector_str, src=src,
|
||||||
field_name=name),
|
field_name=name))
|
||||||
file=self._output)
|
|
||||||
|
|
||||||
def output_end(self):
|
def output_end(self):
|
||||||
self._output_relations()
|
self._output_relations()
|
||||||
print('@enduml', file=self._output)
|
self._print('@enduml')
|
||||||
|
|
||||||
def model_start(self, model_name):
|
def model_start(self, model_name):
|
||||||
self._model = model_name
|
self._model = model_name
|
||||||
print('class {} {{'.format(model_name), file=self._output)
|
self._print('class {} {{'.format(model_name))
|
||||||
|
|
||||||
def model_end(self, model_name):
|
def model_end(self, model_name):
|
||||||
print('}', file=self._output)
|
self._print('}')
|
||||||
self._processed.add(model_name)
|
self._processed.add(model_name)
|
||||||
self._model = ''
|
self._model = ''
|
||||||
|
|
||||||
|
@ -202,23 +204,22 @@ class UMLPrinter(ModelsPrinter):
|
||||||
is_single, restrictions):
|
is_single, restrictions):
|
||||||
restriction_str = ' {}'.format(restrictions) if restrictions else ''
|
restriction_str = ' {}'.format(restrictions) if restrictions else ''
|
||||||
name = '<b>{}</b>'.format(field_name) if is_required else field_name
|
name = '<b>{}</b>'.format(field_name) if is_required else field_name
|
||||||
print(' +{name} : {type} {restriction}'.format(
|
self._print(' +{name} : {type} {restriction}'.format(
|
||||||
name=name, type=field_type, restriction=restriction_str),
|
name=name, type=field_type, restriction=restriction_str))
|
||||||
file=self._output)
|
|
||||||
self._dependencies.add((self._model, field_type, field_name,
|
self._dependencies.add((self._model, field_type, field_name,
|
||||||
is_single, is_embedded))
|
is_single, is_embedded))
|
||||||
|
|
||||||
def indexes_start(self):
|
def indexes_start(self):
|
||||||
print(' .. Indexes ..', file=self._output)
|
self._print(' .. Indexes ..')
|
||||||
|
|
||||||
def handle_index(self, index_name):
|
def handle_index(self, index_name):
|
||||||
print(' {}'.format(index_name), file=self._output)
|
self._print(' {}'.format(index_name))
|
||||||
|
|
||||||
def events_start(self):
|
def events_start(self):
|
||||||
print(' == Events ==', file=self._output)
|
self._print(' == Events ==')
|
||||||
|
|
||||||
def handle_event(self, event_name):
|
def handle_event(self, event_name):
|
||||||
print(' {}'.format(event_name), file=self._output)
|
self._print(' {}'.format(event_name))
|
||||||
|
|
||||||
|
|
||||||
class DfModelParser(object):
|
class DfModelParser(object):
|
||||||
|
|
Loading…
Reference in New Issue