本文整理汇总了Python中sh.cat函数的典型用法代码示例。如果您正苦于以下问题:Python cat函数的具体用法?Python cat怎么用?Python cat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot
def plot(input_file, output_file, nr_of_lines, options = None, label = 'transfer rate [MB per s]'):
'''Plot input file with uneven column number n being x axis value,
and n+1 being the corresponding y axis values for column n.'''
if options is None:
options = []
with tempfile.NamedTemporaryFile() as plot_file:
print >>plot_file, 'set xlabel "time [min]";'
print >>plot_file, 'set xtic auto;'
print >>plot_file, 'set ylabel "%s";' % label
#print >>plot_file, 'set timefmt '%Y-%m-%d %H:%M:%S''
if MONOCHROME in options:
print >>plot_file, 'set terminal pdf linewidth 3 monochrome solid font "Helvetica,14" size 16cm,12cm'
else:
print >>plot_file, 'set terminal pdf linewidth 3 solid font "Helvetica,14" size 16cm,12cm'
print >>plot_file, 'set output "%s"' % output_file
plot_file.write('plot ')
print nr_of_lines
for i in range(nr_of_lines):
print "line:"+str(i)
x_axis_col = i*2 + 1
y_axis_col = i*2 + 2
plot_file.write('"%s" using %s:%s title column(%s) w lines ' % (input_file, x_axis_col, y_axis_col, y_axis_col))
if i+1 != nr_of_lines:
plot_file.write(',')
plot_file.flush()
print "plot file:"
#print plot_file.name
print sh.cat(plot_file.name)
#raw_input("raw_input")
sh.gnuplot(plot_file.name)
示例2: test_internal_bufsize
def test_internal_bufsize(self):
from sh import cat
output = cat(_in="a"*1000, _internal_bufsize=100, _out_bufsize=0)
self.assertEqual(len(output), 100)
output = cat(_in="a"*1000, _internal_bufsize=50, _out_bufsize=2)
self.assertEqual(len(output), 100)
示例3: runCommand
def runCommand(input_path, output_path, *extra_arguments, error_path=None):
# See createNativeCommand for why I'm using cat
if not error_path:
return command(
snapshots(sh.cat(input_path, _piped="direct"), _piped="direct"),
*extra_arguments, _out=output_path, _iter="err")
else:
return command(
snapshots(sh.cat(input_path, _piped="direct"), _piped="direct"),
*extra_arguments, _out=output_path, _err=error_path, _bg=True)
示例4: test_stdin_processing
def test_stdin_processing():
"""
You’re also not limited to using just strings. You may use a file object,
a Queue, or any iterable (list, set, dictionary, etc):
:return:
"""
from sh import cat, tr
# print "test"
print cat(_in='test')
print tr('[:lower:]', '[:upper:]', _in='sh is awesome')
示例5: main
def main(argv=None):
if argv:
post = ' '.join(argv[1:])
else:
post = ''
cap = int(cat('/sys/class/power_supply/BAT0/energy_full'))
now = int(cat('/sys/class/power_supply/BAT0/energy_now'))
per = (now/cap)*100
return output(per, post)
示例6: report_benchmark_results
def report_benchmark_results(file_a, file_b, description):
"""Wrapper around report_benchmark_result.py."""
result = "{0}/perf_results/latest/performance_result.txt".format(IMPALA_HOME)
with open(result, "w") as f:
subprocess.check_call(
["{0}/tests/benchmark/report_benchmark_results.py".format(IMPALA_HOME),
"--reference_result_file={0}".format(file_a),
"--input_result_file={0}".format(file_b),
'--report_description="{0}"'.format(description)],
stdout=f)
sh.cat(result, _out=sys.stdout)
示例7: parse_rdf
def parse_rdf(self):
""" cat|grep's the rdf file for minimum metadata
"""
# FIXME: make this an rdf parser if I can
_title = sh.grep(sh.cat(self.rdf_path), 'dcterms:title', _tty_out=False)
try:
_author = sh.grep(sh.cat(self.rdf_path), 'name', _tty_out=False)
self.author = self._clean_properties(_author)
except sh.ErrorReturnCode_1:
self.author = "Various"
self.title = self._clean_properties(_title)
示例8: restore_config
def restore_config(config_file):
output.itemize(
'Restoring firewall configuration from \'{}\''.format(config_file)
)
sh.iptables_restore(sh.cat(config_file))
files.remove(os.path.dirname(config_file), _output_level=1)
示例9: email_sh_error
def email_sh_error(
sh_error, email_dir, sender_email,
recipient_emails, subject
):
"""
Takes an sh.ErrorReturnCode error
and sends an email (using sendmail) with its contents
"""
epoch_time = datetime.now().strftime('%s')
email_filepath = '{0}/{1}.email'.format(email_dir, epoch_time)
with open(email_filepath, 'w') as email_file:
email_file.write('from: {0}\n'.format(sender_email))
email_file.write('subject: {0}\n'.format(subject))
email_file.write('\n')
email_file.write('{0}\n'.format(sh_error.message))
email_file.write('\n')
email_file.write('Exception properties\n')
email_file.write('===\n')
email_file.write('full_cmd: {0}\n'.format(sh_error.full_cmd))
email_file.write('exit_code: {0}\n'.format(str(sh_error.exit_code)))
email_file.write('stdout: {0}\n'.format(sh_error.stdout))
email_file.write('stderr: {0}\n'.format(sh_error.stderr))
sh.sendmail(sh.cat(email_filepath), recipient_emails)
示例10: test_console_script
def test_console_script(cli):
TEST_COMBINATIONS = (
# quote_mode, var_name, var_value, expected_result
("always", "HELLO", "WORLD", 'HELLO="WORLD"\n'),
("never", "HELLO", "WORLD", 'HELLO=WORLD\n'),
("auto", "HELLO", "WORLD", 'HELLO=WORLD\n'),
("auto", "HELLO", "HELLO WORLD", 'HELLO="HELLO WORLD"\n'),
)
with cli.isolated_filesystem():
for quote_mode, variable, value, expected_result in TEST_COMBINATIONS:
sh.touch(dotenv_path)
sh.dotenv('-f', dotenv_path, '-q', quote_mode, 'set', variable, value)
output = sh.cat(dotenv_path)
assert output == expected_result
sh.rm(dotenv_path)
# should fail for not existing file
result = cli.invoke(dotenv.cli.set, ['my_key', 'my_value'])
assert result.exit_code != 0
# should fail for not existing file
result = cli.invoke(dotenv.cli.get, ['my_key'])
assert result.exit_code != 0
# should fail for not existing file
result = cli.invoke(dotenv.cli.list, [])
assert result.exit_code != 0
示例11: postClone
def postClone(self, cloned_files, target_dir, version):
"""
.. versionadded:: 0.3.0
"""
# Start by extracting all the files
for f in cloned_files:
# GunZIP the file (and remove the archive)
sh.gunzip(f)
# Then let's concat them
target_path = "{}/NCBI.Homo_sapiens.fa".format(target_dir)
# Remove ".gz" ending to point to extracted files
cat_args = [f[:-3] for f in cloned_files]
# Execute the concatenation in the background and write to the target path
sh.cat(*cat_args, _out=target_path, _bg=True)
示例12: test_filter_pipe_config
def test_filter_pipe_config():
output = StringIO()
python3(cat(program_output), path2main, config=config_file,
use_config_section='TEST', _out=output)
with open(program_output_filtered, 'r') as correctly_filtered_output:
assert correctly_filtered_output.read() == output.getvalue()
示例13: test_two_images
def test_two_images():
sh.docker(sh.cat('empty.tar'), 'import', '-', 'footest')
sh.docker('build', '-t', 'bartest', '.')
f = StringIO()
Docktree(restrict='footest', file=f).draw_tree()
assert re.match(
u'└─ sha256:[a-f0-9]{5} footest:latest\n' +
u' └─ sha256:[a-f0-9]{5} bartest:latest\n', f.getvalue())
示例14: raxml_consensus
def raxml_consensus(gene_trees, model, outgroup, list_of_genes):
'''Generates consensus trees from bootstraps and puts support values on
best trees'''
from sh import raxmlHPC as raxml
os.chdir(gene_trees)
for gene in list_of_genes:
raxml("-m", model, "-p", "12345", "-f", "b", "-t", "RAxML_bestTree." +
gene + '.' + model, "-z", "RAxML_bootstrap." + gene + '.boot', "-n",
gene + ".cons.tre", "-o", outgroup)
from sh import cat
consensus_trees = glob('RAxML_bipartitions.*.cons.tre')
cat(consensus_trees, _out='all_consensus_gene_trees.tre')
# NEED TO ADD, ETE2 OR SOMETHING TO PUT NAMES ON TREES
os.chdir('../../')
print "# RAXML bootstrap search finished"
return
示例15: mounted
def mounted(dir=None):
try:
cwd = dir if dir else os.path.join(os.getcwd(), 'files')
cwd = os.path.realpath(cwd)
return any(cwd == path.strip() for path in
list(sh.awk(sh.cat("/proc/mounts"), "{print $2}")))
except sh.ErrorReturnCode:
return False