Beispiel #1
0
    def read(self, reload):
        global _hierarchy

        if _hierarchy is None or reload:
            if os.path.exists(self._path):
                with open(self._path) as f:
                    _hierarchy = Hierachy.from_xml(f.read())
                logging.info(
                    f'Read hierarchy. Elements number: {len(_hierarchy)}')
            else:
                _hierarchy = Hierachy()
                logging.info('Created new hierarchy')
        self.hierarchy = _hierarchy
Beispiel #2
0
def check(xml):
    with open(xml, 'r') as f:
        xml = f.read()
    xml1 = Hierachy.from_xml(xml).pretty_xml()
    xml2 = Hierachy.from_xml(xml1).pretty_xml()

    check = xml1 == xml2
    if check:
        click.echo('Everyting seems to be correct')
    else:
        click.echo(
            'Something is wrong. Perhaps the following can help', err=True
        )
        sys.stdout.writelines(
            difflib.unified_diff(xml1.splitlines(), xml2.splitlines())
        )
 def _on_action_merge(self):
     filename, _ = QFileDialog.getOpenFileName(
         self, "Open file", os.getcwd(), "XML files (*.xml)"
     )
     with open(filename, 'r') as f:
         xml = f.read()
     hierarchy = Hierachy.from_xml(xml)
     self._mgr.h.merge(hierarchy)
     self._update_tree()
Beispiel #4
0
def make_system_tables_hierarchy(admin_role, h=None):
    if h is None:
        h = Hierachy()
    parent = _parent_section(admin_role)
    h.append(parent)
    sql = _sql()
    user = _user_table()
    role = _roles_table()
    token = _token_table()

    h.append(sql)
    h.append(user)
    h.append(role)
    h.append(token)
    parent.children.append(sql.id)
    parent.children.append(user.id)
    parent.children.append(role.id)
    parent.children.append(token.id)
Beispiel #5
0
 def construct(self):
     h = Hierachy()
     parent = Section(accessRights=self._global_rights(),
                      name=stringcase.sentencecase(self._schema))
     h.append(parent)
     for table in self._tables.values():
         t = self._make_table(table)
         h.append(t)
         parent.children.append(t.id)
     h.set_tree()
     return h
Beispiel #6
0
def merge(target, source):
    with open(target, 'r') as f:
        xml = f.read()
    hierarchy = Hierachy.from_xml(xml)
    manager = HierachyManager(path=source)
    manager.h.merge(hierarchy)
Beispiel #7
0
 def drop(self):
     global _hierarchy
     _hierarchy = Hierachy()
     self.hierarchy = _hierarchy