本文整理汇总了Python中execcmd.ExecCmd类的典型用法代码示例。如果您正苦于以下问题:Python ExecCmd类的具体用法?Python ExecCmd怎么用?Python ExecCmd使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExecCmd类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getCurrentTheme
def getCurrentTheme():
curTheme = ['']
if getCurrentResolution() != '':
cmd = '/usr/sbin/plymouth-set-default-theme'
ec = ExecCmd(log)
curTheme = ec.run(cmd, False)
return curTheme[0]
示例2: getLinuxHeadersAndImage
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
示例3: getLatestLunuxHeader
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]
示例4: killProcessByName
def killProcessByName(processName):
killed = False
ec = ExecCmd(log)
lst = ec.run('killall %s' % processName)
if len(lst) == 0:
killed = True
return killed
示例5: isPackageInstalled
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
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: DistroGeneral
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
示例8: getDivertedFiles
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
示例9: previewPlymouth
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')
示例10: isProcessRunning
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
示例11: getDistribution
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')
示例12: getSystemVersionInfo
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')
示例13: isPackageInstalled
def isPackageInstalled(packageName):
isInstalled = False
cmd = 'aptitude search ' + packageName + ' | grep ^i'
ec = ExecCmd(log)
packageList = ec.run(cmd, False)
if packageList:
if len(packageList) > 0:
isInstalled = True
return isInstalled
示例14: getDistributionDescription
def getDistributionDescription():
distribution = ''
try:
cmdDist = 'cat /etc/*-release | grep DISTRIB_DESCRIPTION'
ec = ExecCmd(log)
dist = ec.run(cmdDist, False)[0]
distribution = dist[dist.find('=') + 1:]
distribution = string.replace(distribution, '"', '')
except Exception, detail:
log.write(detail, 'functions.getDistributionDescription', 'error')
示例15: getVideoCards
def getVideoCards(pciId=None):
videoCard = []
cmdVideo = 'lspci -nn | grep VGA'
ec = ExecCmd(log)
hwVideo = ec.run(cmdVideo, False)
for line in hwVideo:
videoMatch = re.search(':\s(.*)\[(\w*):(\w*)\]', line)
if videoMatch and (pciId is None or pciId.lower() + ':' in line.lower()):
videoCard.append([videoMatch.group(1), videoMatch.group(2), videoMatch.group(3)])
return videoCard