예제 #1
0
        def _wrap(*args, **kwargs):
            """
            A simple wrapper

            :param args: positional arguments passed through
            :param kwargs: keyword arguments passed through
            """
            try:
                return func(*args, **kwargs)
            except Exception as ex:
                exc_type, exc_value, exc_traceback = sys.exc_info()
                tb = ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback))
                fatal("{name} - ERROR: {err}\n{tb}".format(name=func.__name__,
                                                           err=str(ex),
                                                           tb=tb))
예제 #2
0
파일: herring_app.py 프로젝트: royw/Herring
    def execute(self, cli, settings):
        """
        Execute the tasks specified in the _settings object.

        Currently:

            * settings.list_task asserted shows the available tasks.
            * settings.list_dependencies asserted shows the available tasks
              and their dependencies.
            * settings.list_all_tasks asserted modifies the listing to include
              tasks that do not have a docstring.
            * if both settings.list_task and settings.list_dependencies are
              deasserted, then run the tasks from settings.tasks

        :param cli: the command line interface instance
        :type cli: herring.HerringCLI
        :param settings: the application settings
        :return: None
        """
        try:
            HerringFile.settings = settings
            herring_file = self._find_herring_file(settings.herringfile)
            HerringFile.directory = str(os.path.realpath(os.path.dirname(herring_file)))
            sys.path.insert(1, HerringFile.directory)

            herringfile_is_nonempty = self._is_herring_file_nonempty(herring_file)

            global debug_mode
            global verbose_mode
            debug_mode = settings.debug
            verbose_mode = not settings.quiet

            # the tasks are always ran with the current working directory
            # set to the directory that contains the herringfile
            os.chdir(HerringFile.directory)

            if not settings.json:
                info("Using: %s" % herring_file)

            if not settings.json and settings.environment:
                cli.show_environment()

            with HerringLoader(settings) as loader:
                loader.load_tasks(herring_file)  # populates HerringTasks

                task_list = list(self._get_tasks_list(HerringTasks,
                                                      settings.list_all_tasks,
                                                      herringfile_is_nonempty,
                                                      settings.tasks))

                if settings.list_tasks:
                    cli.show_tasks(self._get_tasks(task_list), HerringTasks, settings)
                elif settings.list_task_usages:
                    cli.show_task_usages(self._get_tasks(task_list), HerringTasks, settings)
                elif settings.list_dependencies:
                    cli.show_depends(self._get_tasks(task_list), HerringTasks, settings)
                else:
                    try:
                        HerringRunner.run_tasks(settings.tasks)
                    except Exception as ex:
                        fatal(ex)
        except ValueError as ex:
            fatal(ex)
예제 #3
0
    def execute(self, cli, settings):
        """
        Execute the tasks specified in the _settings object.

        Currently:

            * settings.list_task asserted shows the available tasks.
            * settings.list_dependencies asserted shows the available tasks
              and their dependencies.
            * settings.list_all_tasks asserted modifies the listing to include
              tasks that do not have a docstring.
            * if both settings.list_task and settings.list_dependencies are
              deasserted, then run the tasks from settings.tasks

        :param cli: the command line interface instance
        :type cli: herring.HerringCLI
        :param settings: the application settings
        :return: None
        """
        try:
            HerringFile.settings = settings
            herring_file = self._find_herring_file(settings.herringfile)
            HerringFile.directory = str(os.path.realpath(os.path.dirname(herring_file)))
            sys.path.insert(1, HerringFile.directory)

            configured_herringfile = self._configured_herring_file(herring_file)

            global debug_mode
            global verbose_mode
            debug_mode = settings.debug
            verbose_mode = not settings.quiet

            # the tasks are always ran with the current working directory
            # set to the directory that contains the herringfile
            os.chdir(HerringFile.directory)

            if not settings.json:
                info("Using: %s" % herring_file)

            if not settings.json and settings.environment:
                cli.show_environment()

            self._load_tasks(herring_file, settings)
            task_list = list(self._get_tasks_list(HerringTasks, settings.list_all_tasks, configured_herringfile))

            # if we are doing a show (-T, -D, -U) and we give another parameter, then only show
            # tasks that contain the parameter.  Example:  "-T doc" will show only the "doc" tasks.
            if settings.tasks:
                abridged_task_list = []
                for task_ in settings.tasks:
                    abridged_task_list.extend(list([t for t in task_list if task_ in t['name']]))
                task_list = abridged_task_list

            if settings.list_tasks:
                cli.show_tasks(self._get_tasks(task_list), HerringTasks, settings)
            elif settings.list_task_usages:
                cli.show_task_usages(self._get_tasks(task_list), HerringTasks, settings)
            elif settings.list_dependencies:
                cli.show_depends(self._get_tasks(task_list), HerringTasks, settings)
            else:
                try:
                    HerringApp.run_tasks(settings.tasks)
                except Exception as ex:
                    fatal(ex)
        except ValueError as ex:
            fatal(ex)
        finally:
            if self.union_dir is not None and not settings.leave_union_dir:
                # noinspection PyTypeChecker
                shutil.rmtree(os.path.dirname(self.union_dir))