Python схема PlantUML отображается с нечетными символами - PullRequest
0 голосов
/ 07 февраля 2020

Я использую этот код python для создания диаграммы plantUML:

import codecs
import importlib.util
import os
from plantuml import PlantUML
import sadisplay
import tkinter.filedialog as filedialog
import tkinter.messagebox as messagebox

def create_erd():
    # Get the file with the models.
    modelFile = filedialog.askopenfilename(initialdir = os.getcwd, title = 'Select models.py file', filetypes = (('python files', '*.py'), ('all files', '*.*')))

    # Import the file as a module.
    spec = importlib.util.spec_from_file_location('models', modelFile)
    models = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(models)

    # Create a descriptor that lists all the attributes and relationships outlined in the models.py file.
    desc = sadisplay.describe([getattr(models, attr) for attr in dir(models)])

    # Create the plantuml file based on the descriptor.  This is needed to create the png image file
    with codecs.open('schema.plantuml', 'w', encoding='utf-8') as f:
        f.write(sadisplay.plantuml(desc))

    # Call the plantuml library to take the plantuml file and generate the png file.
    plantuml = PlantUML('http://www.plantuml.com/plantuml/img/')
    done = plantuml.processes_file(filename = 'schema.plantuml', outfile = 'schema.png')    

    # Notify the user if the process was successful.
    if done:
        messagebox.showinfo('Create ERD', 'The ERD was successfully written to schema.png.')
    else:
        messagebox.showinfo('Create ERD', 'The ERD was not successfully generated.')

Сгенерированный файл plantuml выглядит следующим образом:

@startuml

skinparam defaultFontName Courier

Class Department {
    INTEGER ★ id     
    VARCHAR ⚪ name   
    +       employees
}

Class Employee {
    INTEGER  ★ id           
    INTEGER  ☆ department_id
    INTEGER  ☆ role_id      
    DATETIME ⚪ hired_on     
    VARCHAR  ⚪ name         
    +        department     
    +        role           
}

Class Role {
    INTEGER ★ role_id
    VARCHAR ⚪ name   
    +       roles    
}

Employee <--o Department: department_id

Employee <--o Role: role_id

right footer generated by sadisplay v0.4.9

@enduml

Но вывод выглядит так :

enter image description here

Я не уверен, почему изображение отображается таким образом, и поэтому не знаю, как его исправить или можно ли его исправить. Есть идеи?

1 Ответ

0 голосов
/ 07 февраля 2020

В итоге я прочитал в файле uml и заменил символы:

processThis = uml.read().replace('★', '[PK]').replace('☆', '[FK]').replace('⚪', '    ')

Это сработало.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...