Esempio n. 1
0
 def test_ensure_parent_directory(self):
     orig = gf.tmp_directory()
     tmp_path = os.path.join(orig, "foo.bar")
     tmp_parent = orig
     gf.ensure_parent_directory(tmp_path)
     self.assertTrue(gf.directory_exists(tmp_parent))
     tmp_path = os.path.join(orig, "foo/bar.baz")
     tmp_parent = os.path.join(orig, "foo")
     gf.ensure_parent_directory(tmp_path)
     self.assertTrue(gf.directory_exists(tmp_parent))
     tmp_path = os.path.join(orig, "bar")
     gf.ensure_parent_directory(tmp_path, ensure_parent=False)
     self.assertTrue(gf.directory_exists(tmp_path))
     gf.delete_directory(orig)
 def test_ensure_parent_directory(self):
     orig = gf.tmp_directory()
     tmp_path = os.path.join(orig, "foo.bar")
     tmp_parent = orig
     gf.ensure_parent_directory(tmp_path)
     self.assertTrue(gf.directory_exists(tmp_parent))
     tmp_path = os.path.join(orig, "foo/bar.baz")
     tmp_parent = os.path.join(orig, "foo")
     gf.ensure_parent_directory(tmp_path)
     self.assertTrue(gf.directory_exists(tmp_parent))
     tmp_path = os.path.join(orig, "bar")
     gf.ensure_parent_directory(tmp_path, ensure_parent=False)
     self.assertTrue(gf.directory_exists(tmp_path))
     gf.delete_directory(orig)
Esempio n. 3
0
    def decompress(self, output_path):
        """
        Decompress the entire container into the given directory.

        :param string output_path: path of the destination directory
        :raises: TypeError: if this container does not exist
        :raises: ValueError: if this container contains unsafe entries,
                             or ``output_path`` is not an existing directory
        :raises: OSError: if an error occurred decompressing the given container
                          (e.g., empty file, damaged file, etc.)
        """
        self.log([u"Decompressing the container into '%s'", output_path])
        if not self.exists():
            self.log_exc(u"This container does not exist. Wrong path?", None,
                         True, TypeError)
        if self.actual_container is None:
            self.log_exc(u"The actual container object has not been set", None,
                         True, TypeError)
        if not gf.directory_exists(output_path):
            self.log_exc(u"The output path is not an existing directory", None,
                         True, ValueError)
        if not self.is_safe:
            self.log_exc(u"This container contains unsafe entries", None, True,
                         ValueError)
        self.actual_container.decompress(output_path)
Esempio n. 4
0
    def exists(self):
        """
        Return ``True`` if the container has its path set and it exists,
        ``False`` otherwise.

        :rtype: boolean
        """
        return gf.file_exists(self.file_path) or gf.directory_exists(self.file_path)
Esempio n. 5
0
    def exists(self):
        """
        Return ``True`` if the container has its path set and it exists,
        ``False`` otherwise.

        :rtype: boolean
        """
        return gf.file_exists(self.file_path) or gf.directory_exists(self.file_path)
Esempio n. 6
0
    def check_container(self, container_path, container_format=None, config_string=None):
        """
        Check whether the given container is well-formed.

        :param string container_path: the path of the container to be checked
        :param container_format: the format of the container
        :type  container_format: :class:`~aeneas.container.ContainerFormat`
        :param string config_string: the configuration string generated by the wizard
        :rtype: :class:`~aeneas.validator.ValidatorResult`
        """
        self.log([u"Checking container '%s'", container_path])
        self.result = ValidatorResult()

        if self._are_safety_checks_disabled(u"check_container"):
            return self.result

        if not (gf.file_exists(container_path) or gf.directory_exists(container_path)):
            self._failed(u"Container '%s' not found." % container_path)
            return self.result

        container = Container(container_path, container_format)
        try:
            self.log(u"Checking container has config file")
            if config_string is not None:
                self.log(u"Container with config string from wizard")
                self.check_config_txt(config_string, is_config_string=True)
            elif container.has_config_xml:
                self.log(u"Container has XML config file")
                contents = container.read_entry(container.entry_config_xml)
                if contents is None:
                    self._failed(u"Unable to read the contents of XML config file.")
                    return self.result
                self.check_config_xml(contents)
            elif container.has_config_txt:
                self.log(u"Container has TXT config file")
                contents = container.read_entry(container.entry_config_txt)
                if contents is None:
                    self._failed(u"Unable to read the contents of TXT config file.")
                    return self.result
                self.check_config_txt(contents, is_config_string=False)
            else:
                self._failed(u"Container does not have a TXT or XML configuration file.")

            self.log(u"Checking we have a valid job in the container")
            if not self.result.passed:
                return self.result
            self.log(u"Analyze the contents of the container")
            analyzer = AnalyzeContainer(container)
            if config_string is not None:
                job = analyzer.analyze(config_string=config_string)
            else:
                job = analyzer.analyze()
            self._check_analyzed_job(job, container)

        except OSError:
            self._failed(u"Unable to read the contents of the container.")
        return self.result
Esempio n. 7
0
    def compress(self, input_path):
        """
        Compress the contents of the given directory.

        :param string input_path: path of the input directory
        :raises: TypeError: if the container path has not been set
        :raises: ValueError: if ``input_path`` is not an existing directory
        :raises: OSError: if an error occurred compressing the given container
                          (e.g., empty file, damaged file, etc.)
        """
        self.log([u"Compressing '%s' into this container", input_path])

        if self.file_path is None:
            self.log_exc(u"The container path has not been set", None, True, TypeError)
        if self.actual_container is None:
            self.log_exc(u"The actual container object has not been set", None, True, TypeError)
        if not gf.directory_exists(input_path):
            self.log_exc(u"The input path is not an existing directory", None, True, ValueError)
        gf.ensure_parent_directory(input_path)
        self.actual_container.compress(input_path)
Esempio n. 8
0
    def compress(self, input_path):
        """
        Compress the contents of the given directory.

        :param string input_path: path of the input directory
        :raises: TypeError: if the container path has not been set
        :raises: ValueError: if ``input_path`` is not an existing directory
        :raises: OSError: if an error occurred compressing the given container
                          (e.g., empty file, damaged file, etc.)
        """
        self.log([u"Compressing '%s' into this container", input_path])

        if self.file_path is None:
            self.log_exc(u"The container path has not been set", None, True, TypeError)
        if self.actual_container is None:
            self.log_exc(u"The actual container object has not been set", None, True, TypeError)
        if not gf.directory_exists(input_path):
            self.log_exc(u"The input path is not an existing directory", None, True, ValueError)
        gf.ensure_parent_directory(input_path)
        self.actual_container.compress(input_path)
Esempio n. 9
0
    def decompress(self, output_path):
        """
        Decompress the entire container into the given directory.

        :param string output_path: path of the destination directory
        :raises: TypeError: if this container does not exist
        :raises: ValueError: if this container contains unsafe entries,
                             or ``output_path`` is not an existing directory
        :raises: OSError: if an error occurred decompressing the given container
                          (e.g., empty file, damaged file, etc.)
        """
        self.log([u"Decompressing the container into '%s'", output_path])
        if not self.exists():
            self.log_exc(u"This container does not exist. Wrong path?", None, True, TypeError)
        if self.actual_container is None:
            self.log_exc(u"The actual container object has not been set", None, True, TypeError)
        if not gf.directory_exists(output_path):
            self.log_exc(u"The output path is not an existing directory", None, True, ValueError)
        if not self.is_safe:
            self.log_exc(u"This container contains unsafe entries", None, True, ValueError)
        self.actual_container.decompress(output_path)
Esempio n. 10
0
 def test_directory_exists_false(self):
     orig = "/foo/bar/baz"
     self.assertFalse(gf.directory_exists(orig))
Esempio n. 11
0
 def test_directory_exists_false(self):
     orig = "/foo/bar/baz"
     self.assertFalse(gf.directory_exists(orig))
Esempio n. 12
0
 def test_delete_directory_existing(self):
     orig = gf.tmp_directory()
     self.assertTrue(gf.directory_exists(orig))
     gf.delete_directory(orig)
     self.assertFalse(gf.directory_exists(orig))
Esempio n. 13
0
 def test_delete_directory_not_existing(self):
     orig = "/foo/bar/baz"
     self.assertFalse(gf.directory_exists(orig))
     gf.delete_directory(orig)
     self.assertFalse(gf.directory_exists(orig))
Esempio n. 14
0
 def test_delete_directory_existing(self):
     orig = gf.tmp_directory()
     self.assertTrue(gf.directory_exists(orig))
     gf.delete_directory(orig)
     self.assertFalse(gf.directory_exists(orig))
Esempio n. 15
0
 def test_tmp_directory(self):
     tmp_dir = gf.tmp_directory()
     self.assertTrue(gf.directory_exists(tmp_dir))
     gf.delete_directory(tmp_dir)
Esempio n. 16
0
 def test_delete_directory_not_existing(self):
     orig = "/foo/bar/baz"
     self.assertFalse(gf.directory_exists(orig))
     gf.delete_directory(orig)
     self.assertFalse(gf.directory_exists(orig))
Esempio n. 17
0
 def test_tmp_directory(self):
     tmp_dir = gf.tmp_directory()
     self.assertTrue(gf.directory_exists(tmp_dir))
     gf.delete_directory(tmp_dir)