コード例 #1
0
    def create_packages(self) -> None:
        if self.ppj.packages_node is None:
            return

        # clear temporary data
        if os.path.exists(self.options.temp_path):
            shutil.rmtree(self.options.temp_path, ignore_errors=True)

        # ensure package path exists
        if not os.path.exists(self.options.package_path):
            os.makedirs(self.options.package_path, exist_ok=True)

        for i, package_node in enumerate(self.ppj.packages_node):
            if not package_node.tag.endswith('Package'):
                continue

            default_name: str = self.ppj.project_name if i == 0 else '%s (%s)' % (
                self.ppj.project_name, i)
            package_name: str = self.ppj.parse(
                package_node.get('Name', default=default_name))
            package_name = self._fix_package_extension(package_name)

            package_root: str = self.ppj.parse(
                package_node.get('RootDir', default=self.ppj.project_path))

            PackageManager.log.info('Creating "%s"...' % package_name)

            package_data: list = self._populate_include_paths(
                package_node, package_root)

            if not package_data:
                PackageManager.log.info('No includes found for package: "%s"' %
                                        package_name)
                continue

            PackageManager.print_list('Includes found:', package_data)

            for source_path in package_data:
                target_path: str = os.path.join(
                    self.options.temp_path,
                    os.path.relpath(source_path, package_root))

                os.makedirs(os.path.dirname(target_path), exist_ok=True)
                shutil.copy2(source_path, target_path)

            package_path: str = os.path.join(self.options.package_path,
                                             package_name)
            self.package_paths.append(package_path)

            # run bsarch
            commands: str = self.build_commands(self.options.temp_path,
                                                package_path)
            ProcessManager.run(commands, use_bsarch=True)

            # clear temporary data
            if os.path.exists(self.options.temp_path):
                shutil.rmtree(self.options.temp_path, ignore_errors=True)
コード例 #2
0
ファイル: PackageManager.py プロジェクト: dmdemoura/pyro
    def create_packages(self) -> None:
        # clear temporary data
        if os.path.isdir(self.options.temp_path):
            shutil.rmtree(self.options.temp_path, ignore_errors=True)

        # ensure package path exists
        if not os.path.isdir(self.options.package_path):
            os.makedirs(self.options.package_path, exist_ok=True)

        file_names = CaseInsensitiveList()

        for i, package_node in enumerate(
                filter(is_package_node, self.ppj.packages_node)):
            file_name: str = package_node.get('Name')

            # prevent clobbering files previously created in this session
            if file_name in file_names:
                file_name = f'{self.ppj.project_name} ({i})'

            if file_name not in file_names:
                file_names.append(file_name)

            file_name = self._fix_package_extension(file_name)

            file_path: str = os.path.join(self.options.package_path, file_name)

            self._check_write_permission(file_path)

            PackageManager.log.info(f'Creating "{file_name}"...')

            for source_path in self._generate_include_paths(
                    package_node, package_node.get('RootDir')):
                PackageManager.log.info(f'+ "{source_path}"')

                relpath = os.path.relpath(source_path,
                                          package_node.get('RootDir'))
                target_path = os.path.join(self.options.temp_path, relpath)

                # fix target path if user passes a deeper package root (RootDir)
                if endswith(source_path, '.pex',
                            ignorecase=True) and not startswith(
                                relpath, 'scripts', ignorecase=True):
                    target_path = os.path.join(self.options.temp_path,
                                               'Scripts', relpath)

                os.makedirs(os.path.dirname(target_path), exist_ok=True)
                shutil.copy2(source_path, target_path)

            # run bsarch
            command: str = self.build_commands(self.options.temp_path,
                                               file_path)
            ProcessManager.run_bsarch(command)

            # clear temporary data
            if os.path.isdir(self.options.temp_path):
                shutil.rmtree(self.options.temp_path, ignore_errors=True)
コード例 #3
0
ファイル: BuildFacade.py プロジェクト: dmdemoura/pyro
    def try_build_event(self, event: BuildEvent) -> None:
        if event == BuildEvent.PRE:
            has_event_node, event_node = self.ppj.has_pre_build_node, self.ppj.pre_build_node
        elif event == BuildEvent.POST:
            has_event_node, event_node = self.ppj.has_post_build_node, self.ppj.post_build_node
        else:
            raise NotImplementedError

        if has_event_node:
            BuildFacade.log.info(event_node.get('Description'))

            reformat = lambda s: re.sub('[ \t\n\r]+', ' ', s.strip())

            environ: dict = os.environ.copy()
            command: str = ' && '.join(reformat(node.text) for node in filter(is_command_node, event_node))

            ProcessManager.run_command(command, self.ppj.project_path, environ)
コード例 #4
0
ファイル: PapyrusProject.py プロジェクト: fireundubh/pyro
 def try_run_event(self, event: Event) -> None:
     if event == ImportEvent.PRE:
         ProcessManager.run_event(self.pre_import_node, self.project_path)
     elif event == ImportEvent.POST:
         ProcessManager.run_event(self.post_import_node, self.project_path)
     elif event == BuildEvent.PRE:
         ProcessManager.run_event(self.pre_build_node, self.project_path)
     elif event == BuildEvent.POST:
         ProcessManager.run_event(self.post_build_node, self.project_path)
     else:
         raise NotImplementedError
コード例 #5
0
    def try_compile(self, time_elapsed: TimeElapsed) -> None:
        """Builds and passes commands to Papyrus Compiler"""
        commands: list = self.ppj.build_commands()

        script_count: int = len(self.ppj.psc_paths)

        time_elapsed.start_time = time.time()

        if self.ppj.options.no_parallel:
            for command in commands:
                ProcessManager.run(command)
        elif script_count > 0:
            if script_count == 1:
                ProcessManager.run(commands[0])
            else:
                multiprocessing.freeze_support()
                p = multiprocessing.Pool(
                    processes=min(script_count, self.ppj.options.worker_limit))
                p.imap(ProcessManager.run, commands)
                p.close()
                p.join()

        time_elapsed.end_time = time.time()
コード例 #6
0
    def try_compile(self) -> None:
        """Builds and passes commands to Papyrus Compiler"""
        commands: list = self.ppj.build_commands()

        self.compile_data.command_count = len(commands)

        self.compile_data.time.start_time = time.time()

        if self.ppj.options.no_parallel or self.compile_data.command_count == 1:
            for command in commands:
                if ProcessManager.run_compiler(command) == ProcessState.SUCCESS:
                    self.compile_data.success_count += 1
        elif self.compile_data.command_count > 0:
            multiprocessing.freeze_support()
            worker_limit = min(self.compile_data.command_count, self.ppj.options.worker_limit)
            with multiprocessing.Pool(processes=worker_limit,
                                      initializer=BuildFacade._limit_priority) as pool:
                for state in pool.imap(ProcessManager.run_compiler, commands):
                    if state == ProcessState.SUCCESS:
                        self.compile_data.success_count += 1
                pool.close()
                pool.join()

        self.compile_data.time.end_time = time.time()
コード例 #7
0
    def create_packages(self) -> None:
        # clear temporary data
        if os.path.isdir(self.options.temp_path):
            shutil.rmtree(self.options.temp_path, ignore_errors=True)

        # ensure package path exists
        if not os.path.isdir(self.options.package_path):
            os.makedirs(self.options.package_path, exist_ok=True)

        file_names = CaseInsensitiveList()

        for i, package_node in enumerate(
                filter(is_package_node, self.ppj.packages_node)):
            attr_file_name: str = package_node.get(XmlAttributeName.NAME)

            # noinspection PyProtectedMember
            root_dir: str = self.ppj._get_path(
                package_node.get(XmlAttributeName.ROOT_DIR),
                relative_root_path=self.ppj.project_path,
                fallback_path=[
                    self.ppj.project_path,
                    os.path.basename(attr_file_name)
                ])

            # prevent clobbering files previously created in this session
            if attr_file_name in file_names:
                attr_file_name = f'{self.ppj.project_name} ({i})'

            if attr_file_name not in file_names:
                file_names.append(attr_file_name)

            attr_file_name = self._fix_package_extension(attr_file_name)

            file_path: str = os.path.join(self.options.package_path,
                                          attr_file_name)

            self._check_write_permission(file_path)

            PackageManager.log.info(f'Creating "{attr_file_name}"...')

            for source_path, attr_path in self._generate_include_paths(
                    package_node, root_dir):
                if os.path.isabs(source_path):
                    relpath: str = os.path.relpath(source_path, root_dir)
                else:
                    relpath: str = source_path
                    source_path = os.path.join(self.ppj.project_path,
                                               source_path)

                adj_relpath = os.path.normpath(os.path.join(
                    attr_path, relpath))

                PackageManager.log.info(f'+ "{adj_relpath.casefold()}"')

                target_path: str = os.path.join(self.options.temp_path,
                                                adj_relpath)

                # fix target path if user passes a deeper package root (RootDir)
                if endswith(source_path, '.pex',
                            ignorecase=True) and not startswith(
                                relpath, 'scripts', ignorecase=True):
                    target_path = os.path.join(self.options.temp_path,
                                               'Scripts', relpath)

                os.makedirs(os.path.dirname(target_path), exist_ok=True)
                shutil.copy2(source_path, target_path)

                self.includes += 1

            # run bsarch
            command: str = self.build_commands(self.options.temp_path,
                                               file_path)
            ProcessManager.run_bsarch(command)

            # clear temporary data
            if os.path.isdir(self.options.temp_path):
                shutil.rmtree(self.options.temp_path, ignore_errors=True)