本文整理汇总了Python中sh.grep函数的典型用法代码示例。如果您正苦于以下问题:Python grep函数的具体用法?Python grep怎么用?Python grep使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了grep函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: assert_hg_count
def assert_hg_count(count, rev=None):
"""Assuming you are in an hg repository, assert that ``count`` commits
have been made to that repo."""
if rev:
assert sh.grep(sh.hg.log(rev=rev), "changeset:").stdout.count(b"\n") == count
else:
assert sh.grep(sh.hg.log(), "changeset:").stdout.count(b"\n") == count
开发者ID:xentac,项目名称:gitifyhg,代码行数:7,代码来源:helpers.py
示例2: check_upgrade
def check_upgrade():
server_file = curl(PIFM_HOST + '/client_agent/pifm_agent.py')
server_sum = awk(
md5sum(
grep(server_file, '-v', '^PIFM_HOST')
), '{print $1}'
)
local_sum = awk(
md5sum(
grep('-v', '^PIFM_HOST', OUR_SCRIPT)
), '{print $1}'
)
if str(server_sum) != str(local_sum):
logging.info(
"server: {server}, local: {local}, should update.".format(
server=server_sum,
local=local_sum
)
)
with open(TMP_SCRIPT, 'w') as f:
f.write(str(server_file))
sed('-i',
"0,/def/ s#http://pi_director#{myhost}#".format(myhost=PIFM_HOST),
OUR_SCRIPT
)
status = python('-m', 'py_compile', TMP_SCRIPT)
if (status.exit_code == 0):
shutil.copy(TMP_SCRIPT, OUR_SCRIPT)
os.chmod(OUR_SCRIPT, 0755)
sys.exit(0)
开发者ID:artschwagerb,项目名称:pi_director,代码行数:32,代码来源:pifm_agent.py
示例3: assert_hg_count
def assert_hg_count(count, rev=None):
'''Assuming you are in an hg repository, assert that ``count`` commits
have been made to that repo.'''
if rev:
assert sh.grep(sh.hg.log(rev=rev), 'changeset:').stdout.count(b'\n') == count
else:
assert sh.grep(sh.hg.log(), 'changeset:').stdout.count(b'\n') == count
开发者ID:jedbrown,项目名称:gitifyhg,代码行数:7,代码来源:helpers.py
示例4: make_stats
def make_stats(self, rerun = False):
self.stats = {}
if os.path.exists(self.out_dir + "mapper/"):
if os.path.exists(self.out_dir + self.name + "_stats.json") and not rerun:
print "Loading stats for", self.name
with open(self.out_dir + self.name + "_stats.json") as handle:
self.stats = json.load(handle)
else:
print "Computing stats for", self.name
self.stats['raw_reads'] = self.pairs
self.stats['output'] = self.out_dir
print "Computing raw number of paired-reads"
self.stats['read_count'] = int(sh.zgrep("-Ec", "$", self.reads))/4
print "Computing clean number of paired-reads"
self.stats['clean_read_count'] = int(sh.grep("-Ec", "$", self.reads.replace("fastq.gz","clean.fastq")))/4
self.stats['ratios'] = float(self.stats['clean_read_count'])/float(self.stats['read_count'])
for k in tqdm(self.success_ks):
self.stats[k] = {}
self.stats[k]['Success'] = os.path.exists(self.out_dir + "ray_" + str(k) + "/Contigs.fasta")
if self.stats[k]['Success']:
t=sh.assemstats(0,self.out_dir + "ray_" + str(k) + "/Contigs.fasta" )
self.stats[k]['Assembly'] = {a:b for a,b in zip(*[[w.strip() for w in l.split("\t")][1:] for l in str(t).split("\n")[0:2]])}
self.stats[k]['mapped_frac'] = float(sh.grep("overall", self.out_dir + "map_" + str(k) + ".err").split(" ")[0][0:-1])/100
self.stats[k]['dupli_frac'] = float(sh.grep("Unknown", self.out_dir + "mapper/ray_" +str(k)+ "_" + self.name+ "-smd.metrics").split("\t")[7])
with open(self.out_dir + self.name + "_stats.json", 'w') as handle:
json.dump(self.stats, handle)
开发者ID:moritzbuck,项目名称:assemblies,代码行数:27,代码来源:__init__.py
示例5: check_if_running_polkit_auth
def check_if_running_polkit_auth():
"""
check if polkit authentication agent is running
and launch it if it is not
"""
try:
grep(ps('aux'), '[p]olkit-gnome-authentication-agent-1')
except sh.ErrorReturnCode_1:
logger.debug('polkit auth agent not found, trying to launch it...')
run_polkit_auth_agent()
开发者ID:andrejb,项目名称:bitmask_client,代码行数:10,代码来源:polkit.py
示例6: 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)
开发者ID:laegrim,项目名称:gitberg,代码行数:12,代码来源:catalog.py
示例7: _info_celery
def _info_celery(self):
d = {}
try:
lines = sh.grep(
sh.grep(self._ps(), "celery"), "worker").split("\n")[:-1]
for line in lines:
(pid, command) = line.lstrip().split(" ", 1)
d[pid] = line
except:
pass
return d
开发者ID:lee212,项目名称:cloudmesh,代码行数:12,代码来源:server_admin.py
示例8: find_process_pid
def find_process_pid(process_line, child_process=False):
ps_opts = 'auxww' if not child_process else 'auxfww'
try:
pid = sh.awk(
sh.grep(
sh.grep(sh.ps(ps_opts, _piped=True, _tty_out=False), "-ie", process_line),
'-v', 'grep'),
"{print $2}",
)
except sh.ErrorReturnCode:
raise AssertionError("Cannot find process pid")
return pid.strip()
开发者ID:nutbunnies,项目名称:cstar_perf,代码行数:13,代码来源:utils.py
示例9: cache_ssh_key
def cache_ssh_key(hostname):
"""
Request the host's key and cache it in .ssh/known_hosts
http://serverfault.com/questions/321167/add-correct-host-key-in-known-hosts-multiple-ssh-host-keys-per-hostname
"""
try:
sh.grep('-q', hostname, SSH_KNOWN_HOSTS)
except sh.ErrorReturnCode:
with open(SSH_KNOWN_HOSTS, 'ab') as known_hosts_file:
known_hosts_file.write('\n')
keyscan = sh.Command('ssh-keyscan')
keyscan('-t', 'rsa', hostname, _out=known_hosts_file)
开发者ID:baremetal,项目名称:debgit,代码行数:15,代码来源:ssh.py
示例10: findImage
def findImage(repository, tag):
container=""
try:
container = sh.awk("{print $3}", _in=sh.head("-n 1", _in=sh.grep(tag, _in=sh.docker("images", repository))))
except:
print "container not available"
return container.rstrip()
开发者ID:hefee,项目名称:docker,代码行数:7,代码来源:dockerutils.py
示例11: get_free_mb
def get_free_mb(folder):
df_result = grep(df("-k", folder), "/")
kb_sizes = map(int, filter(is_int, df_result.split(" ")))
available_mb = kb_sizes[2] / 1024
return available_mb
开发者ID:Velrok,项目名称:CleanUP-After-Me,代码行数:7,代码来源:cleanup.py
示例12: get
def get(self):
query = unquote(self.get_argument('q'))
try:
results = str(grep('-R', '--exclude-dir', '.git', query,
self.settings.repo))
except ErrorReturnCode_1 as e:
results = ''
try:
results += str(find(self.settings.repo, '-type', 'f', '-name',
'*' + query + '*', '-not', '(', '-path',
'%s/%s/*' % (self.settings.repo, '.git') ))
except ErrorReturnCode_1 as e:
pass
results = results.replace(self.settings.repo, '').split('\n')[:-1]
formatted_results = []
for result in results:
if 'Binary file' in result or result == '':
continue
# TODO this doesn't play well with colons in filenames
stuff = result.split(':')
filename = stuff[0]
if path.basename(filename).startswith('.'):
filename = path.join(path.dirname(filename),
path.basename(filename)[1:])
string = ''.join(stuff[1:])
string = self._highlight(string, query)
formatted_results.append({'filename': filename, 'string': string})
self.render('search.html', query=query, results=formatted_results)
开发者ID:ThomicArt,项目名称:magpie,代码行数:31,代码来源:search.py
示例13: findContainer
def findContainer(name):
container=""
try:
container = sh.awk("{print $1}", _in=sh.head("-n 1", _in=sh.grep(name, _in=sh.docker.ps())))
except:
print "container not available"
return container.rstrip()
开发者ID:cmollekopf,项目名称:docker,代码行数:7,代码来源:dockerutils.py
示例14: ip_adresses
def ip_adresses():
"""
IP Host und Device auslesen bzw setzen
"""
check = sh.ifconfig
check = sh.grep("inet")
print check
开发者ID:jitter77,项目名称:practice,代码行数:7,代码来源:ReadSerial.py
示例15: check_if_needed
def check_if_needed(path):
if path[-6:] == '_r.MOV':
return False
file_name, ext = os.path.splitext(path)
conv_name = os.path.join(WORKDIR, file_name + '_r' + ext)
if os.path.isfile(conv_name):
return False
try:
result = grep(grep(mediainfo(path), i='Rotation'), '180')
except sh.ErrorReturnCode_1 as e:
return False
return True
开发者ID:akademic,项目名称:iphone-video-rotate,代码行数:17,代码来源:converter.py
示例16: _get_last_two_deploys
def _get_last_two_deploys(environment):
import sh
git = sh.git.bake(_tty_out=False)
pipe = git('tag')
pipe = sh.grep(pipe, environment)
pipe = sh.sort(pipe, '-rn')
pipe = sh.head(pipe, '-n2')
return pipe.strip().split('\n')
开发者ID:tlwakwella,项目名称:commcare-hq,代码行数:8,代码来源:utils.py
示例17: force_push
def force_push(git, branch):
try:
git.push('origin', branch, '--force')
except sh.ErrorReturnCode_128 as e:
# oops we're using a read-only URL, so change to the suggested url
line = sh.grep(' Use ', _in=e.stderr)
edit_url = line.strip().split()[1]
git.remote('set-url', 'origin', edit_url)
git.push('origin', branch, '--force')
开发者ID:amonkeykong81,项目名称:commcare-hq,代码行数:9,代码来源:rebuildstaging.py
示例18: get_vendor
def get_vendor(mac):
if not mac:
return None
grepped = grep(
mac.upper().replace(':','')[:6],
OUI_FILE,
_ok_code=[0,1]
)
return str(grepped)[7:] or '<unknown vendor>'
开发者ID:lenolib,项目名称:ipmac-lookup,代码行数:9,代码来源:ipmac_lookup.py
示例19: get_remote_branches
def get_remote_branches(origin, git=None):
git = git or get_git()
branches = [
line.strip().replace('origin/HEAD -> ', '')[len(origin) + 1:]
for line in
sh.grep(
git.branch('--remote'), r'^ {}'.format(origin)
).strip().split('\n')
]
return branches
开发者ID:amonkeykong81,项目名称:commcare-hq,代码行数:10,代码来源:check-all-merges.py
示例20: get_node_ip
def get_node_ip():
"""Returns the node's IP, for the interface
that is being used as the default gateway.
This should work on both MacOS X and Linux."""
try:
default_interface = grep(netstat('-nr'), '-e', '^default', '-e' '^0.0.0.0').split()[-1]
my_ip = ifaddresses(default_interface)[2][0]['addr']
return my_ip
except:
raise Exception("Unable to resolve local IP address.")
开发者ID:viaict,项目名称:screenly-ose,代码行数:10,代码来源:utils.py
注:本文中的sh.grep函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论