Beispiel #1
0
    def save(self, project):
        if project is None:
            return False

        globals.generalSignals.preSave.emit()

        # saving trees
        self.__tree_parser.save(project.alphabet, project.trees, project.nodes,
                                project.tree_paths)

        # saving libraries
        if globals.saveLibraries:
            self.__lib_parser.save(project.alphabet, project.libraries)
        else:
            print('info: Libraries would not be saved. Set attribute \'saveLibs\' to \'yes\' ' \
                  'in Your config file to enable libraries saving.')

        # main xml document
        doc = Document()

        # add main xml tag inside document
        main = doc.createElement('btproject')
        main.setAttribute('name', project.name)
        doc.appendChild(main)

        alphabetTag = doc.createElement('alphabet')
        alphabetTag.setAttribute(
            'path', relativePath(project.alphabet.path, project.path))
        main.appendChild(alphabetTag)

        if project.shapelib is not None:
            if os.path.exists(project.shapelib.path):
                shp = doc.createElement('shapelib')
                path = relativePath(project.shapelib.path, project.path)
                shp.setAttribute('path', path)
                main.appendChild(shp)

        for l in project.lib_paths:
            if os.path.exists(l):
                lib = doc.createElement('library')
                path = relativePath(l, project.path)
                lib.setAttribute('path', path)
                main.appendChild(lib)

        for t in project.tree_paths:
            if os.path.exists(t):
                bt = doc.createElement('behavior_tree')
                path = relativePath(t, project.path)
                bt.setAttribute('path', path)
                main.appendChild(bt)

        # saving xml document to file
        f = open(project.path, 'w')
        if f is not None:
            f.write(doc.toprettyxml())
            f.close()

        project.modified = False

        return True
Beispiel #2
0
    def save(self, project):
        if project is None:
            return False

        globals.generalSignals.preSave.emit()

        # saving trees
        self.__tree_parser.save(project.alphabet, project.trees, project.nodes, project.tree_paths)

        # saving libraries
        if globals.saveLibraries:
            self.__lib_parser.save(project.alphabet, project.libraries)
        else:
            print('info: Libraries would not be saved. Set attribute \'saveLibs\' to \'yes\' ' \
                  'in Your config file to enable libraries saving.')

        # main xml document
        doc = Document()

        # add main xml tag inside document
        main = doc.createElement('btproject')
        main.setAttribute('name', project.name)
        doc.appendChild(main)

        alphabetTag = doc.createElement('alphabet')
        alphabetTag.setAttribute('path', relativePath(project.alphabet.path, project.path))
        main.appendChild(alphabetTag)

        if project.shapelib is not None:
            if os.path.exists(project.shapelib.path):
                shp = doc.createElement('shapelib')
                path = relativePath(project.shapelib.path, project.path)
                shp.setAttribute('path', path)
                main.appendChild(shp)

        for l in project.lib_paths:
            if os.path.exists(l):
                lib = doc.createElement('library')
                path = relativePath(l, project.path)
                lib.setAttribute('path', path)
                main.appendChild(lib)

        for t in project.tree_paths:
            if os.path.exists(t):
                bt = doc.createElement('behavior_tree')
                path = relativePath(t, project.path)
                bt.setAttribute('path', path)
                main.appendChild(bt)

        # saving xml document to file
        f = open(project.path, 'w')
        if f is not None:
            f.write(doc.toprettyxml())
            f.close()

        project.modified = False

        return True
Beispiel #3
0
    def __getPathStr(self, _path, proj_path):
        path = relativePath(_path, proj_path)  # getting relative path
        if path is None or not path:
            return tuple()

        temp = os.path.join(os.path.dirname(proj_path), path)  # getting full path
        temp = toUnixPath(os.path.normpath(temp))
        if not os.path.exists(temp):
            return tuple([temp])

        path = toUnixPath(path)
        temp = toUnixPath(temp)

        return tuple([path, temp])
Beispiel #4
0
    def __getPathStr(self, _path, proj_path):
        path = relativePath(_path, proj_path)  # getting relative path
        if path is None or not path:
            return tuple()

        temp = os.path.join(os.path.dirname(proj_path),
                            path)  # getting full path
        temp = toUnixPath(os.path.normpath(temp))
        if not os.path.exists(temp):
            return tuple([temp])

        path = toUnixPath(path)
        temp = toUnixPath(temp)

        return tuple([path, temp])
Beispiel #5
0
    def __getPath(self, xml_node, proj_path):
        path = xml_node.getAttribute('path')
        path = relativePath(path, proj_path)  # getting relative path
        if path is None or not path:
            return tuple()

        temp = os.path.join(os.path.dirname(proj_path), path)  # getting full path
        temp = os.path.normpath(temp)
        if not os.path.exists(temp):
            return tuple([temp])

        path = toUnixPath(path)
        temp = toUnixPath(temp)

        return tuple([path, temp])