当前位置: 首页>>代码示例>>Python>>正文


Python ExecCmd.run方法代码示例

本文整理汇总了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
开发者ID:linuxer9,项目名称:device-driver-manager,代码行数:36,代码来源:functions.py

示例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
开发者ID:xaosfiftytwo,项目名称:solydxk-constructor,代码行数:33,代码来源:solydxk.py

示例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')
开发者ID:linuxer9,项目名称:device-driver-manager,代码行数:10,代码来源:functions.py

示例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
开发者ID:0rakul,项目名称:updatemanager,代码行数:56,代码来源:functions.py

示例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
开发者ID:0rakul,项目名称:updatemanager,代码行数:28,代码来源:functions.py

示例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
开发者ID:linuxer9,项目名称:device-driver-manager,代码行数:33,代码来源:functions.py

示例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")
开发者ID:0rakul,项目名称:updatemanager,代码行数:37,代码来源:mirror.py

示例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
开发者ID:SolydXK,项目名称:solydxk-constructor,代码行数:31,代码来源:solydxk.py

示例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]
开发者ID:linuxer9,项目名称:device-driver-manager,代码行数:9,代码来源:functions.py

示例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]
开发者ID:AlbertJP,项目名称:device-driver-manager,代码行数:27,代码来源:functions.py

示例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
开发者ID:0rakul,项目名称:updatemanager,代码行数:9,代码来源:functions.py

示例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
开发者ID:0rakul,项目名称:updatemanager,代码行数:10,代码来源:functions.py

示例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
开发者ID:linuxer9,项目名称:device-driver-manager,代码行数:11,代码来源:functions.py

示例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')
开发者ID:linuxer9,项目名称:device-driver-manager,代码行数:11,代码来源:functions.py

示例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')
开发者ID:AlbertJP,项目名称:device-driver-manager,代码行数:11,代码来源:functions.py


注:本文中的execcmd.ExecCmd.run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。