本文整理汇总了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)
示例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)
示例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))
示例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()
示例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'),
)
示例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'),
)
示例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'),
)
示例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
示例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))
示例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
##