예제 #1
0
    def run(self):
        self.clean()
        # Re-create the temporary directory, it's an empty directory now
        os.mkdir(self.temp_dir)

        for d in self.package_dirs:
            common.deep_iterate_dir(d, self._iteration_callback, False)

        self.clean()
        print("==> DONE!")
        return
    def run(self):
        self.clean()
        # Re-create the temporary directory, it's an empty directory now
        os.mkdir(self.temp_dir)

        for d in self.package_dirs:
            common.deep_iterate_dir(d, self._iteration_callback, False)

        self.clean()
        print("==> DONE!")
        return
    def _scan_package(self, pkg_path):

        file_name = os.path.split(pkg_path)[-1]

        print("==> Scanning package ( %s )" % file_name.encode('utf-8'))
        print("==> Unzip package ...")
        out_dir = os.path.join(self.temp_dir, file_name)

        scanner = PackageScanner(self.workspace, self.engines, file_name)

        # FIXME: rename the file path to avoid to use utf8 encoding string since 7z.exe on windows will complain.
        new_pkg_path = common.normalize_utf8_path(pkg_path, self.package_index)

        if new_pkg_path != pkg_path:
            os.rename(pkg_path, new_pkg_path)

        new_out_dir = common.normalize_utf8_path(out_dir, self.package_index)
        os.mkdir(new_out_dir)

        try:
            if 0 == scanner.unzip_package(new_pkg_path, new_out_dir,
                                          self.opts["7z_path"]):
                for enginesInPriority in scanner.engines:

                    def callback(path, is_dir):
                        if is_dir:
                            return False

                        if scanner.check_file_name(path, enginesInPriority):
                            return True

                        if self._need_to_check_file_content(path):
                            if scanner.check_file_content(
                                    path, enginesInPriority):
                                return True

                        return False

                    common.deep_iterate_dir(new_out_dir, callback)

            self.all_results.append(scanner.result)
            if pkg_path != new_pkg_path:
                os.rename(new_pkg_path, pkg_path)

        except Exception as e:
            if pkg_path != new_pkg_path:
                os.rename(new_pkg_path, pkg_path)
            raise Exception(e)

        self.package_index += 1

        return
    def _scan_package(self, pkg_path):

        file_name = os.path.split(pkg_path)[-1]

        print("==> Scanning package ( %s )" % file_name.encode('utf-8'))
        print("==> Unzip package ...")
        out_dir = os.path.join(self.temp_dir, file_name)

        scanner = PackageScanner(self.workspace, self.engines, file_name)

        # FIXME: rename the file path to avoid to use utf8 encoding string since 7z.exe on windows will complain.
        new_pkg_path = common.normalize_utf8_path(pkg_path, self.package_index)

        if new_pkg_path != pkg_path:
            os.rename(pkg_path, new_pkg_path)

        new_out_dir = common.normalize_utf8_path(out_dir, self.package_index)
        os.mkdir(new_out_dir)

        try:
            if 0 == scanner.unzip_package(new_pkg_path, new_out_dir, self.opts["7z_path"]):
                def callback(path, is_dir):
                    if is_dir:
                        return False

                    scanner.check_file_name(path)

                    if self._need_to_check_file_content(path):
                        if scanner.check_file_content(path):
                            return True

                    return False

                common.deep_iterate_dir(new_out_dir, callback)

            self.all_results.append(scanner.result)
            if pkg_path != new_pkg_path:
                os.rename(new_pkg_path, pkg_path)

        except Exception as e:
            if pkg_path != new_pkg_path:
                os.rename(new_pkg_path, pkg_path)
            raise Exception(e)

        self.package_index += 1

        return