コード例 #1
0
 def test_origin_caller(self):
     """
     verify that Origin.get_caller_origin() uses PythonFileTextSource as the
     origin.source attribute.
     """
     self.assertIsInstance(
         Origin.get_caller_origin().source, PythonFileTextSource)
コード例 #2
0
    def __init__(self,
                 data,
                 origin=None,
                 raw_data=None,
                 field_offset_map=None):
        """
        Initialize a new record.

        :param data:
            A dictionary with normalized record data
        :param origin:
            A :class:`Origin` instance that describes where the data came from
        :param raw_data:
            An optional dictionary with raw record data. If omitted then it
            will default to normalized data (as the same object, without making
            a copy)
        :param field_offset_map:
            An optional dictionary with offsets (in line numbers) of each field
        """
        self._data = data
        if raw_data is None:
            raw_data = data
        self._raw_data = raw_data
        if origin is None:
            origin = Origin.get_caller_origin()
        self._origin = origin
        self._field_offset_map = field_offset_map
コード例 #3
0
 def _get_job(self):
     job_list = get_matching_job_list(
         self.get_job_list(None),
         JobIdQualifier(self.job_id, Origin.get_caller_origin()))
     if len(job_list) == 0:
         return None
     else:
         return job_list[0]
コード例 #4
0
ファイル: job.py プロジェクト: xinpengliu/checkbox
    def __init__(self,
                 data,
                 origin=None,
                 provider=None,
                 controller=None,
                 raw_data=None,
                 parameters=None,
                 field_offset_map=None):
        """
        Initialize a new JobDefinition instance.

        :param data:
            Normalized data that makes up this job definition
        :param origin:
            An (optional) Origin object. If omitted a fake origin object is
            created. Normally the origin object should be obtained from the
            RFC822Record object.
        :param provider:
            An (optional) Provider1 object. If omitted it defaults to None but
            the actual job definition is not suitable for execution. All job
            definitions are expected to have a provider.
        :param controller:
            An (optional) session state controller. If omitted a checkbox
            session state controller is implicitly used. The controller defines
            how this job influences the session it executes in.
        :param raw_data:
            An (optional) raw version of data, without whitespace
            normalization. If omitted then raw_data is assumed to be data.
        :param parameters:
            An (optional) dictionary of parameters. Parameters allow for unit
            properties to be altered while maintaining a single definition.
            This is required to obtain translated summary and description
            fields, while having a single translated base text and any
            variation in the available parameters.
        :param field_offset_map:
            An optional dictionary with offsets (in line numbers) of each
            field.  Line numbers are relative to the value of origin.line_start

        .. note::
            You should almost always use :meth:`from_rfc822_record()` instead.
        """
        if origin is None:
            origin = Origin.get_caller_origin()
        super().__init__(data,
                         raw_data=raw_data,
                         origin=origin,
                         provider=provider,
                         parameters=parameters,
                         field_offset_map=field_offset_map)
        # NOTE: controllers cannot be customized for instantiated templates so
        # I wonder if we should start hard-coding it in. Nothing seems to be
        # using custom controller functionality anymore.
        if controller is None:
            # XXX: moved here because of cyclic imports
            from plainbox.impl.ctrl import checkbox_session_state_ctrl
            controller = checkbox_session_state_ctrl
        self._resource_program = None
        self._controller = controller
コード例 #5
0
    def __init__(self, retain_id_set):
        """
        Initialize the qualifier.

        :param retain_id_set:
            The set of job identifiers that should be retained on resume.
        """
        super().__init__(Origin.get_caller_origin())
        self._retain_id_set = frozenset(retain_id_set)
コード例 #6
0
 def test_origin_source_filename_is_correct(self):
     """
     verify that make_job() can properly trace the filename of the python
     module that called make_job()
     """
     # Pass -1 to get_caller_origin() to have filename point at this file
     # instead of at whatever ends up calling the test method
     self.assertEqual(
         os.path.basename(Origin.get_caller_origin(-1).source.filename),
         "test_origin.py")
コード例 #7
0
    def __init__(self,
                 data,
                 raw_data=None,
                 origin=None,
                 provider=None,
                 parameters=None,
                 field_offset_map=None,
                 virtual=False):
        """
        Initialize a new unit

        :param data:
            A dictionary of normalized data. This data is suitable for normal
            application usage. It is not suitable for gettext lookups as the
            original form is lost by the normalization process.
        :param raw_data:
            A dictionary of raw data (optional). Defaults to data. Values in
            this dictionary are in their raw form, as they were loaded from a
            unit file. This data is suitable for gettext lookups.
        :param origin:
            An (optional) Origin object. If omitted a fake origin object is
            created. Normally the origin object should be obtained from the
            RFC822Record object.
        :param parameters:
            An (optional) dictionary of parameters. Parameters allow for unit
            properties to be altered while maintaining a single definition.
            This is required to obtain translated summary and description
            fields, while having a single translated base text and any
            variation in the available parameters.
        :param field_offset_map:
            An optional dictionary with offsets (in line numbers) of each
            field.  Line numbers are relative to the value of origin.line_start
        :param virtual:
            An optional flag marking this unit as "virtual". It can be used
            to annotate units synthetized by PlainBox itself so that certain
            operations can treat them differently. It also helps with merging
            non-virtual and virtual units.
        """
        if raw_data is None:
            raw_data = data
        if origin is None:
            origin = Origin.get_caller_origin()
        if field_offset_map is None:
            field_offset_map = {field: 0 for field in data}
        self._data = data
        self._raw_data = raw_data
        self._origin = origin
        self._field_offset_map = field_offset_map
        self._provider = provider
        self._checksum = None
        self._parameters = parameters
        self._virtual = virtual
        self._hash_cache = None
コード例 #8
0
ファイル: newcli.py プロジェクト: mh9527/iotr5
 def select_local_jobs(self):
     print(self.C.header(_("Selecting Job Generators")))
     # Create a qualifier list that will pick all local jobs out of the
     # subset of jobs also enumerated by the whitelists we've already
     # picked.
     #
     # Since each whitelist is a qualifier that selects jobs enumerated
     # within, we only need to and an exclusive qualifier that deselects
     # non-local jobs and we're done.
     qualifier_list = []
     qualifier_list.extend(self._qualifier_list)
     origin = Origin.get_caller_origin()
     qualifier_list.append(FieldQualifier(
         'plugin', OperatorMatcher(operator.ne, 'local'), origin,
         inclusive=False))
     local_job_list = select_jobs(
         self.manager.state.job_list, qualifier_list)
     self._update_desired_job_list(local_job_list)
コード例 #9
0
    def __init__(self,
                 data,
                 origin=None,
                 provider=None,
                 raw_data=None,
                 parameters=None,
                 field_offset_map=None):
        """
        Initialize a new TemplateUnit instance.

        :param data:
            Normalized data that makes up this job template
        :param origin:
            An (optional) Origin object. If omitted a fake origin object is
            created. Normally the origin object should be obtained from the
            RFC822Record object.
        :param provider:
            An (optional) Provider1 object. If omitted it defaults to None but
            the actual job template is not suitable for execution. All job
            templates are expected to have a provider.
        :param controller:
            An (optional) session state controller. If omitted a checkbox
            session state controller is implicitly used. The controller defines
            how this job influences the session it executes in.
        :param raw_data:
            An (optional) raw version of data, without whitespace
            normalization. If omitted then raw_data is assumed to be data.
        :param parameters:
            An (optional) dictionary of parameters. Parameters allow for unit
            properties to be altered while maintaining a single definition.
            This is required to obtain translated summary and description
            fields, while having a single translated base text and any
            variation in the available parameters.

        .. note::
            You should almost always use :meth:`from_rfc822_record()` instead.
        """
        if origin is None:
            origin = Origin.get_caller_origin()
        super().__init__(data, raw_data, origin, provider, parameters,
                         field_offset_map)
        self._filter_program = None