示例#1
0
def main(): #pylint: disable=R0912,R0915
    """ Also, bees knees """
    argp = ArgumentParser()
    argp.add_argument("-i", "--input", dest="inputfile",
                      help="read INPUT file in", metavar="INPUT")
    argp.add_argument("-f", "--from", dest="inputtype",
                      help="read input file as TYPE", metavar="TYPE")
    argp.add_argument("-o", "--output", dest="outputfile",
                      help="write OUTPUT file out", metavar="OUTPUT")
    argp.add_argument("-t", "--to", dest="outputtype",
                      help="write output file as TYPE", metavar="TYPE",
                      default="openjson")
    argp.add_argument("-s", "--sym-dirs", dest="sym_dirs",
                      help="specify SYMDIRS to search for .sym files (for gEDA only)", 
                      metavar="SYMDIRS", nargs="+")
    argp.add_argument('--unsupported', action='store_true', default=False,
                      help="run with an unsupported python version")
    argp.add_argument('--raise-errors', dest='raise_errors',
                      action='store_true', default=False,
                      help="show tracebacks for parsing and writing errors")
    argp.add_argument('--profile', action='store_true', default=False,
                      help="collect profiling information")
    argp.add_argument('-v', '--version', action='store_true', default=False,
                      help="print version information and quit")
    argp.add_argument('--formats', action='store_true', default=False,
                      help="print supported formats and quit")

    args = argp.parse_args()

    if args.version:
        print "upconverter %s in python %s.%s" % (ver.version(), sys.version_info[0], sys.version_info[1])
        print "Copyright (C) 2007 Upverter, Inc."
        print "This is free software; see the source for copying conditions.  There is NO warranty; not even for",
        print "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
        sys.exit(0)

    if args.formats:
        print "upconverter supports the following file formats & encodings"
        print ""
        print "As Input:"
        for frmt in PARSERS:
            print "* %s (%s)" % (frmt, EXTENSIONS[frmt])
        print ""
        print "As Output:"
        for frmt in WRITERS:
            print "* %s (%s)" % (frmt, EXTENSIONS[frmt])
        sys.exit(0)

    # Fail if strict and wrong python version
    if sys.version_info[0] > 2 or sys.version_info[1] > 6:
        print 'WARNING: RUNNING UNSUPPORTED VERSION OF PYTHON (%s.%s > 2.6)' % (sys.version_info[0],
            sys.version_info[1])
        if not args.unsupported:
            sys.exit(-1)

    inputtype = args.inputtype
    outputtype = args.outputtype
    inputfile = args.inputfile
    outputfile = args.outputfile

    parser_kwargs = {}
    if args.sym_dirs:
        parser_kwargs['symbol_dirs'] = args.sym_dirs

    # Test for input file
    if inputfile == None:
        log.error('No input file provided.')
        argp.print_help()
        exit(1)

    # Autodetect input type
    if inputtype == None:
        try:
            inputtype = Upconverter.autodetect(inputfile)
        except Exception: #pylint: disable=W0703
            argp.print_help()
            exit(1)

    # Autoset output file
    if outputfile == None:
        try:
            file_name, file_ext = os.path.splitext(inputfile)  #pylint: disable=W0612
            outputfile = file_name + EXTENSIONS[outputtype]
            log.info('Setting output file & format: %s', outputfile)
        except Exception: #pylint: disable=W0703
            log.error('Failed to set output file & format.')
            argp.print_help()
            exit(1)

    if args.profile:
        import cProfile
        profile = cProfile.Profile()
        profile.enable()

    # parse the data
    try:
        design = Upconverter.parse(inputfile, inputtype, **parser_kwargs) #pylint: disable=W0142
    except Exception: #pylint: disable=W0703
        if args.raise_errors:
            raise
        print "ERROR: Failed to parse", inputtype
        exit(1)

    # we got a good result
    if design is not None:
        try:
            Upconverter.write(design, outputfile, outputtype, **parser_kwargs) #pylint: disable=W0142
        except Exception: #pylint: disable=W0703
            if args.raise_errors:
                raise
            print "ERROR: Failed to write", outputtype
            exit(1)

    # parse returned None -> something went wrong
    else:
        print "Output cancelled due to previous errors."
        exit(1)

    if args.profile:
        profile.disable()
        profile.print_stats()
示例#2
0
#!/usr/bin/env python

from setuptools import setup, find_packages
from upconvert import version as ver

packages = [
    'upconvert.' + p
    for p in find_packages('upconvert', exclude=['test', 'test*', '*.t'])
]
packages.append('upconvert')

setup(
    name='python-upconvert',
    maintainer='Upverter Inc.',
    maintainer_email='*****@*****.**',
    version=ver.version(),
    description='Upconvert library',
    license='Apache 2.0',
    url='https://github.com/upverter/schematic-file-converter',
    packages=packages,
)
示例#3
0
def main():  #pylint: disable=R0912,R0915
    """ Also, bees knees """
    argp = ArgumentParser()
    argp.add_argument("-i",
                      "--input",
                      dest="inputfile",
                      help="read INPUT file in",
                      metavar="INPUT")
    argp.add_argument("-f",
                      "--from",
                      dest="inputtype",
                      help="read input file as TYPE",
                      metavar="TYPE")
    argp.add_argument("-o",
                      "--output",
                      dest="outputfile",
                      help="write OUTPUT file out",
                      metavar="OUTPUT")
    argp.add_argument("-t",
                      "--to",
                      dest="outputtype",
                      help="write output file as TYPE",
                      metavar="TYPE",
                      default="openjson")
    argp.add_argument(
        "-s",
        "--sym-dirs",
        dest="sym_dirs",
        help="specify SYMDIRS to search for .sym files (for gEDA only)",
        metavar="SYMDIRS",
        nargs="+")
    argp.add_argument('--unsupported',
                      action='store_true',
                      default=False,
                      help="run with an unsupported python version")
    argp.add_argument('--raise-errors',
                      dest='raise_errors',
                      action='store_true',
                      default=False,
                      help="show tracebacks for parsing and writing errors")
    argp.add_argument('--profile',
                      action='store_true',
                      default=False,
                      help="collect profiling information")
    argp.add_argument('-v',
                      '--version',
                      action='store_true',
                      default=False,
                      help="print version information and quit")
    argp.add_argument('--formats',
                      action='store_true',
                      default=False,
                      help="print supported formats and quit")

    args = argp.parse_args()

    if args.version:
        print "upconverter %s in python %s.%s" % (
            ver.version(), sys.version_info[0], sys.version_info[1])
        print "Copyright (C) 2007 Upverter, Inc."
        print "This is free software; see the source for copying conditions.  There is NO warranty; not even for",
        print "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
        sys.exit(0)

    if args.formats:
        print "upconverter supports the following file formats & encodings"
        print ""
        print "As Input:"
        for frmt in PARSERS:
            print "* %s (%s)" % (frmt, EXTENSIONS[frmt])
        print ""
        print "As Output:"
        for frmt in WRITERS:
            print "* %s (%s)" % (frmt, EXTENSIONS[frmt])
        sys.exit(0)

    # Fail if strict and wrong python version
    if sys.version_info[0] > 2 or sys.version_info[1] > 6:
        print 'WARNING: RUNNING UNSUPPORTED VERSION OF PYTHON (%s.%s > 2.6)' % (
            sys.version_info[0], sys.version_info[1])
        if not args.unsupported:
            sys.exit(-1)

    inputtype = args.inputtype
    outputtype = args.outputtype
    inputfile = args.inputfile
    outputfile = args.outputfile

    parser_kwargs = {}
    if args.sym_dirs:
        parser_kwargs['symbol_dirs'] = args.sym_dirs

    # Test for input file
    if inputfile == None:
        log.error('No input file provided.')
        argp.print_help()
        exit(1)

    # Autodetect input type
    if inputtype == None:
        try:
            inputtype = Upconverter.autodetect(inputfile)
        except Exception:  #pylint: disable=W0703
            argp.print_help()
            exit(1)

    # Autoset output file
    if outputfile == None:
        try:
            file_name, file_ext = os.path.splitext(inputfile)  #pylint: disable=W0612
            outputfile = file_name + EXTENSIONS[outputtype]
            log.info('Setting output file & format: %s', outputfile)
        except Exception:  #pylint: disable=W0703
            log.error('Failed to set output file & format.')
            argp.print_help()
            exit(1)

    if args.profile:
        import cProfile
        profile = cProfile.Profile()
        profile.enable()

    # parse the data
    try:
        design = Upconverter.parse(inputfile, inputtype, **parser_kwargs)  #pylint: disable=W0142
    except Exception:  #pylint: disable=W0703
        if args.raise_errors:
            raise
        print "ERROR: Failed to parse", inputtype
        exit(1)

    # we got a good result
    if design is not None:
        try:
            Upconverter.write(design, outputfile, outputtype, **parser_kwargs)  #pylint: disable=W0142
        except Exception:  #pylint: disable=W0703
            if args.raise_errors:
                raise
            print "ERROR: Failed to write", outputtype
            exit(1)

    # parse returned None -> something went wrong
    else:
        print "Output cancelled due to previous errors."
        exit(1)

    if args.profile:
        profile.disable()
        profile.print_stats()
示例#4
0
#!/usr/bin/env python

from setuptools import setup, find_packages
from upconvert import version as ver

packages = ['upconvert.' + p for p in find_packages('upconvert', exclude=['test', 'test*', '*.t'])]
packages.append('upconvert')

setup(
    name='python-upconvert',
    maintainer='Upverter Inc.',
    maintainer_email='*****@*****.**',
    version=ver.version(),
    description='Upconvert library',
    license='Apache 2.0',
    url='https://github.com/upverter/schematic-file-converter',
    packages=packages,
)