コード例 #1
0
ファイル: v1.py プロジェクト: Roadmaster/checkbox
 def __init__(self, filename, text, provider):
     """
     Initialize the plug-in with the specified name text
     """
     self._filename = filename
     self._job_list = []
     logger.debug(_("Loading jobs definitions from %r..."), filename)
     try:
         records = load_rfc822_records(
             text, source=FileTextSource(filename))
     except RFC822SyntaxError as exc:
         raise PlugInError(
             _("Cannot load job definitions from {!r}: {}").format(
                 filename, exc))
     for record in records:
         try:
             job = JobDefinition.from_rfc822_record(record)
         except ValueError as exc:
             raise PlugInError(
                 _("Cannot define job from record {!r}: {}").format(
                     record, exc))
         else:
             job._provider = provider
             self._job_list.append(job)
             logger.debug(_("Loaded %r"), job)
コード例 #2
0
 def test_from_rfc822_record_full_record(self):
     job = JobDefinition.from_rfc822_record(self._full_record)
     self.assertEqual(job.plugin, "plugin")
     self.assertEqual(job.id, "id")
     self.assertEqual(job.requires, "requires")
     self.assertEqual(job.command, "command")
     self.assertEqual(job.description, "description")
コード例 #3
0
ファイル: launcher1.py プロジェクト: Roadmaster/checkbox
    def run_local_job(self, checksum, env):
        """
        Run a job with and interpret the stdout as a job definition.

        :param checksum:
            The checksum of the job to execute
        :param env:
            Environment to execute the job in.
        :returns:
            A list of job definitions that were parsed out of the output.
        :raises LookupError:
            If the checksum does not match any known job
        """
        job = self.find_job(checksum)
        cmd = ["bash", "-c", job.command]
        output = subprocess.check_output(cmd, universal_newlines=True, env=self.modify_execution_environment(env))
        job_list = []
        source = JobOutputTextSource(job)
        try:
            record_list = load_rfc822_records(output, source=source)
        except RFC822SyntaxError as exc:
            logging.error(_("Syntax error in job generated from %s: %s"), job, exc)
        else:
            for record in record_list:
                job = JobDefinition.from_rfc822_record(record)
                job_list.append(job)
        return job_list
コード例 #4
0
 def test_from_rfc822_record_min_record(self):
     job = JobDefinition.from_rfc822_record(self._min_record)
     self.assertEqual(job.plugin, "plugin")
     self.assertEqual(job.id, "id")
     self.assertEqual(job.requires, None)
     self.assertEqual(job.command, None)
     self.assertEqual(job.description, None)
コード例 #5
0
ファイル: test_job.py プロジェクト: bladernr/checkbox
 def test_from_rfc822_record_full_record(self):
     job = JobDefinition.from_rfc822_record(self._full_record)
     self.assertEqual(job.plugin, "plugin")
     self.assertEqual(job.name, "name")
     self.assertEqual(job.requires, "requires")
     self.assertEqual(job.command, "command")
     self.assertEqual(job.description, "description")
コード例 #6
0
ファイル: test_job.py プロジェクト: bladernr/checkbox
 def test_from_rfc822_record_min_record(self):
     job = JobDefinition.from_rfc822_record(self._min_record)
     self.assertEqual(job.plugin, "plugin")
     self.assertEqual(job.name, "name")
     self.assertEqual(job.requires, None)
     self.assertEqual(job.command, None)
     self.assertEqual(job.description, None)
コード例 #7
0
 def __init__(self, filename, text, provider):
     """
     Initialize the plug-in with the specified name text
     """
     self._filename = filename
     self._job_list = []
     logger.debug(_("Loading jobs definitions from %r..."), filename)
     try:
         records = load_rfc822_records(text,
                                       source=FileTextSource(filename))
     except RFC822SyntaxError as exc:
         raise PlugInError(
             _("Cannot load job definitions from {!r}: {}").format(
                 filename, exc))
     for record in records:
         try:
             job = JobDefinition.from_rfc822_record(record)
         except ValueError as exc:
             raise PlugInError(
                 _("Cannot define job from record {!r}: {}").format(
                     record, exc))
         else:
             job._provider = provider
             self._job_list.append(job)
             logger.debug(_("Loaded %r"), job)
コード例 #8
0
ファイル: session.py プロジェクト: zyga/plainbox
 def _process_local_result(self, result):
     # First parse all records and create a list of new jobs (confusing
     # name, not a new list of jobs)
     new_job_list = []
     for record in self._gen_rfc822_records_from_io_log(result):
         new_job = JobDefinition.from_rfc822_record(record)
         new_job_list.append(new_job)
     # Then for each new job, add it to the job_list, unless it collides
     # with another job with the same name.
     for new_job in new_job_list:
         try:
             existing_job = self._job_state_map[new_job.name]
         except KeyError:
             logger.info("Storing new job %r", new_job)
             self._job_state_map[new_job.name] = JobState(new_job)
             self._job_list.append(new_job)
         else:
             # XXX: there should be a channel where such errors could be
             # reported back to the UI layer. Perhaps update_job_result()
             # could simply return a list of problems in a similar manner
             # how update_desired_job_list() does.
             logging.warning(
                 ("Local job %s produced job %r that collides with"
                  " an existing job %r, the new job was discarded"),
                 result.job, new_job, existing_job)
コード例 #9
0
    def run_local_job(self, checksum, env):
        """
        Run a job with and interpret the stdout as a job definition.

        :param checksum:
            The checksum of the job to execute
        :param env:
            Environment to execute the job in.
        :returns:
            A list of job definitions that were parsed out of the output.
        :raises LookupError:
            If the checksum does not match any known job
        """
        job = self.find_job(checksum)
        cmd = ['bash', '-c', job.command]
        output = subprocess.check_output(
            cmd,
            universal_newlines=True,
            env=self.modify_execution_environment(env))
        job_list = []
        source = JobOutputTextSource(job)
        try:
            record_list = load_rfc822_records(output, source=source)
        except RFC822SyntaxError as exc:
            logging.error(_("Syntax error in job generated from %s: %s"), job,
                          exc)
        else:
            for record in record_list:
                job = JobDefinition.from_rfc822_record(record)
                job_list.append(job)
        return job_list
コード例 #10
0
    def run_generator_job(self, checksum, env):
        """
        Run a job with and process the stdout to get a job definition.

        :param checksum:
            The checksum of the job to execute
        :param env:
            Environment to execute the job in.
        :returns:
            A list of job definitions that were processed from the output.
        :raises LookupError:
            If the checksum does not match any known job
        """
        job = self.find_job(checksum)
        cmd = [job.shell, '-c', job.command]
        output = subprocess.check_output(
            cmd,
            universal_newlines=True,
            env=self.modify_execution_environment(env))
        job_list = []
        source = JobOutputTextSource(job)
        try:
            record_list = load_rfc822_records(output, source=source)
        except RFC822SyntaxError as exc:
            logging.error(_("Syntax error in record generated from %s: %s"),
                          job, exc)
        else:
            if job.plugin == 'local':
                for record in record_list:
                    job = JobDefinition.from_rfc822_record(record)
                    job_list.append(job)
            elif job.plugin == 'resource':
                resource_list = []
                for record in record_list:
                    resource = Resource(record.data)
                    resource_list.append(resource)
                for plugin in all_providers.get_all_plugins():
                    for u in plugin.plugin_object.unit_list:
                        if (isinstance(u, TemplateUnit)
                                and u.resource_id == job.id):
                            logging.info(_("Instantiating unit: %s"), u)
                            for new_unit in u.instantiate_all(resource_list):
                                job_list.append(new_unit)
        return job_list
コード例 #11
0
ファイル: box.py プロジェクト: yphus/plainbox
 def load(self, somewhere):
     if isinstance(somewhere, str):
         # Load data from a file with the given name
         filename = somewhere
         with open(filename, 'rt', encoding='UTF-8') as stream:
             return load(stream)
     if isinstance(somewhere, TextIOWrapper):
         stream = somewhere
         logger.debug("Loading jobs definitions from %r...", stream.name)
         record_list = load_rfc822_records(stream)
         job_list = []
         for record in record_list:
             job = JobDefinition.from_rfc822_record(record)
             logger.debug("Loaded %r", job)
             job_list.append(job)
         return job_list
     else:
         raise TypeError("Unsupported type of 'somewhere': {!r}".format(
             type(somewhere)))
コード例 #12
0
ファイル: box.py プロジェクト: zyga/plainbox
 def load(self, somewhere):
     if isinstance(somewhere, str):
         # Load data from a file with the given name
         filename = somewhere
         with open(filename, 'rt', encoding='UTF-8') as stream:
             return load(stream)
     if isinstance(somewhere, TextIOWrapper):
         stream = somewhere
         logger.debug("Loading jobs definitions from %r...", stream.name)
         record_list = load_rfc822_records(stream)
         job_list = []
         for record in record_list:
             job = JobDefinition.from_rfc822_record(record)
             logger.debug("Loaded %r", job)
             job_list.append(job)
         return job_list
     else:
         raise TypeError(
             "Unsupported type of 'somewhere': {!r}".format(
                 type(somewhere)))
コード例 #13
0
 def test_from_rfc822_record_missing_id(self):
     record = RFC822Record({'plugin': 'plugin'})
     with self.assertRaises(ValueError):
         JobDefinition.from_rfc822_record(record)
コード例 #14
0
ファイル: test_job.py プロジェクト: brendan-donegan/checkbox
 def test_from_rfc822_record_missing_name(self):
     record = RFC822Record({'plugin': 'plugin'})
     with self.assertRaises(ValueError):
         JobDefinition.from_rfc822_record(record)