當前位置: 首頁>>代碼示例>>Python>>正文


Python click.get_binary_stream方法代碼示例

本文整理匯總了Python中click.get_binary_stream方法的典型用法代碼示例。如果您正苦於以下問題:Python click.get_binary_stream方法的具體用法?Python click.get_binary_stream怎麽用?Python click.get_binary_stream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在click的用法示例。


在下文中一共展示了click.get_binary_stream方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: encode

# 需要導入模塊: import click [as 別名]
# 或者: from click import get_binary_stream [as 別名]
def encode(precision, with_z):
    """Given GeoJSON on stdin, writes a geobuf file to stdout."""
    logger = logging.getLogger('geobuf')
    stdin = click.get_text_stream('stdin')
    sink = click.get_binary_stream('stdout')
    try:
        data = json.load(stdin)
        pbf = geobuf.encode(
            data,
            precision if precision >= 0 else 6,
            3 if with_z else 2)
        sink.write(pbf)
        sys.exit(0)
    except Exception:
        logger.exception("Failed. Exception caught")
        sys.exit(1) 
開發者ID:pygeobuf,項目名稱:pygeobuf,代碼行數:18,代碼來源:cli.py

示例2: decode

# 需要導入模塊: import click [as 別名]
# 或者: from click import get_binary_stream [as 別名]
def decode():
    """Given a Geobuf byte string on stdin, write a GeoJSON feature
    collection to stdout."""
    logger = logging.getLogger('geobuf')
    stdin = click.get_binary_stream('stdin')
    sink = click.get_text_stream('stdout')
    try:
        pbf = stdin.read()
        data = geobuf.decode(pbf)
        json.dump(data, sink)
        sys.exit(0)
    except Exception:
        logger.exception("Failed. Exception caught")
        sys.exit(1) 
開發者ID:pygeobuf,項目名稱:pygeobuf,代碼行數:16,代碼來源:cli.py

示例3: tts_cli

# 需要導入模塊: import click [as 別名]
# 或者: from click import get_binary_stream [as 別名]
def tts_cli(text, file, output, slow, lang, nocheck):
    """ Read <text> to mp3 format using Google Translate's Text-to-Speech API
    (set <text> or --file <file> to - for standard input)
    """

    # stdin for <text>
    if text == '-':
        text = click.get_text_stream('stdin').read()

    # stdout (when no <output>)
    if not output:
        output = click.get_binary_stream('stdout')

    # <file> input (stdin on '-' is handled by click.File)
    if file:
        try:
            text = file.read()
        except UnicodeDecodeError as e:  # pragma: no cover
            log.debug(str(e), exc_info=True)
            raise click.FileError(
                file.name,
                "<file> must be encoded using '%s'." %
                sys_encoding())

    # TTS
    try:
        tts = gTTS(
            text=text,
            lang=lang,
            slow=slow,
            lang_check=not nocheck)
        tts.write_to_fp(output)
    except (ValueError, AssertionError) as e:
        raise click.UsageError(str(e))
    except gTTSError as e:
        raise click.ClickException(str(e)) 
開發者ID:luoliyan,項目名稱:chinese-support-redux,代碼行數:38,代碼來源:cli.py

示例4: download

# 需要導入模塊: import click [as 別名]
# 或者: from click import get_binary_stream [as 別名]
def download(repo_url, directory):
    from plumbum.cmd import curl
    from shutil import rmtree

    directory = Path(directory)
    # download the master branch
    url = repo_url + '/archive/master.zip'
    # download the zip next to the target directory with the same name
    path = directory.with_suffix('.zip')

    if not path.exists():
        logger.info('Downloading {} to {}...'.format(url, path))
        path.parent.mkdir(parents=True, exist_ok=True)
        download = curl[url, '-o', path, '-L']
        download(
            stdout=click.get_binary_stream('stdout'),
            stderr=click.get_binary_stream('stderr'),
        )
    else:
        logger.info('Skipping download: {} already exists'.format(path))

    logger.info('Extracting archive to {}'.format(directory))

    # extract all files
    extract_to = directory.with_name(directory.name + '_extracted')
    with zipfile.ZipFile(str(path), 'r') as f:
        f.extractall(str(extract_to))

    # remove existent folder
    if directory.exists():
        rmtree(str(directory))

    # rename to the target directory
    (extract_to / 'testing-data-master').rename(directory)

    # remove temporary extraction folder
    extract_to.rmdir() 
開發者ID:ibis-project,項目名稱:ibis,代碼行數:39,代碼來源:datamgr.py

示例5: clone

# 需要導入模塊: import click [as 別名]
# 或者: from click import get_binary_stream [as 別名]
def clone(repo_uri, destination, branch):
    if not Path(destination).exists():
        cmd = git['clone', repo_uri, destination]
        cmd(
            stdout=click.get_binary_stream('stdout'),
            stderr=click.get_binary_stream('stderr'),
        )

    cmd = git['-C', destination, 'checkout', branch]
    cmd(
        stdout=click.get_binary_stream('stdout'),
        stderr=click.get_binary_stream('stderr'),
    ) 
開發者ID:ibis-project,項目名稱:ibis,代碼行數:15,代碼來源:feedstock.py

示例6: build

# 需要導入模塊: import click [as 別名]
# 或者: from click import get_binary_stream [as 別名]
def build(recipe, python):
    click.echo('Building {} recipe...'.format(recipe))

    cmd = conda[
        'build', '--channel', 'conda-forge', '--python', python, recipe
    ]

    cmd(
        stdout=click.get_binary_stream('stdout'),
        stderr=click.get_binary_stream('stderr'),
    ) 
開發者ID:ibis-project,項目名稱:ibis,代碼行數:13,代碼來源:feedstock.py

示例7: deploy

# 需要導入模塊: import click [as 別名]
# 或者: from click import get_binary_stream [as 別名]
def deploy(package_location, artifact_directory, architecture):
    artifact_dir = Path(artifact_directory)
    artifact_dir.mkdir(parents=True, exist_ok=True)
    package_loc = Path(package_location)
    assert package_loc.exists(), 'Path {} does not exist'.format(package_loc)

    for architecture in (architecture, 'noarch'):
        arch_artifact_directory = str(artifact_dir / architecture)
        arch_package_directory = str(package_loc / architecture)
        shutil.copytree(arch_package_directory, arch_artifact_directory)
    cmd = conda['index', artifact_directory]
    cmd(
        stdout=click.get_binary_stream('stdout'),
        stderr=click.get_binary_stream('stderr'),
    ) 
開發者ID:ibis-project,項目名稱:ibis,代碼行數:17,代碼來源:feedstock.py

示例8: create_stdin_reader

# 需要導入模塊: import click [as 別名]
# 或者: from click import get_binary_stream [as 別名]
def create_stdin_reader(self):
        # type: () -> PipeReader
        stream = click.get_binary_stream('stdin')
        reader = PipeReader(stream)
        return reader 
開發者ID:aws,項目名稱:chalice,代碼行數:7,代碼來源:factory.py

示例9: tts_cli

# 需要導入模塊: import click [as 別名]
# 或者: from click import get_binary_stream [as 別名]
def tts_cli(text, file, output, slow, tld, lang, nocheck):
    """ Read <text> to mp3 format using Google Translate's Text-to-Speech API
    (set <text> or --file <file> to - for standard input)
    """

    # stdin for <text>
    if text == '-':
        text = click.get_text_stream('stdin').read()

    # stdout (when no <output>)
    if not output:
        output = click.get_binary_stream('stdout')

    # <file> input (stdin on '-' is handled by click.File)
    if file:
        try:
            text = file.read()
        except UnicodeDecodeError as e:  # pragma: no cover
            log.debug(str(e), exc_info=True)
            raise click.FileError(
                file.name,
                "<file> must be encoded using '%s'." %
                sys_encoding())

    # TTS
    try:
        tts = gTTS(
            text=text,
            lang=lang,
            slow=slow,
            tld=tld,
            lang_check=not nocheck)
        tts.write_to_fp(output)
    except (ValueError, AssertionError) as e:
        raise click.UsageError(str(e))
    except gTTSError as e:
        raise click.ClickException(str(e)) 
開發者ID:pndurette,項目名稱:gTTS,代碼行數:39,代碼來源:cli.py

示例10: main

# 需要導入模塊: import click [as 別名]
# 或者: from click import get_binary_stream [as 別名]
def main(click_context, hashmes, s, v, c, f, m, j):
    """
    If there is a file at hashme, read and omnihash that file.
    Elif hashme is a string, omnihash that.
    """

    # Print version and quit
    if v:
        version = pkg_resources.require("omnihash")[0].version
        click.echo(version)
        return

    intialize_plugins()

    results = []
    if not hashmes:
        # If no stdin, just help and quit.
        if not sys.stdin.isatty():
            digesters = make_digesters(None, f, c)
            stdin = click.get_binary_stream('stdin')
            bytechunks = iter(lambda: stdin.read(io.DEFAULT_BUFFER_SIZE), b'')
            if not j:
                click.echo("Hashing " + click.style("standard input", bold=True) + "..", err=True)
            results.append([produce_hashes(bytechunks, digesters, match=m, use_json=j)])
        else:
            print(click_context.get_help())
            return
    else:
        hash_many = len(hashmes) > 1
        for hashme in hashmes:
            result = {}
            digesters = make_digesters(hashme, f, c)
            bytechunks = iterate_bytechunks(hashme, s, j, hash_many)
            if bytechunks:
                result = produce_hashes(bytechunks, digesters, match=m, use_json=j)
            if result:
                result['NAME'] = hashme
                results.append(result)

    if results and j:
        print(json.dumps(results, indent=4, sort_keys=True))


##
# Main Logic
## 
開發者ID:Miserlou,項目名稱:omnihash,代碼行數:48,代碼來源:omnihash.py


注:本文中的click.get_binary_stream方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。