コード例 #1
0
def main():
    global PREFIXES
    args = docopt(__doc__, version="qnamefix 0")
    infmt = args['--format'] = 'turtle'
    ttlser.ttlfmt.args = args
    if args['--exclude'] == ['ALL']:
        for k in list(PREFIXES):
            PREFIXES.pop(k)
    else:
        for x in args['--exclude']:
            if x in PREFIXES:
                PREFIXES.pop(x)
    if not args['<file>']:
        stdin = readFromStdIn(sys.stdin)
        if stdin is not None:
            convert(stdin, stream=True, infmt=infmt)
        else:
            print(__doc__)
    else:
        if args['--slow'] or len(args['<file>']) == 1:
            [convert(f, infmt=infmt) for f in args['<file>']]
        else:
            from joblib import Parallel, delayed
            Parallel(n_jobs=9)(delayed(convert)(f, infmt=infmt)
                               for f in args['<file>'])
コード例 #2
0
ファイル: ttlfmt.py プロジェクト: dbrnz/pyontutils
def main():
    #global args  # vastly preferable to classing everything since this way we can see
    #global outfmt  # in 2 lines what is actually shared instead of stuffed into self
    args = docopt(__doc__, version=getVersion())

    profile = args['--profile']
    if profile:
        try:
            from desc.prof import profile_me
            global parse
            global serialize
            parse = profile_me(parse)
            serialize = profile_me(serialize)
        except ImportError:
            pass

    nowrite = args['--nowrite']

    infmt = args['--format']
    debug = args['--debug']

    if args['--subclass']:
        outfmt = 'scottl'
    elif args['--vanilla']:
        outfmt = 'turtle'
    elif args['--compact']:
        outfmt = 'cmpttl'
    elif args['--uncompact']:
        outfmt = 'uncmpttl'
    elif args['--jsonld']:
        outfmt = 'json-ld'
    elif args['--racket']:
        outfmt = 'rktttl'
    else:
        outfmt = args['--outfmt']

    if outfmt == 'json-ld' or infmt == 'json-ld':
        regjsonld()

    outpath = args['--output']
    files = args['<file>']
    if not files:
        from ttlser.utils import readFromStdIn
        stdin = readFromStdIn(sys.stdin)
        if stdin is not None:
            convert(stdin, outpath, stream=True,
                    infmt=infmt, outfmt=outfmt,
                    debug=debug, profile=profile,
                    nowrite=nowrite)
        else:
            print(__doc__)
    else:
        lenfiles = len(files)
        if outpath or args['--slow'] or lenfiles == 1:
            if lenfiles == 1:
                files,  = files

            convert(files, outpath=outpath,
                    infmt=infmt, outfmt=outfmt,
                    debug=debug, profile=profile,
                    nowrite=nowrite)
        else:
            from joblib import Parallel, delayed
            nj = 9
            if lenfiles < nj:
                nj = lenfiles

            Parallel(n_jobs=nj, verbose=10)(delayed(convert)
                                            (file,
                                             infmt=infmt, outfmt=outfmt,
                                             debug=debug, profile=profile,
                                             nowrite=nowrite)
                                            for file in files)