Ejemplo n.º 1
0
 def bom(self):
     if not self._bom:
         self._bom = EntityElnBom(self.configs)
         self._bom.configure_motifs(self.ident)
     return self._bom
Ejemplo n.º 2
0
 def bom(self):
     if not self._bom:
         self._bom = EntityElnBom(self.configs)
         self._bom.configure_motifs(self.ident)
     return self._bom
Ejemplo n.º 3
0
class EDAModulePrototypeBase(ModulePrototypeBase):
    @property
    def projectname(self):
        raise NotImplementedError

    @property
    def rprojfolder(self):
        return os.path.relpath(self.projfolder, PROJECTS_ROOT)

    @property
    def desc(self):
        return self.configs.description(self.ident)

    @property
    def configs(self):
        if not self._configs:
            self._configs = ConfigsFile(self.projfolder)
        return self._configs

    @property
    def bom(self):
        if not self._bom:
            self._bom = EntityElnBom(self.configs)
            self._bom.configure_motifs(self.ident)
        return self._bom

    @property
    def obom(self):
        if not self._obom:
            self._obom = self.bom.create_output_bom(configname=self.ident)
        return self._obom

    def _get_status(self):
        raise NotImplementedError

    @property
    def _psctx(self):
        ctx = copy(self._validation_context)
        ctx.locality = 'Strategy'
        return ctx

    @property
    def _pspol_doc_am(self):
        return ConfigOptionPolicy(
            context=self._psctx, path=('documentation', 'am'),
            options=[True, False], is_error=True, default=True
        )

    @property
    def _pspol_testing(self):
        return ConfigOptionPolicy(
            context=self._psctx, path=('productionstrategy', 'testing'),
            options=['normal', 'lazy'], is_error=True, default='normal'
        )

    @property
    def _pspol_labelling(self):
        return ConfigOptionPolicy(
            context=self._psctx, path=('productionstrategy', 'labelling'),
            options=['normal', 'lazy'], is_error=True, default='normal'
        )

    @property
    def _pspol_labeldefs(self):
        return ConfigOptionPolicy(
            context=self._psctx, path=('documentation', 'labels'),
            options=None, is_error=True, default=None
        )

    def _get_production_strategy(self):
        rval = {}
        configdata = self.configs.rawconfig
        ec = ErrorCollector()

        try:
            am = get_dict_val(configdata, self._pspol_doc_am)
        except ValidationError as e:
            am = e.policy.default
            ec.add(e)
        if am is True:
            # Assembly manifest should be used
            rval['prodst'] = "@AM"
            rval['genmanifest'] = True
        else:
            # No Assembly manifest needed
            rval['prodst'] = "@THIS"
            rval['genmanifest'] = False

        try:
            testing = get_dict_val(configdata, self._pspol_testing)
        except ValidationError as e:
            testing = e.policy.default
            ec.add(e)
        if testing == 'normal':
            # Normal test procedure, Test when made
            rval['testst'] = "@NOW"
        if testing == 'lazy':
            # Lazy test procedure, Test when used
            rval['testst'] = "@USE"

        try:
            labelling = get_dict_val(configdata, self._pspol_labelling)
        except ValidationError as e:
            labelling = e.policy.default
            ec.add(e)
        if labelling == 'normal':
            # Normal test procedure, Label when made
            rval['lblst'] = "@NOW"
        if labelling == 'lazy':
            # Lazy test procedure, Label when used
            rval['lblst'] = "@USE"
        rval['genlabel'] = False
        rval['labels'] = []

        try:
            labeldefs = get_dict_val(configdata, self._pspol_labeldefs)
        except ValidationError as e:
            labeldefs = e.policy.default
            ec.add(e)

        if labeldefs is not None:
            if isinstance(labeldefs, dict):
                for k in sorted(labeldefs.keys()):
                    rval['labels'].append(
                        {'code': k,
                         'ident': self.ident + '.' + configdata['label'][k]}
                    )
                rval['genlabel'] = True
            elif isinstance(labeldefs, str):
                rval['labels'].append(
                    {'code': labeldefs,
                     'ident': self.ident}
                )
                rval['genlabel'] = True
        return rval

    def make_labels(self, sno, label_manager=None):
        # This does not check whether the sno is valid and correct and
        # so on. This should therefore not be called directly, but instead
        # the instance's makelabel function should be used.
        if label_manager is None:
            from tendril.dox.labelmaker import manager
            label_manager = manager
        if self.strategy['genlabel'] is True:
            for label in self.strategy['labels']:
                label_manager.add_label(
                    label['code'], label['ident'], sno
                )

    @property
    def _changelogpath(self):
        return os.path.join(self.projfolder, 'ChangeLog')

    @property
    def projfolder(self):
        return projects.cards[self.ident]

    @property
    def indicative_cost(self):
        return self.obom.indicative_cost

    @property
    def sourcing_errors(self):
        if self._sourcing_errors is None:
            self._sourcing_errors = self.obom.sourcing_errors
        return self._sourcing_errors

    @property
    def indicative_cost_breakup(self):
        return self.obom.indicative_cost_breakup

    @property
    def indicative_cost_hierarchical_breakup(self):
        try:
            return self.bom.indicative_cost_hierarchical_breakup(self.ident)
        except NoStructureHereException:
            return self.indicative_cost_breakup

    def _validate_obom(self, ec):
        # Final Validation of Output BOMs. This validation is of the
        # ultimate BOM generated, a last check after all possible
        # transformations are complete.

        # On-construction validation of OBOMs only includes the
        # specific mechanisms for construction and transformation,
        # and not validation of the output itself. The output is
        # therefore done here, at the very last minute.

        # NOTE Tentatively, validation errors are to be reported at the
        # instant when the data required to fully explain the error is
        # about to go out of immediately accessible scope.

        obom = self.obom
        ctx = copy(self._validation_context)
        ctx.locality = "OBOM"
        for line in obom.lines:
            policy = IdentPolicy(ctx, projects.is_recognized)
            try:
                policy.check(line.ident, line.refdeslist, self.status)
            except ValidationError as e:
                ec.add(e)
            policy = IdentQtyPolicy(ctx, True)
            try:
                temp = line.quantity
            except ValueError:
                ec.add(QuantityTypeError(policy, line.ident, line.refdeslist))

    def _validate(self):
        # One Time Validators
        temp = self.configs
        temp = self.status
        temp = self.strategy
        temp = self.changelog
        temp = self.bom

        # Validators for Reconstructed Structures
        lvalidation_errors = ErrorCollector()
        # Validate all OBOM line devices
        # Validate all OBOM line idents
        # Validate all OBOM line quantity types
        self._validate_obom(lvalidation_errors)
        self._sourcing_errors = self.obom.sourcing_errors
        # TODO Check for valid snoseries
        # TODO Check for empty groups?
        # TODO Check for unused motifs?
        # TODO Validate all motifs as configured
        # TODO Validate all SJs are accounted for
        # TODO Validate all Generators are expected
        # TODO Higher order configuration validation
        self._validated = True
        return lvalidation_errors

    @property
    def validation_errors(self):
        # Regenerate Validation reconstructed structures
        lverrors = self._validate()
        rval = ErrorCollector()
        rval.add(self._validation_errors)
        # Obtain validation errors from Configs load
        rval.add(self._configs.validation_errors)
        # Obtain validation errors collected during construction
        # from Parser -> BOM -> OBOM
        rval.add(self._obom.validation_errors)
        rval.add(lverrors)
        return rval

    @property
    def docs(self):
        return get_docs_list(self.projfolder, self.ident)
Ejemplo n.º 4
0
class EDAModulePrototypeBase(ModulePrototypeBase):
    @property
    def desc(self):
        return self.configs.description(self.ident)

    @property
    def configs(self):
        if not self._configs:
            self._configs = ConfigsFile(self.projfolder)
        return self._configs

    @property
    def bom(self):
        if not self._bom:
            self._bom = EntityElnBom(self.configs)
            self._bom.configure_motifs(self.ident)
        return self._bom

    @property
    def obom(self):
        if not self._obom:
            self._obom = self.bom.create_output_bom(configname=self.ident)
        return self._obom

    def _get_status(self):
        raise NotImplementedError

    @property
    def _psctx(self):
        ctx = copy(self._validation_context)
        ctx.locality = 'Strategy'
        return ctx

    @property
    def _pspol_doc_am(self):
        return ConfigOptionPolicy(
            context=self._psctx, path=('documentation', 'am'),
            options=[True, False], is_error=True, default=True
        )

    @property
    def _pspol_testing(self):
        return ConfigOptionPolicy(
            context=self._psctx, path=('productionstrategy', 'testing'),
            options=['normal', 'lazy'], is_error=True, default='normal'
        )

    @property
    def _pspol_labelling(self):
        return ConfigOptionPolicy(
            context=self._psctx, path=('productionstrategy', 'labelling'),
            options=['normal', 'lazy'], is_error=True, default='normal'
        )

    @property
    def _pspol_labeldefs(self):
        return ConfigOptionPolicy(
            context=self._psctx, path=('documentation', 'labels'),
            options=None, is_error=True, default=None
        )

    def _get_production_strategy(self):
        rval = {}
        configdata = self.configs.rawconfig
        ec = ErrorCollector()

        try:
            am = get_dict_val(configdata, self._pspol_doc_am)
        except ValidationError as e:
            am = e.policy.default
            ec.add(e)
        if am is True:
            # Assembly manifest should be used
            rval['prodst'] = "@AM"
            rval['genmanifest'] = True
        else:
            # No Assembly manifest needed
            rval['prodst'] = "@THIS"
            rval['genmanifest'] = False

        try:
            testing = get_dict_val(configdata, self._pspol_testing)
        except ValidationError as e:
            testing = e.policy.default
            ec.add(e)
        if testing == 'normal':
            # Normal test procedure, Test when made
            rval['testst'] = "@NOW"
        if testing == 'lazy':
            # Lazy test procedure, Test when used
            rval['testst'] = "@USE"

        try:
            labelling = get_dict_val(configdata, self._pspol_labelling)
        except ValidationError as e:
            labelling = e.policy.default
            ec.add(e)
        if labelling == 'normal':
            # Normal test procedure, Label when made
            rval['lblst'] = "@NOW"
        if labelling == 'lazy':
            # Lazy test procedure, Label when used
            rval['lblst'] = "@USE"
        rval['genlabel'] = False
        rval['labels'] = []

        try:
            labeldefs = get_dict_val(configdata, self._pspol_labeldefs)
        except ValidationError as e:
            labeldefs = e.policy.default
            ec.add(e)

        if labeldefs is not None:
            if isinstance(labeldefs, dict):
                for k in sorted(labeldefs.keys()):
                    rval['labels'].append(
                        {'code': k,
                         'ident': self.ident + '.' + configdata['label'][k]}
                    )
                rval['genlabel'] = True
            elif isinstance(labeldefs, str):
                rval['labels'].append(
                    {'code': labeldefs,
                     'ident': self.ident}
                )
                rval['genlabel'] = True
        return rval

    def make_labels(self, sno, label_manager=None):
        # This does not check whether the sno is valid and correct and
        # so on. This should therefore not be called directly, but instead
        # the instance's makelabel function should be used.
        if label_manager is None:
            from tendril.dox.labelmaker import manager
            label_manager = manager
        if self.strategy['genlabel'] is True:
            for label in self.strategy['labels']:
                label_manager.add_label(
                    label['code'], label['ident'], sno
                )

    @property
    def _changelogpath(self):
        return os.path.join(self.projfolder, 'ChangeLog')

    @property
    def projfolder(self):
        return projects.cards[self.ident]

    @property
    def indicative_cost(self):
        return self.obom.indicative_cost

    @property
    def sourcing_errors(self):
        if self._sourcing_errors is None:
            self._sourcing_errors = self.obom.sourcing_errors
        return self._sourcing_errors

    @property
    def indicative_cost_breakup(self):
        return self.obom.indicative_cost_breakup

    @property
    def indicative_cost_hierarchical_breakup(self):
        try:
            return self.bom.indicative_cost_hierarchical_breakup(self.ident)
        except NoStructureHereException:
            return self.indicative_cost_breakup

    def _validate_obom(self, ec):
        # Final Validation of Output BOMs. This validation is of the
        # ultimate BOM generated, a last check after all possible
        # transformations are complete.

        # On-construction validation of OBOMs only includes the
        # specific mechanisms for construction and transformation,
        # and not validation of the output itself. The output is
        # therefore done here, at the very last minute.

        # NOTE Tentatively, validation errors are to be reported at the
        # instant when the data required to fully explain the error is
        # about to go out of immediately accessible scope.

        obom = self.obom
        ctx = copy(self._validation_context)
        ctx.locality = "OBOM"
        for line in obom.lines:
            policy = IdentPolicy(ctx, projects.is_recognized)
            try:
                policy.check(line.ident, line.refdeslist, self.status)
            except ValidationError as e:
                ec.add(e)
            policy = IdentQtyPolicy(ctx, True)
            try:
                temp = line.quantity
            except ValueError:
                ec.add(QuantityTypeError(policy, line.ident, line.refdeslist))

    def _validate(self):
        # One Time Validators
        temp = self.configs
        temp = self.status
        temp = self.strategy
        temp = self.changelog
        temp = self.bom

        # Validators for Reconstructed Structures
        lvalidation_errors = ErrorCollector()
        # Validate all OBOM line devices
        # Validate all OBOM line idents
        # Validate all OBOM line quantity types
        self._validate_obom(lvalidation_errors)
        self._sourcing_errors = self.obom.sourcing_errors
        # TODO Check for empty groups?
        # TODO Check for unused motifs?
        # TODO Validate all motifs as configured
        # TODO Validate all SJs are accounted for
        # TODO Validate all Generators are expected
        # TODO Higher order configuration validation
        self._validated = True
        return lvalidation_errors

    @property
    def validation_errors(self):
        # Regenerate Validation reconstructed structures
        lverrors = self._validate()
        rval = ErrorCollector()
        rval.add(self._validation_errors)
        # Obtain validation errors from Configs load
        rval.add(self._configs.validation_errors)
        # Obtain validation errors collected during construction
        # from Parser -> BOM -> OBOM
        rval.add(self._obom.validation_errors)
        rval.add(lverrors)
        return rval

    @property
    def docs(self):
        return get_docs_list(self.projfolder, self.ident)