Esempio n. 1
0
 def setup(self, delta_order, force):
     self._sno = delta_order['sno']
     self._orig_modulename = delta_order['orig-cardname']
     self._target_modulename = delta_order['target-cardname']
     if self._orig_modulename == self._target_modulename:
         raise DeltaValidationError
     try:
         try:
             self._original = get_module_instance(self._sno,
                                                  self._orig_modulename,
                                                  session=self._session,
                                                  scaffold=force)
             self._target = get_module_prototype(self._target_modulename)
             self._is_done = False
         except ModuleInstanceTypeMismatchError:
             self._target = get_module_instance(self._sno,
                                                self._target_modulename,
                                                session=self._session,
                                                scaffold=force)
             self._original = get_module_prototype(self._orig_modulename)
             self._is_done = True
     except:
         # TODO a second delta on the same serial number will
         # make the first one fail. The entire delta architecture
         # may need to be thought through. Additionally, this
         # structure only handles deltas between cardnames, and
         # will go to hell in a handbasket if there are any
         # temporal changes to cards.
         raise DeltaValidationError
Esempio n. 2
0
 def setup(self, delta_order, force):
     self._sno = delta_order['sno']
     self._orig_modulename = delta_order['orig-cardname']
     self._target_modulename = delta_order['target-cardname']
     if self._orig_modulename == self._target_modulename:
         raise DeltaValidationError
     try:
         try:
             self._original = get_module_instance(
                     self._sno, self._orig_modulename,
                     session=self._session,
                     scaffold=force
             )
             self._target = get_module_prototype(self._target_modulename)
             self._is_done = False
         except ModuleInstanceTypeMismatchError:
             self._target = get_module_instance(
                     self._sno, self._target_modulename,
                     session=self._session,
                     scaffold=force
             )
             self._original = get_module_prototype(self._orig_modulename)
             self._is_done = True
     except:
         # TODO a second delta on the same serial number will
         # make the first one fail. The entire delta architecture
         # may need to be thought through. Additionally, this
         # structure only handles deltas between cardnames, and
         # will go to hell in a handbasket if there are any
         # temporal changes to cards.
         raise DeltaValidationError
Esempio n. 3
0
 def commit(self,
            outfolder=None,
            indent_sno=None,
            prod_ord_sno=None,
            register=False,
            pb_class=None,
            stacked_pb=False,
            leaf_pb=True,
            session=None):
     if self._is_done is True:
         raise NothingToProduceError
     self._generate_docs(outfolder, indent_sno, prod_ord_sno, register,
                         session)
     if register is True:
         serialnos.set_serialno_efield(sno=self._sno,
                                       efield=self._target_modulename,
                                       session=session)
         serialnos.link_serialno(child=self._sno,
                                 parent=prod_ord_sno,
                                 session=session)
         self._original = get_module_prototype(self._orig_modulename)
         self._target = get_module_instance(self._sno,
                                            self._target_modulename,
                                            session=session)
         self._is_done = True
Esempio n. 4
0
 def modules(self):
     return [
         get_module_instance(x,
                             self.ident,
                             scaffold=self._scaffold,
                             session=self._session) for x in self.refdes
     ]
Esempio n. 5
0
 def commit(self, outfolder=None, indent_sno=None, prod_ord_sno=None,
            register=False, pb_class=None, stacked_pb=False, leaf_pb=True,
            session=None):
     if self._is_done is True:
         raise NothingToProduceError
     self._generate_docs(outfolder, indent_sno, prod_ord_sno,
                         register, session)
     if register is True:
         serialnos.set_serialno_efield(
             sno=self._sno, efield=self._target_modulename,
             session=session
         )
         serialnos.link_serialno(
             child=self._sno, parent=prod_ord_sno, session=session
         )
         self._original = get_module_prototype(self._orig_modulename)
         self._target = get_module_instance(self._sno,
                                            self._target_modulename,
                                            session=session)
         self._is_done = True
Esempio n. 6
0
def gen_pcb_am(configname,
               outfolder,
               sno=None,
               productionorderno=None,
               indentsno=None,
               scaffold=False,
               verbose=True,
               session=None):
    """
    Generates a PCB Assembly Manifest for a 'card', a card being defined as a
    gEDA project, with a specified ``configname``.

    In the present implementation, the project could provide either a PCB or a
    Cable.

        - In case the project provides the card, the schematic for the cable
          is included along with the assembly manifest.
        - In case the project provides a PCB, the schematic is not included
          with the assembly manifest.

    This behavior is not really intuitive nor universally desirable. This
    rationale should be changed to something that makes more sense.

    .. note::
        This function does not register the document in the
        :mod:`tendril.dox.docstore`. You should use the output file path
        (returned by this function) to register the document when desired.

    .. seealso::
        - :mod:`tendril.gedaif.conffile`, for information about confignames.
        - :mod:`tendril.entityhub.projects`, for information about 'cards'

    .. todo:: Update this function to also handle registering once the main
              scripts are better integrated into the core.

    :param configname: The name of the project configuration to use.
    :type configname: str
    :param outfolder: The folder within which the output file should be
                      created.
    :type outfolder: str
    :param sno: The serial number of the card for which you want the Assembly
                Manifest.
    :type sno: str
    :param productionorderno: The serial number of the Production Order for
                              the card.
    :type productionorderno: str
    :param indentsno: The serial number of the Stock Indent which accounts for
                      the components used in this card.
    :type indentsno: str
    :return: The path of the generated file.

    .. rubric:: Template Used

    ``tendril/dox/templates/production/pcb-assem-manifest.tex``
    (:download:`Included version
    <../../tendril/dox/templates/production/pcb-assem-manifest.tex>`)

    .. rubric:: Stage Keys Provided
    .. list-table::

        * - ``sno``
          - The serial number of the card.
        * - ``configname``
          - The configuration name of the card.
        * - ``pcbname``
          - The name of the PCB provided by the gEDA project.
        * - ``title``
          - Whether the device is a PCB or a Cable.
        * - ``desc``
          - The description of the card.
        * - ``lines``
          - List of :class:`tendril.boms.outputbase.OutputBomLine` instances.
        * - ``stockindent``
          - The serial number of the Stock Indent which accounts for
            the components used in this card.
        * - ``productionorderno``
          - The serial number of the Production Order for the card.
        * - ``repopath``
          - The root of the VCS repository which contains the gEDA project.
        * - ``evenpages``
          - Whether to render PDF with even number of pages by adding an extra
            page if needed (useful for bulk printing).

    """
    if sno is None:
        # TODO Generate real S.No. here
        sno = 1

    outpath = os.path.join(outfolder,
                           'am-' + configname + '-' + str(sno) + '.pdf')

    instance = get_module_instance(sno,
                                   configname,
                                   scaffold=scaffold,
                                   session=session)
    obom = instance.obom

    if projects.check_module_is_card(configname):
        entityname = instance.pcbname
        title = 'PCB '
        evenpages = True
        add_schematic = False
    elif projects.check_module_is_cable(configname):
        entityname = instance.cblname
        title = 'Cable '
        evenpages = False
        add_schematic = True
    else:
        raise ValueError

    stage = {
        'configname': obom.descriptor.configname,
        'pcbname': entityname,
        'title': title,
        'sno': sno,
        'lines': obom.lines,
        'evenpages': evenpages,
        'stockindent': indentsno,
        'repopath': projects.get_project_repo_repr(configname),
        'productionorderno': productionorderno
    }

    for config in obom.descriptor.configurations.configurations:
        if config['configname'] == configname:
            stage['desc'] = config['desc']

    template = 'production/pcb-assem-manifest.tex'

    render.render_pdf(stage, template, outpath, verbose=verbose)

    if add_schematic is True:
        merge_pdf([
            outpath,
            os.path.join(instance.projfolder, 'doc',
                         entityname + '-schematic.pdf')
        ], outpath)
    return outpath
Esempio n. 7
0
def gen_delta_pcb_am(orig_cardname,
                     target_cardname,
                     outfolder=None,
                     sno=None,
                     productionorderno=None,
                     indentsno=None,
                     scaffold=False,
                     verbose=True,
                     session=None):
    """
    Generates a Delta PCB Assembly Manifest for converting one card to
    another. This is typically only useful when the two cards are very
    closely related and use the same PCB..

    In the present implementation, the cardname could represent either a PCB
    or a Cable.

    .. note::
        This function does not register the document in the
        :mod:`tendril.dox.docstore`. You should use the output file path
        (returned by this function) to register the document when desired.

    .. seealso::
        - :mod:`tendril.entityhub.projects`, for information about 'cards'

    .. todo:: Update this function to also handle registering once the main
              scripts are better integrated into the core.

    :param orig_cardname: The name of the original card. This should be
                              present in :data:`entityhub.projects.cards`
    :type orig_cardname: str
    :param target_cardname: The name of the target card. This should be
                              present in :data:`entityhub.projects.cards`
    :type target_cardname: str
    :param outfolder: The folder within which the output file should be
                      created.
    :type outfolder: str
    :param sno: The serial number of the card for which you want the Delta
                Assembly Manifest.
    :type sno: str
    :param productionorderno: The serial number of the Production Order for
                              the modification.
    :type productionorderno: str
    :param indentsno: The serial number of the Stock Indent which accounts for
                      the components used in this card.
    :type indentsno: str
    :return: The path of the generated file.

    .. rubric:: Template Used

    ``tendril/dox/templates/production/delta-assem-manifest.tex``
    (:download:`Included version
    <../../tendril/dox/templates/production/delta-assem-manifest.tex>`)

    .. rubric:: Stage Keys Provided
    .. list-table::

        * - ``sno``
          - The serial number of the card.
        * - ``orig_configname``
          - The configuration name of the original card.
        * - ``target_configname``
          - The configuration name of the target card.
        * - ``pcbname``
          - The name of the original PCB.
        * - ``title``
          - Whether the device is a PCB or a Cable.
        * - ``desc``
          - The description of the modification.
        * - ``addition_lines``
          - List of :class:`tendril.boms.outputbase.OutputBomLine` instances.
        * - ``subtraction_lines``
          - List of :class:`tendril.boms.outputbase.OutputBomLine` instances.
        * - ``stockindent``
          - The serial number of the Stock Indent which accounts for
            the components used in this card.
        * - ``productionorderno``
          - The serial number of the Production Order for the card.
        * - ``original_repopath``
          - The root of the VCS repository which contains the original gEDA project.
        * - ``target_repopath``
          - The root of the VCS repository which contains the target gEDA project.
        * - ``evenpages``
          - Whether to render PDF with even number of pages by adding an extra
            page if needed (useful for bulk printing).

    """

    if outfolder is None:
        from tendril.config.legacy import INSTANCE_ROOT
        outfolder = os.path.join(INSTANCE_ROOT, 'scratch', 'production')

    if sno is None:
        # TODO Generate real S.No. here
        sno = 1

    outpath = os.path.join(
        outfolder, 'dm-' + orig_cardname + '->' + target_cardname + '-' +
        str(sno) + '.pdf')

    orig_instance = get_module_instance(sno,
                                        orig_cardname,
                                        session=session,
                                        scaffold=True)
    orig_obom = orig_instance.obom
    target_instance = get_module_prototype(target_cardname)
    target_obom = target_instance.obom

    delta_obom = DeltaOutputBom(orig_obom, target_obom)

    if projects.check_module_is_card(orig_cardname):
        orig_entityname = orig_instance.pcbname
        try:
            target_entityname = target_instance.pcbname
        except AttributeError:
            logger.error("Target for the delta should be a PCB!")
            raise
        title = 'PCB '
        evenpages = True
    elif projects.check_module_is_cable(orig_cardname):
        orig_entityname = orig_instance.cblname
        try:
            target_entityname = target_instance.cblname
        except AttributeError:
            logger.error("Target for the delta should be a Cable!")
            raise
        title = 'Cable '
        evenpages = False
    else:
        raise ValueError

    stage = {
        'orig_configname': orig_cardname,
        'target_configname': target_cardname,
        'pcbname': orig_entityname,
        'title': title,
        'sno': sno,
        'addition_lines': delta_obom.additions_bom.lines,
        'subtraction_lines': delta_obom.subtractions_bom.lines,
        'evenpages': evenpages,
        'stockindent': indentsno,
        'orig_repopath': projects.get_project_repo_repr(orig_cardname),
        'target_repopath':
        projects.get_project_repo_repr(target_cardname),  # noqa
        'productionorderno': productionorderno,
        'desc': delta_obom.descriptor.configname
    }

    template = 'production/delta-assem-manifest.tex'

    render.render_pdf(stage, template, outpath, verbose=verbose)
    return outpath
Esempio n. 8
0
 def modules(self):
     return [
         get_module_instance(x,
                             self._target_modulename,
                             session=self._session) for x in self.refdes
     ]
Esempio n. 9
0
 def modules(self):
     return [get_module_instance(x, self._target_modulename,
                                 session=self._session)
             for x in self.refdes]
Esempio n. 10
0
 def modules(self):
     return [get_module_instance(x, self.ident,
                                 scaffold=self._scaffold,
                                 session=self._session)
             for x in self.refdes]
Esempio n. 11
0
def gen_pcb_am(configname, outfolder, sno=None, productionorderno=None,
               indentsno=None, scaffold=False, verbose=True, session=None):
    """
    Generates a PCB Assembly Manifest for a 'card', a card being defined as a
    gEDA project, with a specified ``configname``.

    In the present implementation, the project could provide either a PCB or a
    Cable.

        - In case the project provides the card, the schematic for the cable
          is included along with the assembly manifest.
        - In case the project provides a PCB, the schematic is not included
          with the assembly manifest.

    This behavior is not really intuitive nor universally desirable. This
    rationale should be changed to something that makes more sense.

    .. note::
        This function does not register the document in the
        :mod:`tendril.dox.docstore`. You should use the output file path
        (returned by this function) to register the document when desired.

    .. seealso::
        - :mod:`tendril.gedaif.conffile`, for information about confignames.
        - :mod:`tendril.entityhub.projects`, for information about 'cards'

    .. todo:: Update this function to also handle registering once the main
              scripts are better integrated into the core.

    :param configname: The name of the project configuration to use.
    :type configname: str
    :param outfolder: The folder within which the output file should be
                      created.
    :type outfolder: str
    :param sno: The serial number of the card for which you want the Assembly
                Manifest.
    :type sno: str
    :param productionorderno: The serial number of the Production Order for
                              the card.
    :type productionorderno: str
    :param indentsno: The serial number of the Stock Indent which accounts for
                      the components used in this card.
    :type indentsno: str
    :return: The path of the generated file.

    .. rubric:: Template Used

    ``tendril/dox/templates/production/pcb-assem-manifest.tex``
    (:download:`Included version
    <../../tendril/dox/templates/production/pcb-assem-manifest.tex>`)

    .. rubric:: Stage Keys Provided
    .. list-table::

        * - ``sno``
          - The serial number of the card.
        * - ``configname``
          - The configuration name of the card.
        * - ``pcbname``
          - The name of the PCB provided by the gEDA project.
        * - ``title``
          - Whether the device is a PCB or a Cable.
        * - ``desc``
          - The description of the card.
        * - ``lines``
          - List of :class:`tendril.boms.outputbase.OutputBomLine` instances.
        * - ``stockindent``
          - The serial number of the Stock Indent which accounts for
            the components used in this card.
        * - ``productionorderno``
          - The serial number of the Production Order for the card.
        * - ``repopath``
          - The root of the VCS repository which contains the gEDA project.
        * - ``evenpages``
          - Whether to render PDF with even number of pages by adding an extra
            page if needed (useful for bulk printing).

    """
    if sno is None:
        # TODO Generate real S.No. here
        sno = 1

    outpath = os.path.join(outfolder,
                           'am-' + configname + '-' + str(sno) + '.pdf')

    instance = get_module_instance(sno, configname,
                                   scaffold=scaffold, session=session)
    obom = instance.obom

    if projects.check_module_is_card(configname):
        entityname = instance.pcbname
        title = 'PCB '
        evenpages = True
        add_schematic = False
    elif projects.check_module_is_cable(configname):
        entityname = instance.cblname
        title = 'Cable '
        evenpages = False
        add_schematic = True
    else:
        raise ValueError

    stage = {'configname': obom.descriptor.configname,
             'pcbname': entityname,
             'title': title,
             'sno': sno,
             'lines': obom.lines,
             'evenpages': evenpages,
             'stockindent': indentsno,
             'repopath': projects.get_project_repo_repr(configname),
             'productionorderno': productionorderno}

    for config in obom.descriptor.configurations.configurations:
        if config['configname'] == configname:
            stage['desc'] = config['desc']

    template = 'production/pcb-assem-manifest.tex'

    render.render_pdf(stage, template, outpath, verbose=verbose)

    if add_schematic is True:
        merge_pdf([outpath,
                   os.path.join(instance.projfolder, 'doc',
                                entityname + '-schematic.pdf')],
                  outpath)
    return outpath
Esempio n. 12
0
def gen_delta_pcb_am(orig_cardname, target_cardname, outfolder=None, sno=None,
                     productionorderno=None, indentsno=None, scaffold=False,
                     verbose=True, session=None):
    """
    Generates a Delta PCB Assembly Manifest for converting one card to
    another. This is typically only useful when the two cards are very
    closely related and use the same PCB..

    In the present implementation, the cardname could represent either a PCB
    or a Cable.

    .. note::
        This function does not register the document in the
        :mod:`tendril.dox.docstore`. You should use the output file path
        (returned by this function) to register the document when desired.

    .. seealso::
        - :mod:`tendril.entityhub.projects`, for information about 'cards'

    .. todo:: Update this function to also handle registering once the main
              scripts are better integrated into the core.

    :param orig_cardname: The name of the original card. This should be
                              present in :data:`entityhub.projects.cards`
    :type orig_cardname: str
    :param target_cardname: The name of the target card. This should be
                              present in :data:`entityhub.projects.cards`
    :type target_cardname: str
    :param outfolder: The folder within which the output file should be
                      created.
    :type outfolder: str
    :param sno: The serial number of the card for which you want the Delta
                Assembly Manifest.
    :type sno: str
    :param productionorderno: The serial number of the Production Order for
                              the modification.
    :type productionorderno: str
    :param indentsno: The serial number of the Stock Indent which accounts for
                      the components used in this card.
    :type indentsno: str
    :return: The path of the generated file.

    .. rubric:: Template Used

    ``tendril/dox/templates/production/delta-assem-manifest.tex``
    (:download:`Included version
    <../../tendril/dox/templates/production/delta-assem-manifest.tex>`)

    .. rubric:: Stage Keys Provided
    .. list-table::

        * - ``sno``
          - The serial number of the card.
        * - ``orig_configname``
          - The configuration name of the original card.
        * - ``target_configname``
          - The configuration name of the target card.
        * - ``pcbname``
          - The name of the original PCB.
        * - ``title``
          - Whether the device is a PCB or a Cable.
        * - ``desc``
          - The description of the modification.
        * - ``addition_lines``
          - List of :class:`tendril.boms.outputbase.OutputBomLine` instances.
        * - ``subtraction_lines``
          - List of :class:`tendril.boms.outputbase.OutputBomLine` instances.
        * - ``stockindent``
          - The serial number of the Stock Indent which accounts for
            the components used in this card.
        * - ``productionorderno``
          - The serial number of the Production Order for the card.
        * - ``original_repopath``
          - The root of the VCS repository which contains the original gEDA project.
        * - ``target_repopath``
          - The root of the VCS repository which contains the target gEDA project.
        * - ``evenpages``
          - Whether to render PDF with even number of pages by adding an extra
            page if needed (useful for bulk printing).

    """

    if outfolder is None:
        from tendril.utils.config import INSTANCE_ROOT
        outfolder = os.path.join(INSTANCE_ROOT, 'scratch', 'production')

    if sno is None:
        # TODO Generate real S.No. here
        sno = 1

    outpath = os.path.join(
            outfolder,
            'dm-' + orig_cardname + '->' + target_cardname +
            '-' + str(sno) + '.pdf'
    )

    orig_instance = get_module_instance(sno, orig_cardname,
                                        session=session, scaffold=True)
    orig_obom = orig_instance.obom
    target_instance = get_module_prototype(target_cardname)
    target_obom = target_instance.obom

    delta_obom = DeltaOutputBom(orig_obom, target_obom)

    if projects.check_module_is_card(orig_cardname):
        orig_entityname = orig_instance.pcbname
        try:
            target_entityname = target_instance.pcbname
        except AttributeError:
            logger.error("Target for the delta should be a PCB!")
            raise
        title = 'PCB '
        evenpages = True
    elif projects.check_module_is_cable(orig_cardname):
        orig_entityname = orig_instance.cblname
        try:
            target_entityname = target_instance.cblname
        except AttributeError:
            logger.error("Target for the delta should be a Cable!")
            raise
        title = 'Cable '
        evenpages = False
    else:
        raise ValueError

    stage = {'orig_configname': orig_cardname,
             'target_configname': target_cardname,
             'pcbname': orig_entityname,
             'title': title,
             'sno': sno,
             'addition_lines': delta_obom.additions_bom.lines,
             'subtraction_lines': delta_obom.subtractions_bom.lines,
             'evenpages': evenpages,
             'stockindent': indentsno,
             'orig_repopath': projects.get_project_repo_repr(orig_cardname),
             'target_repopath': projects.get_project_repo_repr(target_cardname),  # noqa
             'productionorderno': productionorderno,
             'desc': delta_obom.descriptor.configname}

    template = 'production/delta-assem-manifest.tex'

    render.render_pdf(stage, template, outpath, verbose=verbose)
    return outpath