本文整理汇总了Python中util.run_command函数的典型用法代码示例。如果您正苦于以下问题:Python run_command函数的具体用法?Python run_command怎么用?Python run_command使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run_command函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_dev
def get_dev(user_mod=''):
'''
use v4l-info to determine device for a given driver module
'''
if user_mod == 'bttv0':
user_mod = 'bttv'
with run_command('ls /dev/video*', do_popen=True) as pop_:
for line in pop_:
devname = line.strip()
if hasattr(devname, 'decode'):
devname = devname.decode()
if not os.path.exists('/usr/bin/v4l-info'):
print('YOU NEED TO INSTALL v4l-conf')
exit(0)
driver = ''
with run_command('v4l-info %s 2> /dev/null | grep driver'
% devname, do_popen=True) as v4linfo:
for line in v4linfo:
if hasattr(line, 'decode'):
line = line.decode()
if line != '':
driver = line.split()[2].strip('"')
if user_mod in driver or (not user_mod and driver == 'em28xx'):
return devname
示例2: build_ns3
def build_ns3(config, build_examples, build_tests, args, build_options):
cmd = [sys.executable, "waf", "configure"] + args
if build_examples:
cmd.append("--enable-examples")
if build_tests:
cmd.append("--enable-tests")
try:
ns3_traces, = config.getElementsByTagName("ns-3-traces")
except ValueError:
# Don't print a warning message here since regression traces
# are no longer used.
pass
else:
cmd.extend([
"--with-regression-traces", os.path.join("..", ns3_traces.getAttribute("dir")),
])
try:
pybindgen, = config.getElementsByTagName("pybindgen")
except ValueError:
print "Note: configuring ns-3 without pybindgen"
else:
cmd.extend([
"--with-pybindgen", os.path.join("..", pybindgen.getAttribute("dir")),
])
run_command(cmd) # waf configure ...
run_command([sys.executable, "waf", "build"] + build_options)
示例3: install_pkgs
def install_pkgs(self, pkg_lst, mnt_pt):
for pkg in pkg_lst:
self.install_package(mnt_pt, pkg)
#clean apt package cache
util.run_command("chroot %s /usr/bin/apt-get clean" % mnt_pt)
示例4: run
def run(self,input):
filename = tempfile.mktemp()
f = open(filename,'wb')
cmd = self.command
if input: cmd += '< %s' % input.pathname
util.run_command(cmd, f.write, self.callback.log)
f.close()
return {'output': File(filename)}
示例5: _disable_ttys
def _disable_ttys(self, mnt_pt):
#disable gettys
util.run_command("sed -i -e 's/^\([1-6].*:respawn*\)/#\1/' -e 's/^T/#\t/' %s/etc/inittab" % mnt_pt)
text = "S0:12345:respawn:/sbin/getty -L console 9600 vt100\n"
util.write_to_file("%s/etc/inittab" % mnt_pt, "a", text)
示例6: copy_kernel_modules
def copy_kernel_modules(self, mnt_pt):
#disable hw clock
#os.chmod("%s/etc/init.d/hwclock.sh" % mnt_pt, 0644)
#copy kernek modules
kernel_version = os.path.basename(self._kernel)[8:]
util.run_command("cp -r /lib/modules/%s \
%s/lib/modules/%s" % (kernel_version, mnt_pt, kernel_version))
示例7: netanim_download
def netanim_download():
local_file = required_netanim_version + ".tar.bz2"
remote_file = constants.NETANIM_RELEASE_URL + "/" + local_file
print "Retrieving NetAnim from " + remote_file
urllib.urlretrieve(remote_file, local_file)
print "Uncompressing " + local_file
run_command(["tar", "-xjf", local_file])
print "Rename %s as %s" % (required_netanim_version, constants.LOCAL_NETANIM_PATH)
os.rename(required_netanim_version, constants.LOCAL_NETANIM_PATH)
示例8: run
def run(self, **k):
input = k["test data"]
model = k["model"]
filename = tempfile.mktemp()
cmd = "%s %s %s %s" % (svm_predict_pathname, input.pathname, model.pathname, filename)
log = self.callback.log
log("# Running %s\n" % cmd)
util.run_command(cmd, log, log)
return {"output": TextFile(filename, autodel=True)}
示例9: pipeline_monogenic_validation
def pipeline_monogenic_validation(work_dir=os.environ['OBER_OUT'] + '/requests/monogenic/work',
index_segments_dir=os.environ['OBER_OUT'] + '/requests/monogenic/work/index_segments',
region_size=100,
theta_affinity=0.95,
theta_weight=0.5,
regenerate_segments=True,
snps=None, # np.array([6, 8]),
debug=1,
debug_sample=512):
# Load SNPs
problem = im.io.read_plink(prefix=work_dir + '/monogenic.12', pedigree=im.itu.HUTT_PED, haplotype=None, frames=None)
# Testing: simulate aligned samples output (hap types should be 2 in the imputed genotype output line)
problem.haplotype.poo_phase = np.zeros((problem.num_samples,), dtype=np.byte)
problem.haplotype.poo_phase[np.array([0, 1])] = 1
problem.haplotype.poo_phase[np.array([2, 3])] = -1
# Create segments only for the regions around each snp
if regenerate_segments:
for row in (problem.info.snp[snps] if snps is not None else problem.info.snp):
# Find SNP's region (the one containing its base-pair position)
chrom, bp = row['chrom'], row['base_pair']
phasing_dir = '%s/phasing/chr%d' % (os.environ['OBER_OUT'], chrom)
index_segments_chrom_dir = '%s/chr%d' % (index_segments_dir, chrom)
info_file = '%s/hutt.phased.info.npz' % (phasing_dir,)
info = im.io.read_info_npz(info_file)
snp_bp = info.snp['base_pair']
snp_index = util.nearest_neighbor_in_list_tree(bp, snp_bp, util.list_index_tree(snp_bp))
snp_index = snp_index if snp_bp[snp_index] <= bp else snp_index - 1
start = region_size * (snp_index / region_size)
stop = start + region_size
segment_file = '%s/segments-%d-%d.out' % (index_segments_chrom_dir, start, stop)
if not os.path.exists(segment_file):
util.mkdir_if_not_exists(index_segments_chrom_dir)
util.run_command('find-segments-of-snp-range %d %d < %s/segments.out > %s' % (start, stop, phasing_dir, segment_file))
# Index segments
if regenerate_segments or \
not os.path.exists('%s/metadata.npz' % (index_segments_chrom_dir,)) or \
not os.path.exists('%s/region-%d.npz' % (index_segments_chrom_dir, start)):
index_segments_beagle.main(segment_file, info_file, segment_file, index_segments_chrom_dir,
snp_index=snp_index, debug=2,
theta_affinity=theta_affinity, theta_weight=theta_weight)
# Impute using the newly generated segment index
_, t = im.v.iv.impute_problem(problem, debug=debug, remove_partial_calls=True,
segment_location=index_segments_dir, # if regenerate_segments else None,
snps=snps, debug_sample=debug_sample)
im.io.write_plink(im.Problem(genotype=t.imputed, pedigree=im.examples.hutt_pedigree(), haplotype=None, frames=None),
work_dir + '/imputed.12', save_frames=False, save_haplotype=False)
im.cgi.io_cgi.write_imputed(t, sys.stdout, poo_phase=problem.haplotype.poo_phase)
with open(work_dir + '/imputed.12.lgen', 'wb') as f:
im.cgi.io_cgi.write_imputed_lgen(t, f)
return t
示例10: install
def install(self):
"""mount disk image and download base system"""
#mount disk image
mnt_pt = "/mnt/%s" % self._name
os.mkdir(mnt_pt)
util.run_command("mount -o loop %s %s" % (self._path, mnt_pt))
#download base system
print "Downloading %s base system\n" % self._release
return util.run_command("debootstrap --arch %s %s %s %s" %
(self._arch, self._release, mnt_pt, self._location))
示例11: post_install
def post_install(self):
# create /etc/fstab, /etc/hostname, /etc/network/interfaces, /etc/hosts
# create xen config file, unmount disk image
mnt_pt = "/mnt/%s" % self._name
print "Setting up guest OS %s\n" % self._name
print "Copying kernel modules\n"
self.copy_kernel_modules(mnt_pt)
print "Disabling extra ttys\n"
self._disable_ttys(mnt_pt)
print "Setting up apt\n"
text = """# %s/stable
deb http://archive.ubuntu.com/ubuntu/ %s main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu %s-security main restricted universe multiverse
""" % (
self._release,
self._release,
self._release,
)
self._apt_setup(text, mnt_pt)
print "installing libc6-xen, udev, ssh\n"
self.install_pkgs(["libc6-xen", "openssh-server", "udev"], mnt_pt)
# create /etc/fstab
print "Setting up filesystem table\n"
self.create_fstab(mnt_pt)
print "Setting up networking\n"
self.network_setup(mnt_pt)
# hack to prevent nash-hotplug from hogging cpu
self.kill_nash_hotplug(mnt_pt)
print "Creating initrd for %s\n" % self._name
self.create_initrd()
print "Generating xen configuration file /etc/xen/%s\n" % self._name
self.create_xen_config()
# unmount filesystem
util.run_command("umount %s" % mnt_pt)
os.rmdir(mnt_pt)
print "Installation of guest domain %s complete!!!" % self._name
return 0
示例12: list_auto_snapshot_sets
def list_auto_snapshot_sets(self, tag = None):
"""
Returns a list of zfs filesystems and volumes tagged with
the "com.sun:auto-snapshot" property set to "true", either
set locally or inherited. Snapshots are excluded from the
returned result.
Keyword Arguments:
tag:
A string indicating one of the standard auto-snapshot schedules
tags to check (eg. "frequent" will map to the tag:
com.sun:auto-snapshot:frequent). If specified as a zfs property
on a zfs dataset, the property corresponding to the tag will
override the wildcard property: "com.sun:auto-snapshot"
Default value = None
"""
#Get auto-snap property in two passes. First with the global
#value, then overriding with the label/schedule specific value
included = []
excluded = []
cmd = [ZFSCMD, "list", "-H", "-t", "filesystem,volume",
"-o", "name,com.sun:auto-snapshot", "-s", "name"]
if tag:
overrideprop = "com.sun:auto-snapshot:" + tag
scmd = [ZFSCMD, "list", "-H", "-t", "filesystem,volume",
"-o", "name," + overrideprop, "-s", "name"]
outdata,errdata = util.run_command(scmd)
for line in outdata.rstrip().split('\n'):
line = line.split()
if line[1] == "true":
included.append(line[0])
elif line[1] == "false":
excluded.append(line[0])
outdata,errdata = util.run_command(cmd)
for line in outdata.rstrip().split('\n'):
line = line.split()
# Only set values that aren't already set. Don't override
try:
included.index(line[0])
continue
except ValueError:
try:
excluded.index(line[0])
continue
except ValueError:
# Dataset is not listed in either list.
if line[1] == "true":
included.append(line[0])
return included
示例13: get_regression_traces
def get_regression_traces(ns3_dir, regression_branch):
print """
#
# Get the regression traces
#
"""
# ns3_dir is the directory into which we cloned the repo
# regression_branch is the repo in which we will find the traces. Variations like this should work:
# ns-3-dev-ref-traces
# craigdo/ns-3-dev-ref-traces
# craigdo/ns-3-tap-ref-traces
regression_traces_dir = os.path.split(regression_branch)[-1]
regression_branch_url = constants.REGRESSION_TRACES_REPO + regression_branch
print "Synchronizing reference traces using Mercurial."
try:
if not os.path.exists(regression_traces_dir):
run_command(["hg", "clone", regression_branch_url, regression_traces_dir])
else:
run_command(["hg", "-q", "pull", "--cwd", regression_traces_dir, regression_branch_url])
run_command(["hg", "-q", "update", "--cwd", regression_traces_dir])
except OSError: # this exception normally means mercurial is not found
if not os.path.exists(regression_traces_dir_name):
traceball = regression_tbranch + constants.TRACEBALL_SUFFIX
print "Retrieving " + traceball + " from web."
urllib.urlretrieve(constants.REGRESSION_TRACES_URL + traceball, traceball)
run_command(["tar", "-xjf", traceball])
print "Done."
return regression_traces_dir
示例14: _disable_ttys
def _disable_ttys(self, mnt_pt):
util.run_command("rm -f %s/etc/event.d/tty[2-6]" % mnt_pt)
lines = util.pipe_command("cat %s/etc/event.d/tty1" % mnt_pt)
if self._release == "feisty":
lines[-1] = "exec /sbin/getty -L 9600 console vt100\n"
else:
lines[-1] = "respawn /sbin/getty -L 9600 console vt100\n"
fd = None
try:
fd = open("%s/etc/event.d/tty1" % mnt_pt, "w")
fd.writelines(lines)
finally:
if fd is not None:
fd.close()
示例15: build_ns3
def build_ns3(config, build_examples, build_tests):
cmd = [
"python", "waf", "configure",
]
if build_examples:
cmd.append("--enable-examples")
if build_tests:
cmd.append("--enable-tests")
try:
ns3_traces, = config.getElementsByTagName("ns-3-traces")
except ValueError:
# Don't print a warning message here since regression traces
# are no longer used.
pass
else:
cmd.extend([
"--with-regression-traces", os.path.join("..", ns3_traces.getAttribute("dir")),
])
try:
pybindgen, = config.getElementsByTagName("pybindgen")
except ValueError:
print "Note: configuring ns-3 without pybindgen"
else:
cmd.extend([
"--with-pybindgen", os.path.join("..", pybindgen.getAttribute("dir")),
])
try:
nsc, = config.getElementsByTagName("nsc")
except ValueError:
print "Note: configuring ns-3 without NSC"
else:
# Build NSC if the architecture supports it
if sys.platform not in ['linux2']:
arch = None
else:
arch = os.uname()[4]
if arch == 'x86_64' or arch == 'i686' or arch == 'i586' or arch == 'i486' or arch == 'i386':
cmd.extend(["--with-nsc", os.path.join("..", nsc.getAttribute("dir"))])
else:
print "Note: configuring ns-3 without NSC (architecture not supported)"
run_command(cmd)
run_command(["python", "waf"])