本文整理汇总了Python中execcmd.ExecCmd.run方法的典型用法代码示例。如果您正苦于以下问题:Python ExecCmd.run方法的具体用法?Python ExecCmd.run怎么用?Python ExecCmd.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类execcmd.ExecCmd
的用法示例。
在下文中一共展示了ExecCmd.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getLinuxHeadersAndImage
# 需要导入模块: from execcmd import ExecCmd [as 别名]
# 或者: from execcmd.ExecCmd import run [as 别名]
def getLinuxHeadersAndImage(getLatest=False, includeLatestRegExp='', excludeLatestRegExp=''):
returnList = []
lhList = []
ec = ExecCmd(log)
if getLatest:
lst = ec.run('aptitude search linux-headers', False)
for item in lst:
lhMatch = re.search('linux-headers-\d+\.[a-zA-Z0-9-\.]*', item)
if lhMatch:
lh = lhMatch.group(0)
addLh = True
if includeLatestRegExp != '':
inclMatch = re.search(includeLatestRegExp, lh)
if not inclMatch:
addLh = False
if excludeLatestRegExp != '':
exclMatch = re.search(excludeLatestRegExp, lh)
if exclMatch:
addLh = False
# Append to list
if addLh:
lhList.append(lh)
else:
# Get the current linux header package
linHeader = ec.run("echo linux-headers-$(uname -r)", False)
lhList.append(linHeader[0])
# Sort the list and add the linux-image package name
if lhList:
lhList.sort(reverse=True)
returnList.append(lhList[0])
returnList.append('linux-image-' + lhList[0][14:])
return returnList
示例2: DistroGeneral
# 需要导入模块: from execcmd import ExecCmd [as 别名]
# 或者: from execcmd.ExecCmd import run [as 别名]
class DistroGeneral(object):
def __init__(self, distroPath):
self.ec = ExecCmd()
distroPath = distroPath.rstrip('/')
if basename(distroPath) == "root":
distroPath = dirname(distroPath)
self.distroPath = distroPath
self.rootPath = join(distroPath, "root")
self.edition = basename(distroPath)
self.description = "SolydXK"
infoPath = join(self.rootPath, "etc/solydxk/info")
if exists(infoPath):
self.edition = self.ec.run(cmd="grep EDITION= \"{}\" | cut -d'=' -f 2".format(infoPath), returnAsList=False).strip('"')
self.description = self.ec.run(cmd="grep DESCRIPTION= \"{}\" | cut -d'=' -f 2".format(infoPath), returnAsList=False).strip('"')
def getIsoFileName(self):
# Get the date string
d = datetime.now()
serial = d.strftime("%Y%m")
# Check for a localized system
localePath = join(self.rootPath, "etc/default/locale")
if exists(localePath):
locale = self.ec.run(cmd="grep LANG= {}".format(localePath), returnAsList=False).strip('"').replace(" ", "")
matchObj = re.search("\=\s*([a-z]{2})", locale)
if matchObj:
language = matchObj.group(1)
if language != "en":
serial += "_{}".format(language)
isoFileName = "{}_{}.iso".format(self.description.lower().replace(' ', '_').split('-')[0], serial)
return isoFileName
示例3: previewPlymouth
# 需要导入模块: from execcmd import ExecCmd [as 别名]
# 或者: from execcmd.ExecCmd import run [as 别名]
def previewPlymouth():
cmd = "su -c 'plymouthd; plymouth --show-splash ; for ((I=0; I<10; I++)); do plymouth --update=test$I ; sleep 1; done; plymouth quit'"
log.write('Preview command: ' + cmd, 'drivers.previewPlymouth', 'debug')
try:
ec = ExecCmd(log)
ec.run(cmd, False)
except Exception, detail:
log.write(detail, 'drivers.previewPlymouth', 'error')
示例4: getKernelPackages
# 需要导入模块: from execcmd import ExecCmd [as 别名]
# 或者: from execcmd.ExecCmd import run [as 别名]
def getKernelPackages(getLatest=False, includeLatestRegExp='', excludeLatestRegExp=''):
lst = []
ec = ExecCmd(log)
if getLatest:
cmdList = ec.run('apt-get -s dist-upgrade | grep "linux-image" | grep ^Inst', False)
if not cmdList:
# Already the latest kernel: get all linux-image packages of the current version
kernelRelease = getKernelRelease()
if 'amd64' in kernelRelease:
cmd = "aptitude search linux-image-%s" % kernelRelease
else:
pos = kernelRelease.find('486')
if pos == 0:
pos = kernelRelease.find('686')
if pos > 0:
kernelRelease = kernelRelease[0:pos - 1]
cmd = "aptitude search linux-image-%s" % kernelRelease
cmdList = ec.run(cmd, False)
for item in cmdList:
if not '-dbg' in item:
obj = re.search('linux\-image\-[a-z0-9\-\.]*', item)
if obj:
img = obj.group(0)
addImg = True
if includeLatestRegExp != '':
inclObj = re.search(includeLatestRegExp, img)
if not inclObj:
addImg = False
if excludeLatestRegExp != '':
exclObj = re.search(excludeLatestRegExp, img)
if exclObj:
addImg = False
# Append to list
if addImg:
lst.append(img)
lst.append(string.replace(img, "image", "headers"))
if not lst:
# Get the current linux header package
cmdList = ec.run('echo linux-image-$(uname -r)', False)
img = cmdList[0]
lst.append(img)
lst.append(string.replace(img, "image", "headers"))
else:
# Get the current linux header package
cmdList = ec.run('echo linux-image-$(uname -r)', False)
img = cmdList[0]
lst.append(img)
lst.append(string.replace(img, "image", "headers"))
return lst
示例5: isPackageInstalled
# 需要导入模块: from execcmd import ExecCmd [as 别名]
# 或者: from execcmd.ExecCmd import run [as 别名]
def isPackageInstalled(packageName, alsoCheckVersion=True):
isInstalled = False
try:
cmd = 'dpkg-query -l %s | grep ^i' % packageName
if '*' in packageName:
cmd = 'aptitude search %s | grep ^i' % packageName
ec = ExecCmd(log)
pckList = ec.run(cmd, False)
for line in pckList:
matchObj = re.search('([a-z]+)\s+([a-z0-9\-_\.]*)', line)
if matchObj:
if matchObj.group(1)[:1] == 'i':
if alsoCheckVersion:
cache = apt.Cache()
pkg = cache[matchObj.group(2)]
if pkg.installed.version == pkg.candidate.version:
isInstalled = True
break
else:
isInstalled = True
break
if isInstalled:
break
except:
pass
return isInstalled
示例6: getPackageStatus
# 需要导入模块: from execcmd import ExecCmd [as 别名]
# 或者: from execcmd.ExecCmd import run [as 别名]
def getPackageStatus(packageName):
status = ''
try:
cmdChk = 'apt-cache policy ' + str(packageName)
ec = ExecCmd(log)
packageCheck = ec.run(cmdChk, False)
for line in packageCheck:
instChk = re.search('installed:.*\d.*', line.lower())
if not instChk:
instChk = re.search('installed.*', line.lower())
if instChk:
# Package is not installed
log.write('Package not installed: ' + str(packageName), 'drivers.getPackageStatus', 'debug')
status = packageStatus[1]
break
else:
# Package is installed
log.write('Package is installed: ' + str(packageName), 'drivers.getPackageStatus', 'debug')
status = packageStatus[0]
break
# Package is not found: uninstallable
if not status:
log.write('Package not found: ' + str(packageName), 'drivers.getPackageStatus', 'warning')
status = packageStatus[2]
except:
# If something went wrong: assume that package is uninstallable
log.write('Could not get status info for package: ' + str(packageName), 'drivers.getPackageStatus', 'error')
status = packageStatus[2]
return status
示例7: Mirror
# 需要导入模块: from execcmd import ExecCmd [as 别名]
# 或者: from execcmd.ExecCmd import run [as 别名]
class Mirror():
def __init__(self, log=None):
self.log = log
self.ec = ExecCmd()
def save(self, replaceRepos):
try:
src = '/etc/apt/sources.list'
if os.path.exists(src):
dt = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
msg = _("Backup %(src)s to %(src)s.%(date)s") % { "src": src, "src": src, "date": dt }
self.log.write(msg, "Mirror.save", "debug")
os.system("cp -f %s %s.%s" % (src, src, dt))
new_repos = []
cmd = "cat %s" % src
lstOut = self.ec.run(cmd, False)
for line in lstOut:
line = str(unicode(line.strip(), 'ascii', 'ignore'))
if not line.startswith('#'):
for repo in replaceRepos:
if repo[0] in line:
line = line.replace(repo[0], repo[1])
new_repos.append(line)
if new_repos:
f = open(src, 'w')
for repo in new_repos:
f.write("%s\n" % repo)
#print "%s\n" % repo
f.close()
except Exception, detail:
# This is a best-effort attempt, fail graciously
self.log.write(str(detail), "Mirror.save", "exception")
示例8: DistroGeneral
# 需要导入模块: from execcmd import ExecCmd [as 别名]
# 或者: from execcmd.ExecCmd import run [as 别名]
class DistroGeneral(object):
def __init__(self, distroPath):
self.ec = ExecCmd()
distroPath = distroPath.rstrip('/')
if basename(distroPath) == "root":
distroPath = dirname(distroPath)
self.distroPath = distroPath
self.rootPath = join(distroPath, "root")
lsb_release_path = join(self.rootPath, "etc/lsb-release")
self.edition = get_lsb_release_info('DISTRIB_CODENAME', lsb_release_path)
self.description = get_lsb_release_info('DISTRIB_DESCRIPTION', lsb_release_path)
if len(self.edition) == 0: self.edition = basename(distroPath)
if len(self.description) == 0: self.description = basename(distroPath)
def getIsoFileName(self):
# Get the date string
d = datetime.now()
serial = d.strftime("%Y%m")
# Check for a localized system
localePath = join(self.rootPath, "etc/default/locale")
if exists(localePath):
locale = self.ec.run(cmd="grep LANG= '%s'" % localePath, returnAsList=False).strip('"').replace(" ", "")
matchObj = re.search("\=\s*([a-z]{2})", locale)
if matchObj:
language = matchObj.group(1)
if language != "en":
serial += "_{}".format(language)
isoFileName = "{}_{}.iso".format(self.description.lower().replace(' ', '_').split('-')[0], serial)
return isoFileName
示例9: getCurrentTheme
# 需要导入模块: from execcmd import ExecCmd [as 别名]
# 或者: from execcmd.ExecCmd import run [as 别名]
def getCurrentTheme():
curTheme = ['']
if getCurrentResolution() != '':
cmd = '/usr/sbin/plymouth-set-default-theme'
ec = ExecCmd(log)
curTheme = ec.run(cmd, False)
return curTheme[0]
示例10: getLatestLunuxHeader
# 需要导入模块: from execcmd import ExecCmd [as 别名]
# 或者: from execcmd.ExecCmd import run [as 别名]
def getLatestLunuxHeader(includeString='', excludeString=''):
lhList = []
ec = ExecCmd(log)
list = ec.run('apt search linux-headers', False)
startIndex = 14
for item in list:
lhMatch = re.search('linux-headers-\d[a-zA-Z0-9-\.]*', item)
if lhMatch:
lh = lhMatch.group(0)
addLh = True
if includeString != '':
inclMatch = re.search(includeString, lh)
if inclMatch:
if excludeString != '':
exclMatch = re.search(excludeString, lh)
if exclMatch:
addLh = False
else:
addLh = False
# Append to list
if addLh:
lhList.append(lh)
lhList.sort(reverse=True)
return lhList[0]
示例11: killProcessByName
# 需要导入模块: from execcmd import ExecCmd [as 别名]
# 或者: from execcmd.ExecCmd import run [as 别名]
def killProcessByName(processName):
killed = False
ec = ExecCmd(log)
lst = ec.run('killall %s' % processName)
if len(lst) == 0:
killed = True
return killed
示例12: getDivertedFiles
# 需要导入模块: from execcmd import ExecCmd [as 别名]
# 或者: from execcmd.ExecCmd import run [as 别名]
def getDivertedFiles(mustContain=None):
divertedFiles = []
cmd = 'dpkg-divert --list'
if mustContain:
cmd = 'dpkg-divert --list | grep %s | cut -d' ' -f3' % mustContain
ec = ExecCmd(log)
divertedFiles = ec.run(cmd, False)
return divertedFiles
示例13: isProcessRunning
# 需要导入模块: from execcmd import ExecCmd [as 别名]
# 或者: from execcmd.ExecCmd import run [as 别名]
def isProcessRunning(processName):
isProc = False
cmd = 'ps -C ' + processName
ec = ExecCmd(log)
procList = ec.run(cmd, False)
if procList:
if len(procList) > 1:
isProc = True
return isProc
示例14: getSystemVersionInfo
# 需要导入模块: from execcmd import ExecCmd [as 别名]
# 或者: from execcmd.ExecCmd import run [as 别名]
def getSystemVersionInfo():
info = ''
try:
ec = ExecCmd(log)
infoList = ec.run('cat /proc/version', False)
if infoList:
info = infoList[0]
except Exception, detail:
log.write(detail, 'functions.getSystemVersionInfo', 'error')
示例15: getDistribution
# 需要导入模块: from execcmd import ExecCmd [as 别名]
# 或者: from execcmd.ExecCmd import run [as 别名]
def getDistribution():
distribution = ''
try:
cmdDist = 'cat /etc/*-release | grep DISTRIB_CODENAME'
ec = ExecCmd(log)
dist = ec.run(cmdDist, False)[0]
distribution = dist[dist.find('=') + 1:]
except Exception, detail:
log.write(detail, 'functions.getDistribution', 'error')