Ejemplo n.º 1
0
def gen_mapfile(vendor, idents, maxage=-1):
    pb = TendrilProgressBar(max=len(idents))
    vendor_obj = controller.get_vendor(name=vendor.cname)
    for ident in idents:
        pb.next(note=ident)
        vpnos, strategy = vendor.search_vpnos(ident)
        if vpnos is not None:
            # pb.writeln("Found: {0}\n".format(ident))
            avpnos = vpnos
        else:
            if strategy not in ['NODEVICE', 'NOVALUE', 'NOT_IMPL']:
                pb.writeln("Not Found: {0:40}::{1}\n".format(ident, strategy))
            avpnos = []
        with get_session() as session:
            # pb.writeln("{0:25} {1}\n".format(ident, avpnos))
            controller.set_strategy(vendor=vendor_obj,
                                    ident=ident,
                                    strategy=strategy,
                                    session=session)
            controller.set_amap_vpnos(vendor=vendor_obj,
                                      ident=ident,
                                      vpnos=avpnos,
                                      session=session)
    pb.finish()
    vendor.map._dump_mapfile()
Ejemplo n.º 2
0
    def search_vpnos(self, ident):
        parts, strategy = self._search_vpnos(ident)
        if parts is None:
            return None, strategy
        pnos = [x.pno for x in parts]

        try:
            # TODO Figure out how the mouser impl works without this mess :|
            with get_session() as s:
                dbvobj = controller.get_vendor(name=self.cname)
                controller.set_strategy(vendor=dbvobj,
                                        ident=ident,
                                        strategy=strategy,
                                        session=s)
                controller.set_amap_vpnos(vendor=dbvobj,
                                          ident=ident,
                                          vpnos=pnos,
                                          session=s)
                for part in parts:
                    partobj = self._partclass(part.pno,
                                              ident=ident,
                                              vendor=self,
                                              max_age=None,
                                              shell_only=True)
                    partobj.load_from_response(part.raw)
                    partobj.commit(session=s)
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            raise

        return pnos, strategy
Ejemplo n.º 3
0
 def get_vpnos(self, ident, max_age=VENDOR_DEFAULT_MAXAGE):
     if ident in self._ident_blacklist:
         return []
     acquire = False
     mtime = self._map.get_map_time(canonical=ident)
     if max_age > 0:
         now = time.time()
         if not mtime:
             acquire = True
         elif now - mtime > max_age:
             maintenance.update_vpmap(self.cname, ident)
     elif max_age == 0 or mtime is None:
         acquire = True
     if acquire is True:
         try:
             vpnos, strategy = self.search_vpnos(ident)
             if not vpnos:
                 vpnos = []
             with get_session() as session:
                 controller.set_strategy(vendor=self._name,
                                         ident=ident,
                                         strategy=strategy,
                                         session=session)
                 controller.set_amap_vpnos(vendor=self._name,
                                           ident=ident,
                                           vpnos=vpnos,
                                           session=session)
         except (NotImplementedError, URLError, HTTPError):
             pass
     return self._map.get_partnos(ident)
Ejemplo n.º 4
0
def new_production_order():
    form = CreateProductionOrderForm()
    stage = {'crumbroot': '/production'}
    if form.validate_on_submit():
        try:
            sno = form.prod_order_sno.sno.data
            with get_session() as session:
                title = form.prod_order_title.data.strip()
                if not sno:
                    sno = get_serialno(series='PROD', efield=title,
                                       register=True, session=session)
                else:
                    # additional sno validation?
                    pass

                cards = {x['ident']: int(x['qty']) for x in form.modules.data if x['ident']}
                deltas = [{'orig-cardname': x['orig_cardname'],
                           'target-cardname': x['target_cardname'],
                           'sno': x['sno']}
                          for x in form.deltas.data if x['sno']]
                requested_by = get_username_from_full_name(full_name=form.user.data,
                                                           session=session)
                # Construct Production Order
                prod_order = order.ProductionOrder(sno=sno)
                prod_order.create(
                    title=form.prod_order_title.data.strip(),
                    desc=form.desc.data.strip(),
                    cards=cards,
                    deltas=deltas,
                    sourcing_order_snos=None,
                    root_order_snos=form.root_order_sno.data,
                    ordered_by=requested_by,
                )
                # Check for Authorization
                # Nothing right now.
                # Create Order

                # TODO detach at this point
                fe_workspace_path = os.path.join(TEMPDIR, 'frontend')
                if not os.path.exists(fe_workspace_path):
                    os.makedirs(fe_workspace_path)
                workspace_path = os.path.join(fe_workspace_path, get_tempname())
                os.makedirs(workspace_path)
                prod_order.process(outfolder=workspace_path,
                                   register=True, session=session)
                shutil.rmtree(workspace_path)
                # Redirect to Created Order
            return redirect(url_for('.production_orders', order_sno=str(sno)))
        except AuthChainNotValidError:
            stage['auth_not_valid'] = True

    stage_crumbs = {'breadcrumbs': [Crumb(name="Production", path=""),
                                    Crumb(name="Orders", path="order/"),
                                    Crumb(name="New", path="order/new")],
                    }
    stage.update(stage_crumbs)
    pagetitle = "Create New Production Order"
    return render_template('production_order_new.html', stage=stage, form=form,
                           pagetitle=pagetitle)
Ejemplo n.º 5
0
 def process(self, session=None, **kwargs):
     if self._defined is True and self._force is False:
         raise Exception("This inventory indent instance seems to be already "
                         "done. You can't 'create' it again.")
     if session is None:
         with get_session() as session:
             return self._process(session=session, **kwargs)
     else:
         return self._process(session=session, **kwargs)
Ejemplo n.º 6
0
 def process(self, session=None, **kwargs):
     if self._defined is True and self._force is False:
         raise Exception(
             "This inventory indent instance seems to be already "
             "done. You can't 'create' it again.")
     if session is None:
         with get_session() as session:
             return self._process(session=session, **kwargs)
     else:
         return self._process(session=session, **kwargs)
Ejemplo n.º 7
0
def main():
    """
    The tendril-testresult script entry point.
    """
    parser = _get_parser()
    args = parser.parse_args()
    with get_session() as s:
        suites = analysis.get_test_suite_objects(serialno=args.serialno,
                                                 session=s)
        for suite in suites:
            suite.finish()
Ejemplo n.º 8
0
    def process(self, session=None, **kwargs):
        force = self._force
        if self._defined is True and force is False:
            raise Exception("This production order instance seems to be "
                            "already defined. You can't 'create' it again.")

        if session is None:
            with get_session() as session:
                return self._process(session=session, **kwargs)
        else:
            return self._process(session=session, **kwargs)
Ejemplo n.º 9
0
def main():
    """
    The tendril-testresult script entry point.
    """
    parser = _get_parser()
    args = parser.parse_args()
    with get_session() as s:
        suites = analysis.get_test_suite_objects(
                serialno=args.serialno, session=s
        )
        for suite in suites:
            suite.finish()
Ejemplo n.º 10
0
def populate_inventorylocationcodes():
    logger.info("Populating Inventory Location Codes")
    for location in INVENTORY_LOCATIONS:
        with get_session() as session:
            if not session.query(exists().where(
                    InventoryLocationCode.name == location)).scalar():
                logger.info("Creating location code for : " + location)
                obj = InventoryLocationCode(name=location)
                session.add(obj)
            else:
                logger.debug("Found preexisting location code for : " +
                             location)
Ejemplo n.º 11
0
 def _get_prod_ord_sno_legacy(self):
     with get_session() as s:
         parents = serialnos.get_parent_serialnos(sno=self._sno, session=s)
         prod_sno = None
         for parent in parents:
             # TODO Change this to look for well defined production
             # orders or migrate to the new structure where the DB
             # maintains the correct mappings.
             if parent.parent.sno.startswith('PROD'):
                 prod_sno = parent.parent.sno
                 break
     if not prod_sno:
         prod_sno = None
     self._prod_order_sno = prod_sno
Ejemplo n.º 12
0
def populate_inventorylocationcodes():
    logger.info("Populating Inventory Location Codes")
    for location in INVENTORY_LOCATIONS:
        with get_session() as session:
            if not session.query(
                    exists().where(
                        InventoryLocationCode.name == location)
            ).scalar():
                logger.info("Creating location code for : " + location)
                obj = InventoryLocationCode(name=location)
                session.add(obj)
            else:
                logger.debug("Found preexisting location code for : " +
                             location)
Ejemplo n.º 13
0
 def _get_prod_ord_sno_legacy(self):
     with get_session() as s:
         parents = serialnos.get_parent_serialnos(sno=self._sno, session=s)
         prod_sno = None
         for parent in parents:
             # TODO Change this to look for well defined production
             # orders or migrate to the new structure where the DB
             # maintains the correct mappings.
             if parent.parent.sno.startswith('PROD'):
                 prod_sno = parent.parent.sno
                 break
     if not prod_sno:
         prod_sno = None
     self._prod_order_sno = prod_sno
Ejemplo n.º 14
0
def get_inventorylocationcode(name, create=False):
    with get_session() as session:
        try:
            return session.query(InventoryLocationCode).filter_by(
                name=name).one().id
        except MultipleResultsFound:
            logger.warning("Found Multiple Codes for Inventory Location : " +
                           name)
        except NoResultFound:
            if create is True:
                obj = InventoryLocationCode(name=name)
                session.add(obj)
                return obj.id
            else:
                return None
Ejemplo n.º 15
0
def get_inventorylocationcode(name, create=False):
    with get_session() as session:
        try:
            return session.query(
                InventoryLocationCode).filter_by(name=name).one().id
        except MultipleResultsFound:
            logger.warning("Found Multiple Codes for Inventory Location : " +
                           name)
        except NoResultFound:
            if create is True:
                obj = InventoryLocationCode(name=name)
                session.add(obj)
                return obj.id
            else:
                return None
Ejemplo n.º 16
0
 def get_vpnos(self, ident, max_age=600000):
     mtime = self._map.get_map_time(canonical=ident)
     now = time.time()
     if not mtime or now - mtime > max_age:
         # TODO Pass on request to vendor maintenance queue instead
         try:
             vpnos, strategy = self.search_vpnos(ident)
             if not vpnos:
                 vpnos = []
             with get_session() as session:
                 controller.set_strategy(vendor=self._name, ident=ident,
                                         strategy=strategy, session=session)
                 controller.set_amap_vpnos(vendor=self._name, ident=ident,
                                           vpnos=vpnos, session=session)
         except (NotImplementedError, URLError, HTTPError):
             pass
     return self._map.get_partnos(ident)
Ejemplo n.º 17
0
 def _populate(self, max_age):
     if self._vendor is not None and self._canonical_repr is not None:
         with get_session() as s:
             # TODO Allow max_age = -1 for don't care
             if max_age > 0:
                 try:
                     self.load_from_db(max_age, s)
                     return
                 except DBPartDataUnusable:
                     pass
             self._get_data()
             try:
                 self.commit(s)
             except NoResultFound:
                 pass
     else:
         self._get_data()
Ejemplo n.º 18
0
def populate_vendors():
    logger.info("Populating Sourcing Vendors")
    for vendor in VENDORS_DATA:
        with get_session() as session:
            if not session.query(exists().where(
                    SourcingVendor.name == vendor['name'])).scalar():
                logger.info("Creating vendor entry for : " + vendor['name'])
                obj = SourcingVendor(name=vendor['name'],
                                     dname=vendor['dname'],
                                     type=vendor['vtype'],
                                     mapfile_base=vendor['name'],
                                     pclass=vendor['pclass'],
                                     status='active')
                session.add(obj)
            else:
                logger.debug("Found preexisting vendor entry for : " +
                             vendor['name'])
Ejemplo n.º 19
0
def populate_vendors():
    logger.info("Populating Sourcing Vendors")
    for vendor in VENDORS_DATA:
        with get_session() as session:
            if not session.query(
                    exists().where(
                        SourcingVendor.name == vendor['name'])
            ).scalar():
                logger.info("Creating vendor entry for : " + vendor['name'])
                obj = SourcingVendor(name=vendor['name'],
                                     dname=vendor['dname'],
                                     type=vendor['type'],
                                     mapfile_base=vendor['name'],
                                     pclass=vendor['pclass'],
                                     status='active')
                session.add(obj)
            else:
                logger.debug("Found preexisting vendor entry for : " +
                             vendor['name'])
Ejemplo n.º 20
0
 def _populate(self, max_age=VENDOR_DEFAULT_MAXAGE):
     if self._vendor is not None and self._canonical_repr is not None:
         with get_session() as s:
             try:
                 self.load_from_db(max_age, s)
                 return
             except DBPartDataUnusable:
                 try:
                     self._get_data()
                 except VendorPartInaccessibleError:
                     # Part cannot be accessed directly.
                     # TODO Map must be updated instead.
                     self.load_from_db(-1, s)
                     return
                 try:
                     self.commit(s)
                 except NoResultFound:
                     pass
     else:
         self._get_data()
Ejemplo n.º 21
0
def gen_mapfile(vendor, idents):
    pb = TendrilProgressBar(max=len(idents))
    vendor_obj = controller.get_vendor(name=vendor._name)
    for ident in idents:
        pb.next(note=ident)
        vpnos, strategy = vendor.search_vpnos(ident)
        if vpnos is not None:
            # pb.writeln("Found: {0}\n".format(ident))
            avpnos = vpnos
        else:
            if strategy not in ['NODEVICE', 'NOVALUE',
                                'NOT_IMPL']:
                pb.writeln("Not Found: {0:40}::{1}\n".format(ident, strategy))
            avpnos = []
        with get_session() as session:
            # pb.writeln("{0:25} {1}\n".format(ident, avpnos))
            controller.set_strategy(vendor=vendor_obj, ident=ident,
                                    strategy=strategy, session=session)
            controller.set_amap_vpnos(vendor=vendor_obj, ident=ident,
                                      vpnos=avpnos, session=session)
    pb.finish()
    vendor.map._dump_mapfile()
Ejemplo n.º 22
0
 def commit(self, session=None):
     if session is None:
         with get_session() as s:
             self._commit_to_db(session=s)
     else:
         self._commit_to_db(session=session)
Ejemplo n.º 23
0
 def load(self, verbose=True, session=None):
     if session is None:
         with get_session() as session:
             self._load(session=session, verbose=verbose)
     else:
         self._load(session=session, verbose=verbose)
Ejemplo n.º 24
0
 def load_from_db(self, session=None):
     if not session:
         with get_session() as session:
             self._load_from_db(session)
     else:
         self._load_from_db(session)
Ejemplo n.º 25
0
 def load_from_db(self, session=None):
     if not session:
         with get_session() as session:
             self._load_from_db(session)
     else:
         self._load_from_db(session)
Ejemplo n.º 26
0
 def load(self, verbose=True, session=None):
     if session is None:
         with get_session() as session:
             self._load(session=session, verbose=verbose)
     else:
         self._load(session=session, verbose=verbose)
Ejemplo n.º 27
0
 def commit(self, session=None):
     if session is None:
         with get_session() as s:
             self._commit_to_db(session=s)
     else:
         self._commit_to_db(session=session)
Ejemplo n.º 28
0
 def load_from_db(self, max_age, session=None):
     if session is None:
         with get_session() as s:
             self._load_from_db(max_age, session=s)
     else:
         self._load_from_db(max_age, session=session)
Ejemplo n.º 29
0
def new_production_order():
    form = CreateProductionOrderForm()
    stage = {'crumbroot': '/production'}
    if form.validate_on_submit():
        try:
            sno = form.prod_order_sno.sno.data
            with get_session() as session:
                title = form.prod_order_title.data.strip()
                if not sno:
                    sno = get_serialno(series='PROD',
                                       efield=title,
                                       register=True,
                                       session=session)
                else:
                    # additional sno validation?
                    pass

                cards = {
                    x['ident']: int(x['qty'])
                    for x in form.modules.data if x['ident']
                }
                deltas = [{
                    'orig-cardname': x['orig_cardname'],
                    'target-cardname': x['target_cardname'],
                    'sno': x['sno']
                } for x in form.deltas.data if x['sno']]
                requested_by = get_username_from_full_name(
                    full_name=form.user.data, session=session)
                # Construct Production Order
                prod_order = order.ProductionOrder(sno=sno)
                prod_order.create(
                    title=form.prod_order_title.data.strip(),
                    desc=form.desc.data.strip(),
                    cards=cards,
                    deltas=deltas,
                    sourcing_order_snos=None,
                    root_order_snos=form.root_order_sno.data,
                    ordered_by=requested_by,
                )
                # Check for Authorization
                # Nothing right now.
                # Create Order

                # TODO detach at this point
                fe_workspace_path = os.path.join(TEMPDIR, 'frontend')
                if not os.path.exists(fe_workspace_path):
                    os.makedirs(fe_workspace_path)
                workspace_path = os.path.join(fe_workspace_path,
                                              get_tempname())
                os.makedirs(workspace_path)
                prod_order.process(outfolder=workspace_path,
                                   register=True,
                                   session=session)
                shutil.rmtree(workspace_path)
                # Redirect to Created Order
            return redirect(url_for('.production_orders', order_sno=str(sno)))
        except AuthChainNotValidError:
            stage['auth_not_valid'] = True

    stage_crumbs = {
        'breadcrumbs': [
            Crumb(name="Production", path=""),
            Crumb(name="Orders", path="order/"),
            Crumb(name="New", path="order/new")
        ],
    }
    stage.update(stage_crumbs)
    pagetitle = "Create New Production Order"
    return render_template('production_order_new.html',
                           stage=stage,
                           form=form,
                           pagetitle=pagetitle)
Ejemplo n.º 30
0
def new_indent(indent_sno=None):
    form = CreateIndentForm(parent_indent_sno=indent_sno)
    stage = {'crumbroot': '/inventory'}
    if form.validate_on_submit():
        try:
            with get_session() as session:
                sno = form.indent_sno.sno.data
                if not sno:
                    if indent_sno is not None:
                        sno = form.get_supplementary_sno_default()
                        register_serialno(sno=sno,
                                          efield="WEB FRONTEND INDENT",
                                          session=session)
                    else:
                        sno = get_serialno(series='IDT',
                                           efield='WEB FRONTEND INDENT',
                                           register=True,
                                           session=session)
                else:
                    # additional sno validation?
                    pass
                nindent = InventoryIndent(sno=sno, session=session)
                # Construct COBOM
                obom = create_obom_from_listing(form.components.data,
                                                'MANUAL (WEB)')
                cobom = CompositeOutputBom([obom],
                                           name='MANUAL (WEB) {0}'.format(sno))

                requested_by = get_username_from_full_name(
                    full_name=form.user.data, session=session)

                icparams = {
                    'cobom': cobom,
                    'title': form.indent_title.data,
                    'desc': form.indent_desc.data,
                    'requested_by': requested_by,
                    'rdate': form.rdate.data or arrow.utcnow(),
                    'indent_type': form.indent_type.data,
                }
                nindent.create(**icparams)

                root_order_sno = form.root_order_sno.data
                prod_order_sno = form.prod_order_sno.data
                try:
                    nindent.define_auth_chain(prod_order_sno=prod_order_sno,
                                              root_order_sno=root_order_sno,
                                              session=session)
                except AuthChainNotValidError:
                    raise
                nindent.register_auth_chain(session=session)

                fe_workspace_path = os.path.join(TEMPDIR, 'frontend')
                if not os.path.exists(fe_workspace_path):
                    os.makedirs(fe_workspace_path)
                workspace_path = os.path.join(fe_workspace_path,
                                              get_tempname())
                os.makedirs(workspace_path)

                nindent.process(outfolder=workspace_path,
                                register=True,
                                session=session)

                shutil.rmtree(workspace_path)
            return redirect(url_for('.indent', indent_sno=str(sno)))
        except AuthChainNotValidError:
            stage['auth_not_valid'] = True

    if indent_sno is None:
        stage_crumbs = {
            'breadcrumbs': [
                Crumb(name="Inventory", path=""),
                Crumb(name="Indent", path="indent/"),
                Crumb(name="New", path="indent/new")
            ],
        }
        pagetitle = "Create New Indent"
    else:
        stage_crumbs = {
            'breadcrumbs': [
                Crumb(name="Inventory", path=""),
                Crumb(name="Indent", path="indent/"),
                Crumb(name=indent_sno, path="indent/" + indent_sno),
                Crumb(name="New",
                      path='/'.join(["indent", indent_sno, "/new"])),
            ]
        }
        pagetitle = "New Supplementary Indent for " + indent_sno
    stage.update(stage_crumbs)
    return render_template('indent_new.html',
                           stage=stage,
                           form=form,
                           pagetitle=pagetitle)
Ejemplo n.º 31
0
 def load_from_db(self, max_age, session=None):
     if session is None:
         with get_session() as s:
             self._load_from_db(max_age, session=s)
     else:
         self._load_from_db(max_age, session=session)
Ejemplo n.º 32
0
def new_indent(indent_sno=None):
    form = CreateIndentForm(parent_indent_sno=indent_sno)
    stage = {'crumbroot': '/inventory'}
    if form.validate_on_submit():
        try:
            with get_session() as session:
                sno = form.indent_sno.sno.data
                if not sno:
                    if indent_sno is not None:
                        sno = form.get_supplementary_sno_default()
                        register_serialno(sno=sno, efield="WEB FRONTEND INDENT",
                                          session=session)
                    else:
                        sno = get_serialno(series='IDT',
                                           efield='WEB FRONTEND INDENT',
                                           register=True, session=session)
                else:
                    # additional sno validation?
                    pass
                nindent = InventoryIndent(sno=sno, session=session)
                # Construct COBOM
                obom = create_obom_from_listing(form.components.data,
                                                'MANUAL (WEB)')
                cobom = CompositeOutputBom([obom],
                                           name='MANUAL (WEB) {0}'.format(sno))

                requested_by = get_username_from_full_name(full_name=form.user.data,
                                                           session=session)

                icparams = {
                    'cobom': cobom,
                    'title': form.indent_title.data,
                    'desc': form.indent_desc.data,
                    'requested_by': requested_by,
                    'rdate': form.rdate.data or arrow.utcnow(),
                    'indent_type': form.indent_type.data,
                }
                nindent.create(**icparams)

                root_order_sno = form.root_order_sno.data
                prod_order_sno = form.prod_order_sno.data
                try:
                    nindent.define_auth_chain(prod_order_sno=prod_order_sno,
                                              root_order_sno=root_order_sno,
                                              session=session)
                except AuthChainNotValidError:
                    raise
                nindent.register_auth_chain(session=session)

                fe_workspace_path = os.path.join(TEMPDIR, 'frontend')
                if not os.path.exists(fe_workspace_path):
                    os.makedirs(fe_workspace_path)
                workspace_path = os.path.join(fe_workspace_path, get_tempname())
                os.makedirs(workspace_path)

                nindent.process(outfolder=workspace_path,
                                register=True, session=session)

                shutil.rmtree(workspace_path)
            return redirect(url_for('.indent', indent_sno=str(sno)))
        except AuthChainNotValidError:
            stage['auth_not_valid'] = True

    if indent_sno is None:
        stage_crumbs = {'breadcrumbs': [Crumb(name="Inventory", path=""),
                                        Crumb(name="Indent", path="indent/"),
                                        Crumb(name="New", path="indent/new")],
                        }
        pagetitle = "Create New Indent"
    else:
        stage_crumbs = {'breadcrumbs': [Crumb(name="Inventory", path=""),
                                        Crumb(name="Indent", path="indent/"),
                                        Crumb(name=indent_sno,
                                              path="indent/" + indent_sno),
                                        Crumb(name="New",
                                              path='/'.join(["indent",
                                                             indent_sno,
                                                             "/new"])),
                                        ]
                        }
        pagetitle = "New Supplementary Indent for " + indent_sno
    stage.update(stage_crumbs)
    return render_template('indent_new.html', stage=stage, form=form,
                           pagetitle=pagetitle)