def main(): parser = ap.ArgumentParser( description='Build cost spreadsheet for a KiCAD project.') parser.add_argument('-v', '--version', action='version', version='KiCost ' + __version__) parser.add_argument('-i', '--input', nargs='?', type=str, metavar='file.xml', help='Schematic BOM XML file.') parser.add_argument('-o', '--output', nargs='?', type=str, metavar='file.xlsx', help='Generated cost spreadsheet.') parser.add_argument('-w', '--overwrite', action='store_true', help='Allow overwriting of an existing spreadsheet.') parser.add_argument( '-d', '--debug', nargs='?', type=int, default=0, metavar='LEVEL', help='Print debugging info. (Larger LEVEL means more info.)') args = parser.parse_args() if args.output == None: if args.input != None: args.output = os.path.splitext(args.input)[0] + '.xlsx' else: args.output = os.path.splitext(sys.argv[0])[0] + '.xlsx' else: args.output = os.path.splitext(args.output)[0] + '.xlsx' if os.path.isfile(args.output): if not args.overwrite: print 'Output file {} already exists! Use the --overwrite option to replace it.'.format( args.output) sys.exit(1) if args.input == None: args.input = sys.stdin else: args.input = os.path.splitext(args.input)[0] + '.xml' args.input = open(args.input) kicost(in_file=args.input, out_filename=args.output, debug_level=args.debug)
parser.add_argument( '-d', '--debug', nargs='?', type=int, default=0, metavar='LEVEL', help='Print debugging info. (Larger LEVEL means more info.)') args = parser.parse_args() if args.output == None: if args.input != None: args.output = os.path.splitext(args.input)[0] + '.xlsx' else: args.output = os.path.splitext(sys.argv[0])[0] + '.xlsx' else: args.output = os.path.splitext(args.output)[0] + '.xlsx' if os.path.isfile(args.output): if not args.overwrite: print 'Output file {} already exists! Use the --overwrite option to replace it.'.format( args.output) sys.exit(1) if args.input == None: args.input = sys.stdin else: args.input = os.path.splitext(args.input)[0] + '.xml' args.input = open(args.input) kicost(in_file=args.input, out_filename=args.output, debug_level=args.debug)