Beispiel #1
0
def venreport(venstr):
    outfile = ('kit' + str(kitgen.kitnum) + '_' + venstr + '.dat')
    venfile = venpath + '/' + venstr + '.dat'
    descdict = partman.org2dict(kitgen.descfile)
    if os.path.isfile(venfile):
        if needorder(venstr):
            fvo = open(kitgen.kitdir + '/' + outfile,'w')
            # Shortage list generated from the summary file
            shortdict = partman.org2dict(kitgen.sumpath)
            vdict = partman.org2dict(venfile)
            fvo.write('-*- mode: Org; mode: Auto-Revert; -*-' + '\n')
            fvo.write('#+STARTUP: align' + '\n')
            fvo.write('#' + '\n')
            fvo.write('#' + '\n')
            fvo.write('|-' + '\n')
            fvo.write('|JRR part' + '|' + venstr + ' part' +
                '|Quantity|' + '\n')
            fvo.write('|-' + '\n')
            count = 0
            for part in shortdict:
                if (shortdict[part][1] == venstr) and (int(shortdict[part][0]) > 0):
                    count += 1
                    fvo.write('|' + part + '|' + vdict[part][0] + '|' +
                        str(shortdict[part][0]) + '|' + '\n')
            fvo.write('|-' + '\n')
            print('Wrote ' + str(count) + ' parts to ' + outfile)
            fvo.close()
            partman.sortorg(kitgen.kitdir + '/' + outfile,0)
            partman.sortorg(venfile,1)
        else:
            print('No parts need to be ordered from ' + venstr)
    else:
        print('venreport: Did not find file ' + venfile)
Beispiel #2
0
def makefill(pagelist):
    bomqty = partcount(pagelist)
    fillfile = ('kit' + str(kitnum) + '_fill.dat')
    descdict = partman.org2dict(descfile)
    fot = open(kitdir + '/' + fillfile,'w')
    fot.write('-*- mode: Org; mode: Auto-Revert; -*-' + '\n')
    fot.write('#+STARTUP: align' + '\n')
    fot.write('#' + '\n')
    fot.write('# Update the quantity of parts in the kit and run buygen.py'
        + '\n')
    fot.write('#' + '\n')
    fot.write('|-' + '\n')
    fot.write('|JRR part' + '|Needed' + '|In Kit' + '|Description|' +
        '\n')
    fot.write('| | | |<70>|' + '\n') # To set description column width
    fot.write('|-' + '\n')
    for part in bomqty:
        if part in descdict:
            fot.write('|' + part + '|' + str(bomqty[part]) + '| |' + descdict[part][0] + '|' + '\n')
            fot.write('|-' + '\n')
        else:
            fot.write('|' + part + '|' + str(bomqty[part]) + '| |' + 'No description' + '|' + '\n')
            fot.write('|-' + '\n')
    fot.write('|-')
    print('* Found ' + str(len(bomqty)) + ' unique parts in design.')
    print('* Fill kit by editing ' + fillfile +
            ' with emacs.  Then run buygen.py' + '\n' +
            '  to see what needs to be ordered.')
    fot.close()
    partman.sortorg(kitdir + '/' + fillfile,0)
Beispiel #3
0
def needorder(venstr):
    venfile = venpath + '/' + venstr + '.dat'
    found = False
    if os.path.isfile(venfile):
        # Shortage list generated from the summary file
        shortdict = partman.org2dict(kitgen.sumpath)
        for part in shortdict:
            if (int(shortdict[part][0]) > 0) and (shortdict[part][1] == venstr):
                found = True
    else:
        print('Did not find file ' + venfile)
    return found
Beispiel #4
0
def getshort():
    shortdict = {}
    fillfile = ('kit' + str(kitgen.kitnum) + '_fill.dat')
    fillpath = kitgen.kitdir + '/' + fillfile
    rawdict = partman.org2dict(fillpath)
    for part in rawdict:
        try:
            inkit = int(rawdict[part][1])
        except:
            inkit = 0
        shortdict[part] = int(rawdict[part][0]) - inkit
    return shortdict
Beispiel #5
0
def sumreport(shortdict):
    sumfile = ('kit' + str(kitgen.kitnum) + '_summary.dat')
    descdict = partman.org2dict(kitgen.descfile)
    fos = open(kitgen.kitdir + "/" + sumfile,'w')
    fos.write('-*- mode: Org; mode: Auto-Revert; -*-' + '\n')
    fos.write('#+STARTUP: align' + '\n')
    fos.write('# \n')
    fos.write('# Add an x anywhere in the "Remove" column \n')
    fos.write('# and save this file to disqualify a vendor \n')
    fos.write('# for a given part. \n')
    fos.write('|-' + '\n')
    fos.write('|JRR part' + '|Quantity' + '|Vendor' + '|Remove' +
              '|Description|' + '\n')
    fos.write('| | | | |<70>|' + '\n') # Set description column width
    fos.write('|-' + '\n')
    for part in shortdict:
        if (shortdict[part] > 0):
            foundit = False # Did we find the part in any vendor file?
            for vendor in venlist:
                venfile = venpath + '/' + vendor + '.dat'
                if part in partman.org2dict(venfile):
                    if part in descdict:
                        fos.write('|' + str(part) + '|' +
                        str(shortdict[part]) + '|' + vendor + '| |' + 
                            descdict[part][0] + '\n')
                    else:
                        fos.write('|' + str(part) + '|' + 
                        str(shortdict[part]) + '|' + vendor + '| |' + 
                            'No description' + '\n')
                    fos.write('|-' + '\n')
                    foundit = True
            if not foundit: # The part was not found in any vendor file.
                fos.write('|' + str(part) + '|' + str(shortdict[part]) +
                          '|' + 'None' + '|' +'\n')
                fos.write('|-' + '\n')
                print('Part ' + str(part) + ' was not found in any vendor file :-(')
    fos.close()
    partman.multisort(kitgen.sumpath,0)
    print('* Wrote summary to ' + sumfile)
Beispiel #6
0
def bomcost(pagelist):
    kitcostfile = ('kit' + str(kitnum) + '_cost.bom')
    fob = open(kitdir + '/' + kitcostfile,'w')
    partman.sortorg(costfile,0) # Sort the nomcost file
    costdict = partman.org2dict(costfile) # Maps JPart to unit price
    descdict = partman.org2dict(descfile) # Description dictionary
    bomqty = partcount(pagelist) # Maps JPart to quantity
    fob.write('-*- mode: Org; mode: Auto-Revert; -*-' + '\n')
    fob.write('#+STARTUP: align' + '\n')
    fob.write('#' + '\n')
    fob.write('|-' + '\n')
    fob.write('|JPart' + '|Kit Qty' + '|Each ($)' + '|Extended ($)' +
              '|Description|' + '\n')
    fob.write('| | | | |<70>|' + '\n') # To set description column width
    fob.write('|-' + '\n')
    costsum = 0
    for part in bomqty:
        fob.write('|' + part + '|' + str(bomqty[part]) + '|')
        if part in costdict:
            eachcost = float(costdict[part][0])
            extcost = bomqty[part] * eachcost
            fob.write('%0.2f'%eachcost + '|' + 
                      '%0.2f'%extcost)
            costsum += extcost
        else:
            fob.write('Unknown' + '|' + 'Unknown')
        if part in descdict:
            fob.write('|' + descdict[part][0] + '|' + '\n')
        else:
            fob.write('|' + 'unknown' + '|' + '\n')
        fob.write('|-' + '\n')
    fob.write('BOM cost is %0.2f'%costsum + '\n')
    fob.close()
    partman.multisort(kitdir + '/' + kitcostfile,0)
    fob = open(kitdir + '/' + kitcostfile,'a')
    fob.write('BOM cost is $%0.2f'%costsum + '\n')
    fob.close()
    print('* Nominal BOM cost breakdown written to ' + kitcostfile + 
          ' in emacs org-mode format.')
Beispiel #7
0
def venpaste(venstr):
    outfile = ('kit' + str(kitgen.kitnum) + '_' + venstr + '.pst')
    venfile = ('kit' + str(kitgen.kitnum) + '_' + venstr + '.dat')
    descdict = partman.org2dict(kitgen.descfile)
    # The vendor file will only exist if there are parts in it to be ordered.
    if os.path.isfile(kitgen.kitdir + '/' + venfile):
        buydict = partman.org2dict(kitgen.kitdir + '/' + venfile)
        fot = open(kitgen.kitdir + '/' + outfile,'w')
        for part in buydict:
            """ Newark file format:
                Newark part <tab> Qty <tab> Comment """
            if (venstr == 'newark'):
                fot.write(buydict[part][0] + '\t' + buydict[part][1] + 
                          '\t' + part + ' ' + descdict[part][0] + '\n')
            """ Digikey file format:
                Quantity <tab> Digi-Key part number <tab> Customer reference """
            if (venstr == 'digikey'):
                # Digi-Key can't tolerate commas at all
                description = descdict[part][0].replace(',','')
                fot.write(buydict[part][1] + '\t' + buydict[part][0] +
                          '\t' + part + ' ' + description + '\n')
        print('--> Use ' + outfile + ' for cut and paste.')
        fot.close()
Beispiel #8
0
def buildbom():
    buildfile = ('kit' + str(kitnum) + '_build.bom')
    fob = open(kitdir + '/' + buildfile,'w')
    refdict = {} # Dictionary of JPart: refdes list
    fbm = open(bomname,'r')
    rawbom = fbm.read()
    for line in rawbom.split('\n')[1:]:
        if not donread(line):
            fields = line.split(":")
            #fields[3] is the JPart number.
            refdict[fields[3]] = fields[0]
    descdict = partman.org2dict(descfile) # Description dictionary
    fob.write('-*- mode: Org; mode: Auto-Revert; -*-' + '\n')
    fob.write('#+STARTUP: align' + '\n')
    fob.write('#' + '\n')
    fob.write('|-' + '\n')
    fob.write('|JPart' + '|References' + '|Description|' + '\n')
    fob.write('| | |<70>|' + '\n') # To set description column width
    fob.write('|-' + '\n')
    for part in refdict:
        if part in descdict:
            fob.write('|' + part + '|' + str(refdict[part]) + '|' +
                descdict[part][0] + '|' + '\n')
            fob.write('|-' + '\n')
        else:
            fob.write('|' + part + '|' + str(refdict[part]) + '|' +
                'unknown' + '|' + '\n')
            fob.write('|-' + '\n')
    fbm.close()
    fob.close()
    partman.sortorg(kitdir + '/' + buildfile,0)
    partman.texbuild(kitdir + '/' + buildfile)
    print('* Assembly BOM written to ' + buildfile + ' and ' +
        buildfile.split('.')[0] + ".tex. Execute 'latex " + '\n' +
        '  '  + buildfile.split('.')[0] + ".tex' " +
        'to process .tex file.')