コード例 #1
0
ファイル: dbbase.py プロジェクト: dwfreed/layman
    def write(self, path):
        '''
        Write the list of overlays to a file.

        >>> import tempfile
        >>> tmpdir = tempfile.mkdtemp(prefix="laymantmp_")
        >>> write = os.path.join(tmpdir, 'test.xml')
        >>> here = os.path.dirname(os.path.realpath(__file__))
        >>> from layman.config import BareConfig
        >>> config = BareConfig()
        >>> a = DbBase(config, [here + '/tests/testfiles/global-overlays.xml', ])
        >>> from layman.output import Message
        >>> b = DbBase({"output": Message() }, [write,])
        >>> b.overlays['wrobel-stable'] = a.overlays['wrobel-stable']
        >>> b.write(write)
        >>> c = DbBase({"output": Message() }, [write,])
        >>> c.overlays.keys()
        ['wrobel-stable']

        >>> os.unlink(write)
        >>> os.rmdir(tmpdir)
        '''

        tree = ET.Element('repositories', version="1.0", encoding=_UNICODE)
        tree[:] = [e.to_xml() for e in self.overlays.values()]
        indent(tree)
        tree = ET.ElementTree(tree)
        try:
            with fileopen(path, 'w') as f:
                 tree.write(f, encoding=_UNICODE)

        except Exception as error:
            raise Exception('Failed to write to local overlays file: '
                            + path + '\nError was:\n' + str(error))
コード例 #2
0
ファイル: dbbase.py プロジェクト: wking/layman
    def write(self, path):
        '''
        Write the list of overlays to a file.
        '''

        tree = ET.Element('repositories', version="1.0", encoding=_UNICODE)
        tree[:] = [e.to_xml() for e in self.overlays.values()]
        indent(tree)
        tree = ET.ElementTree(tree)
        try:
            with fileopen(path, 'w') as f:
                 tree.write(f, encoding=_UNICODE)

        except Exception as error:
            raise Exception('Failed to write to local overlays file: '
                            + path + '\nError was:\n' + str(error))
コード例 #3
0
ファイル: xml_db.py プロジェクト: fatman2021/layman
    def write(self, path):
        '''
        Write the list of overlays to a file.
        '''
        tree = ET.Element('repositories', version="1.0", encoding=_UNICODE)
        tree[:] = [e.to_xml() for e in self.overlays.values()]
        indent(tree)
        tree = ET.ElementTree(tree)
        try:
            with fileopen(path, 'w') as f:
                tree.write(f, encoding=_UNICODE)

        except Exception as err:
            msg = 'Failed to write to local overlays file: %(path)s\nError was'\
                  ':\n%(err)s' % {'path': path, 'err': err}
            raise Exception(msg)
コード例 #4
0
    def write(self, path, remove=False):
        '''
        Write the list of overlays to a file.
        '''
        tree = ET.Element('repositories', version="1.0", encoding=_UNICODE)
        tree[:] = [e.to_xml() for e in self.overlays.values()]
        indent(tree)
        tree = ET.ElementTree(tree)
        try:
            with fileopen(path, 'w') as f:
                tree.write(f, encoding=_UNICODE)

        except Exception as err:
            msg = 'Failed to write to local overlays file: %(path)s\nError was'\
                  ':\n%(err)s' % {'path': path, 'err': err}
            raise Exception(msg)
コード例 #5
0
    def write(self, destination):
        '''
        Writes overlay file to desired location.

        @params destination: path & file to write xml to.
        @rtype bool: reflects success or failure to write xml.
        '''
        if not destination:
            filepath = self.config.get_option('overlay_defs')
            if self.sudo:
                filepath = get_input('Desired file destination dir: ')
            filename = get_input('Desired overlay file name: ')

            if not filename.endswith('.xml'):
                filename += ".xml"

            if not filepath.endswith(os.path.sep):
                filepath += os.path.sep

            destination = filepath + filename

        self.tree = ET.Element('repositories',
                               version='1.1',
                               encoding=_UNICODE)

        if os.path.isfile(destination):
            self.read(destination)

        self._sort_to_tree()
        indent(self.tree)
        self.tree = ET.ElementTree(self.tree)

        try:
            with fileopen(destination, 'w') as xml:
                self.tree.write(xml, encoding=_UNICODE)
            msg = 'Successfully wrote repo(s) to: %(path)s'\
                  % ({'path': destination})
            self.output.info(msg)
            return True

        except IOError as e:
            raise Exception("Writing XML failed: %(error)s" % ({'error': e}))
コード例 #6
0
ファイル: maker.py プロジェクト: dewey/layman
    def write(self, destination):
        '''
        Writes overlay file to desired location.

        @params destination: path & file to write xml to.
        @rtype bool: reflects success or failure to write xml.
        '''
        if not destination:
            filepath = self.config.get_option('overlay_defs')
            if self.sudo:
                filepath = get_input('Desired file destination dir: ')
            filename = get_input('Desired overlay file name: ')

            if not filename.endswith('.xml'):
                filename += ".xml"

            if not filepath.endswith(os.path.sep):
                filepath += os.path.sep

            destination = filepath + filename

        self.tree = ET.Element('repositories', version='1.1', encoding=_UNICODE)

        if os.path.isfile(destination):
            self.read(destination)

        self._sort_to_tree()
        indent(self.tree)
        self.tree = ET.ElementTree(self.tree)

        try:
            with fileopen(destination, 'w') as xml:
                self.tree.write(xml, encoding=_UNICODE)
            msg = 'Successfully wrote repo(s) to: %(path)s'\
                  % ({'path': destination})
            self.output.info(msg)
            return True

        except IOError as e:
            raise Exception("Writing XML failed: %(error)s" % ({'error': e}))
コード例 #7
0
ファイル: maker.py プロジェクト: fatman2021/layman
    def write(self, destination):
        """
        Writes overlay file to desired location.

        @params destination: path & file to write xml to.
        @rtype bool: reflects success or failure to write xml.
        """
        if not destination:
            filepath = self.config.get_option("overlay_defs")
            if self.sudo:
                filepath = get_input("Desired file destination dir: ")
            filename = get_input("Desired overlay file name: ")

            if not filename.endswith(".xml"):
                filename += ".xml"

            if not filepath.endswith(os.path.sep):
                filepath += os.path.sep

            destination = filepath + filename

        self.tree = ET.Element("repositories", version="1.1", encoding=_UNICODE)

        if os.path.isfile(destination):
            self.read(destination)

        self._sort_to_tree()
        indent(self.tree)
        self.tree = ET.ElementTree(self.tree)

        try:
            with fileopen(destination, "w") as xml:
                self.tree.write(xml, encoding=_UNICODE)
            msg = "Successfully wrote repo(s) to: %(path)s" % ({"path": destination})
            self.output.info(msg)
            return True

        except IOError as e:
            raise Exception("Writing XML failed: %(error)s" % ({"error": e}))