Example #1
0
def step_tasks(conf):
    step_sources = conf.system.content.steps.sources
    s = StepDataCache(step_sources, conf)

    if len(step_sources) > 0 and not os.path.isdir(
            conf.system.content.steps.output_dir):
        safe_create_directory(conf.system.content.steps.output_dir)

    tasks = []
    for fn, stepf in s.file_iter():
        basename = conf.system.content.steps.get_basename(fn)

        out_fn = os.path.join(conf.system.content.steps.output_dir,
                              basename) + '.rst'

        t = Task(job=write_steps,
                 description='generate a stepfile for ' + fn,
                 target=out_fn,
                 dependency=fn)
        t.args = (stepf, out_fn, conf)

        tasks.append(t)

    logger.info("added tasks for {0} step generation tasks".format(len(tasks)))
    return tasks
Example #2
0
def example_tasks(conf):
    # In the beginning of this operation, which executes in the main thread, we
    # read all files in "source/includes/" and sub-directories that start with
    # "example-*"

    example_sources = conf.system.content.examples.sources

    # process the corpus of example data.
    d = ExampleDataCache(example_sources, conf)

    if len(example_sources) > 0 and not os.path.isdir(
            conf.system.content.examples.output_dir):
        safe_create_directory(conf.system.content.examples.output_dir)

    tasks = []
    for fn, exmpf in d.file_iter():
        if exmpf.collection is None or exmpf.collection.options.base_file is True:
            continue
        basename = conf.system.content.examples.get_basename(fn)
        out_fn = os.path.join(conf.system.content.examples.output_dir,
                              basename) + '.rst'

        t = Task(
            job=write_full_example,
            description='generate an example for ' + fn,
            target=out_fn,
            dependency=fn,
        )
        t.args = (exmpf.collection, exmpf.examples, out_fn)

        tasks.append(t)

    logger.info("added tasks for {0} example generation tasks".format(
        len(tasks)))
    return tasks
Example #3
0
 def test_add_existing_task_object(self):
     self.assertEqual(self.app.queue, [])
     t = Task()
     self.app.add(t)
     self.assertIs(t, self.app.queue[0])
     self.assertIsNot(t, Task())
     self.assertIsNot(Task(), self.app.queue[0])
Example #4
0
def option_tasks(conf):
    option_sources = conf.system.content.options.sources
    o = OptionDataCache(option_sources, conf)

    if len(option_sources) > 0 and not os.path.isdir(
            conf.system.content.options.output_dir):
        safe_create_directory(conf.system.content.options.output_dir)

    tasks = []
    for dep_fn, option in o.content_iter():
        if option.program.startswith('_'):
            continue

        out_fn = hyph_concat(option.directive, option.program,
                             option.name) + '.rst'
        output_fn = os.path.join(conf.system.content.options.fn_prefix, out_fn)

        t = Task(job=write_options,
                 description='generating option file "{0}" from "{1}"'.format(
                     output_fn, dep_fn),
                 target=output_fn,
                 dependency=[dep_fn])
        t.args = (option, output_fn, conf)

        tasks.append(t)

    logger.info("added tasks for {0} option generation tasks".format(
        len(tasks)))
    return tasks
Example #5
0
    def test_single_runner_task(self):
        self.assertEqual(self.app.queue, [])
        self.assertEqual(self.app.results, [])

        t = Task()
        t.job = sum
        t.args = [[ 1 , 2 ], 0]

        self.app._run_single(t)
        self.assertEqual(self.app.results[0], 3)
Example #6
0
    def test_single_runner_task(self):
        self.assertEqual(self.app.queue, [])
        self.assertEqual(self.app.results, [])

        t = Task()
        t.job = sum
        t.args = [[ 1 , 2 ], 0]

        self.app._run_single(t)
        self.assertEqual(self.app.results[0], 3)
Example #7
0
def toc_tasks(conf):
    toc_sources = conf.system.content.toc.sources

    tocs = TocDataCache(toc_sources, conf)

    if len(toc_sources) > 0 and not os.path.isdir(
            conf.system.content.toc.output_dir):
        safe_create_directory(conf.system.content.toc.output_dir)

    tasks = []
    for dep_fn, toc_data in tocs.file_iter():
        deps = [dep_fn]
        if 'ref-toc-' in dep_fn:
            base_offset = 8
        else:
            base_offset = 4

        fn_basename = os.path.basename(dep_fn)[base_offset:].replace(
            'yaml', 'rst')

        toc_items = toc_data.ordered_items()

        if toc_data.is_spec() is False:
            out_fn = os.path.join(conf.system.content.toc.output_dir,
                                  fn_basename)

            t = Task(job=write_toc_tree_output,
                     target=out_fn,
                     dependency=dep_fn,
                     description="writing toctree to '{0}'".format(out_fn))
            t.args = (out_fn, toc_items)
            tasks.append(t)
        else:
            deps.extend(toc_data.spec_deps())

        if 'ref-toc' in dep_fn:
            out_fn = os.path.join(conf.system.content.toc.output_dir,
                                  hyph_concat('table', fn_basename))

            reft = Task(
                job=write_toc_table,
                target=out_fn,
                dependency=deps,
                description="write table of contents generator".format(out_fn))
            reft.args = (out_fn, toc_items)
            tasks.append(reft)
        else:
            out_fn = os.path.join(conf.system.content.toc.output_dir,
                                  hyph_concat('dfn-list', fn_basename))
            dt = Task(job=write_dfn_list_output,
                      target=out_fn,
                      dependency=deps,
                      description="write definition list toc to '{0}'".format(
                          out_fn))
            dt.args = (out_fn, toc_items)
            tasks.append(dt)

    logger.info('added tasks for {0} toc generation tasks'.format(len(tasks)))

    return tasks
Example #8
0
 def setUp(self):
     self.c = Configuration()
     self.c.runstate = RuntimeStateConfig()
     self.task = Task()
     self.task.job = sum
     self.Task = Task
     self.task.conf = self.c
Example #9
0
 def test_conf_objet_consistent_in_new_task(self):
     self.assertEqual(self.app.queue, [])
     t = Task()
     self.assertIsNone(t.conf)
     self.app.add(t)
     self.assertIsNotNone(t.conf)
     self.assertIs(self.c, self.app.queue[0].conf)
     self.assertIs(self.c, t.conf)
Example #10
0
    def add(self, task=None):
        """
        Adds a new :class:`~giza.app.BuildApp()` or :class:`~giza.task.Task()`
        to the :class:`~giza.app.BuildApp()` object.

        :param string,Task,BuildApp task: Optional. If not specified,
           :meth:`~giza.app.BuildApp.add()` creates and returns a new
           :class:`~giza.task.Task()` object. You can pass the string ``task``
           or the class :class:`~giza.task.Task` to explicitly create a new
           Task, or pass an existing :class:`~giza.task.Task()` instance to add
           that task to the :class:`~giza.app.BuildApp()` instance. You can also
           pass the string ``app`` or the :class:`~giza.app.BuildApp` class, to
           create and add new :class:`~giza.app.BuildApp()`: pass an existing
           :class:`~giza.app.BuildApp()`  instance to add that that operation
           grouping to the queue.

        :returns: A reference to a :class:`~giza.app.BuildApp()` or
           :class:`~giza.task.Task()` object in the :class:`~giza.app.BuildApp()`

        :raises: :exc:`TypeError` if the ``task`` argument is invalid.

        """

        if task is None or task in (Task, 'task'):
            t = Task()
            t.conf = self.conf
            self.queue.append(t)
            return t
        elif task in (MapTask, 'map'):
            t = MapTask()
            t.conf = self.conf
            self.queue.append(t)
            return t
        elif task in (BuildApp, 'app'):
            self.create_pool()
            t = BuildApp(self.conf)
            t.pool = self.pool
            t.root_app = False
            self.queue.append(t)
            return t
        else:
            if isinstance(task, Task):
                if task.conf is None:
                    task.conf = self.conf

                self.queue.append(task)
                return task
            elif isinstance(task, BuildApp):
                self.create_pool()
                task.root_app = False
                task.pool = self.pool
                self.queue.append(task)
                return task
            else:
                raise TypeError('invalid task type')
Example #11
0
    def add(self, task=None):
        """
        Adds a new :class:`~giza.app.BuildApp()` or :class:`~giza.task.Task()`
        to the :class:`~giza.app.BuildApp()` object.

        :param string,Task,BuildApp task: Optional. If not specified,
           :meth:`~giza.app.BuildApp.add()` creates and returns a new
           :class:`~giza.task.Task()` object. You can pass the string ``task``
           or the class :class:`~giza.task.Task` to explicitly create a new
           Task, or pass an existing :class:`~giza.task.Task()` instance to add
           that task to the :class:`~giza.app.BuildApp()` instance. You can also
           pass the string ``app`` or the :class:`~giza.app.BuildApp` class, to
           create and add new :class:`~giza.app.BuildApp()`: pass an existing
           :class:`~giza.app.BuildApp()`  instance to add that that operation
           grouping to the queue.

        :returns: A reference to a :class:`~giza.app.BuildApp()` or
           :class:`~giza.task.Task()` object in the :class:`~giza.app.BuildApp()`

        :raises: :exc:`TypeError` if the ``task`` argument is invalid.

        """

        if task is None or task in (Task, 'task'):
            t = Task()
            t.conf = self.conf
            self.queue.append(t)
            return t
        elif task in (MapTask, 'map'):
            t = MapTask()
            t.conf = self.conf
            self.queue.append(t)
            return t
        elif task in (BuildApp, 'app'):
            self.create_pool()
            t = BuildApp(self.conf)
            t.pool = self.pool
            t.root_app = False
            self.queue.append(t)
            return t
        else:
            if isinstance(task, Task):
                if task.conf is None:
                    task.conf = self.conf

                self.queue.append(task)
                return task
            elif isinstance(task, BuildApp):
                self.create_pool()
                task.root_app = False
                task.pool = self.pool
                self.queue.append(task)
                return task
            else:
                raise TypeError('invalid task type')
Example #12
0
def release_tasks(conf):
    release_sources = conf.system.content.releases.sources

    rel = ReleaseDataCache(release_sources, conf)

    if len(release_sources) > 0 and not os.path.isdir(
            conf.system.content.releases.output_dir):
        safe_create_directory(conf.system.content.releases.output_dir)

    tasks = []

    for dep_fn, release in rel.content_iter():
        t = Task(job=write_release_file,
                 description='generating release spec file: ' + release.target,
                 target=release.target,
                 dependency=dep_fn)
        t.args = (release, release.target, conf)

        tasks.append(t)

    logger.info("added tasks for {0} release generation tasks".format(
        len(tasks)))
    return tasks
Example #13
0
def extract_tasks(conf):
    extract_sources = conf.system.content.extracts.sources

    extracts = ExtractDataCache(extract_sources, conf)

    if len(extract_sources) > 0 and not os.path.isdir(
            conf.system.content.extracts.output_dir):
        safe_create_directory(conf.system.content.extracts.output_dir)

    tasks = []
    for dep_fn, extract in extracts.content_iter():
        t = Task(job=write_extract_file,
                 description="generating extract file: " + extract.target,
                 target=extract.target,
                 dependency=dep_fn)
        t.args = (extract, extract.target)
        tasks.append(t)

        include_statement = get_include_statement(extract.target_project_path)

        for verb, adjc, noun in [(prepend_to_file, 'prepend', extract.prepend),
                                 (append_to_file, 'append', extract.append)]:
            if noun:
                if not isinstance(noun, list):
                    files = [noun]
                else:
                    files = noun

                for fn in files:
                    t = Task(
                        job=verb,
                        target=fn,
                        dependency=dep_fn,
                        description="{0} extract include for '{0}' to '{1}'".
                        format(adjc, extract.target, fn))
                    t.args = (fn, include_statement)
                    tasks.append(t)

    logger.info("added tasks for {0} extract generation tasks".format(
        len(tasks)))

    return tasks