Exemplo n.º 1
0
 def get(self):
     chrootPath = self.Get('cl_chroot_path')
     pathOldUdevNet = path.join(chrootPath,
         'etc/udev/rules.d/70-persistent-net.rules')
     pathNewUdevNet = path.join(chrootPath,
         'etc/udev/rules.d/80-net-name-slot.rules')
     pathOrigUdevNet = path.join(chrootPath,
         'lib/udev/rules.d/80-net-name-slot.rules')
     if path.exists(pathOldUdevNet) or \
         (path.exists(pathNewUdevNet) and 
         hashlib.md5(readFile(pathNewUdevNet)).digest() != \
         hashlib.md5(readFile(pathOrigUdevNet)).digest()):
         return self.Get('os_install_net_interfaces')
     def getOrig(x):
         try:
             nameParam = filter(lambda x:x.startswith("ID_NET_NAME_PATH="),
                         process("udevadm","test-builtin","net_id",
                                 "/sys/class/net/%s"%x))
             if nameParam:
                 return nameParam[0].partition('=')[2].strip() or x
         except Exception as e:
             print str(e)
             return x
         return x
     return map(getOrig,self.Get('os_install_net_interfaces'))
Exemplo n.º 2
0
 def get(self):
     """Laptop vendor"""
     chassisType = '/sys/class/dmi/id/chassis_type'
     boardVendor = '/sys/class/dmi/id/board_vendor'
     notebookChassis = ['1','8','10']
     if readFile(chassisType).strip() in notebookChassis:
         return (readFile(boardVendor).strip().split(" ")[0]).lower() or \
             "unknown"
     return ""
Exemplo n.º 3
0
def checkContents(pkg,fileName,prefix='/',reservedFile=None):
    """
    Check contents with newContent
    """
    contentFile = path.join(prefix,'var/db/pkg/%s/CONTENTS'%pkg)
    if prefix != '/' and fileName.startswith(prefix):
        shortName = fileName[len(prefix):]
    else:
        shortName = fileName

    TYPE,FILENAME,MD5,MTIME=0,1,2,3
    obj = filter(lambda x:x[1] == shortName,
          map(lambda x:x.split(' '),
          filter(lambda x:x.startswith('obj'),
          readLinesFile(contentFile))))
    # if pkg not content filename
    if not obj:
        # for using reserved -CONTENTS file on postinst
        if not reservedFile or checkReserved(fileName,reservedFile):
            return True
        else:
            return False
    # if file is not exists
    if not path.exists(fileName):
        # for using reserved -CONTENTS file on postinst
        if not reservedFile or checkReserved(fileName,reservedFile):
            return True
        else:
            return False
    contentMD5 = hashlib.md5(readFile(fileName)).hexdigest().strip()
    configMD5 = obj[0][MD5].strip()
    # if content was not changed
    if contentMD5 == configMD5:
        return True
    return False
Exemplo n.º 4
0
 def getVersionFromOverlay(self,systemroot):
     """
     Get version from overlay calculate-release
     """
     overlayPath = 'var/lib/layman/calculate'
     releaseFile = 'profiles/calculate-release'
     return readFile(path.join(systemroot,overlayPath,releaseFile))
Exemplo n.º 5
0
 def get(self):
     image = self.Get('cl_image')
     try:
         if image:
             image = image.convertToDirectory()
             chrootPath = image.getDirectory()
             chrootPath = image.getDirectory()
         else:
             chrootPath = self.Get("cl_chroot_path")
         nvidiaeclass = path.join(chrootPath,
                                  'usr/portage/eclass/nvidia-driver.eclass')
         if not os.access(nvidiaeclass,os.R_OK):
             return ""
         category = "0300"
         vendor = "10de:"
         lsPciProg = getProgPath("/usr/sbin/lspci")
         nvidiacards = filter(lambda x:" %s: "%category in x,
                       process(lsPciProg,"-d",vendor,"-n"))
         if not nvidiacards:
             return ""
         cardsid = \
             map(lambda x:x.groups()[0],
             filter(lambda x:x,
             map(lambda x:re.search("[0-9a-fA-F]{4}:([0-9a-fA-F]{4})",x),
             nvidiacards)))
         if not cardsid:
             return ""
         eclassdata = readFile(nvidiaeclass)
         drv_categories = re.findall('^drv_([^=]+)="', eclassdata, re.M)
         drvs = map(lambda x:(x[0],x[1].replace('\\\n','').split()),
                re.findall('\ndrv_(%s)="(.*?)"'%"|".join(drv_categories),
                                eclassdata,re.S))
         mask_categories = re.findall('^mask_([^=]+)="', eclassdata, re.M)
         masks = dict(map(lambda x:(x[0],x[1].replace('\\\n','')),
                 re.findall('\nmask_(%s)="(.*?)"'%"|".join(drv_categories),
                                eclassdata,re.S)))
         drvsForCardsid = filter(lambda x:set(x[1])&set(cardsid),drvs)
         if drvsForCardsid and drvsForCardsid[0][0] in masks:
             return masks[drvsForCardsid[0][0]]
     finally:
         if image:
             image.close()
     return ""
Exemplo n.º 6
0
def checkReserved(fileName,contentFile):
    """
    Check contents with newContent
    """
    TYPE,FILENAME,MD5,MTIME=0,1,2,3
    obj = filter(lambda x:x[1] == fileName,
          map(lambda x:x.split(' '),
          filter(lambda x:x.startswith('obj'),
          readLinesFile(contentFile))))
    # if pkg not content filename
    if not obj:
        return True
    # if file is not exists
    if not path.exists(fileName):
        return True
    contentMD5 = hashlib.md5(readFile(fileName)).hexdigest().strip()
    configMD5 = obj[0][MD5].strip()
    # if content was not changed
    if contentMD5 == configMD5:
        return True
    return False
Exemplo n.º 7
0
 def get(self):
     """Root filesystem device"""
     record = readFile('/proc/cmdline').strip()
     re_resRealRoot=re.search('(?:^|\s)real_root=(\S+)(\s|$)',record)
     re_resFakeRoot=re.search('(?:^|\s)root=(\S+)(\s|$)',record)
     # param real_root priority that root
     re_res = re_resRealRoot or re_resFakeRoot
     if re_res:
         rootparam=re_res.group(1)
         # check root for /dev/sd view
         if re.match("^\/dev\/[a-z]+.*$", rootparam):
             return getUdevDeviceInfo(
                name=rootparam.strip()).get('DEVNAME',rootparam)
         # check root set by uuid
         if re.match("^UUID=.*$",rootparam):
             uuid = rootparam[5:].strip("\"'")
             blkidProcess = process('/sbin/blkid','-c','/dev/null','-U',
                                 uuid)
             if blkidProcess.success():
                 return getUdevDeviceInfo(
                    name=blkidProcess.read().strip()).get('DEVNAME','')
         # check root set by label
         if re.match("^LABEL=.*$",rootparam):
             uuid = rootparam[6:].strip("\"'")
             blkidProcess = process('/sbin/blkid','-c','/dev/null','-L',
                                 uuid)
             if blkidProcess.success():
                 return getUdevDeviceInfo(
                    name=blkidProcess.read().strip()).get('DEVNAME','')
     # get device mounted to root
     dfProcess = process('df','/',envdict={'LANG':'C'})
     if dfProcess.failed():
         return ""
     dfLines = dfProcess.readlines()
     if len(dfLines)>1:
         root_dev = dfLines[1].split(" ")[0].strip()
         if root_dev:
             return {'none':'/dev/ram0'}.get(root_dev,root_dev)
     return ""
Exemplo n.º 8
0
 def addFile(self,filename):
     newfilename = pathJoin(self.prefix,filename)
     filename = self.reCfg.sub("/",filename)
     self.content[filename] = {'type':'obj',
               'md5':hashlib.md5(readFile(newfilename)).hexdigest(),
               'mtime':str(int(os.stat(newfilename).st_mtime))}
Exemplo n.º 9
0
 def get(self):
     """Get motherboard vendor"""
     vendorFile = "/sys/class/dmi/id/board_vendor"
     return readFile(vendorFile).strip()
Exemplo n.º 10
0
 def get(self):
     modelFile = "/sys/class/dmi/id/board_name"
     return readFile(modelFile).strip()
Exemplo n.º 11
0
 def get(self):
     boardName = '/sys/class/dmi/id/board_name'
     if self.Get('hr_laptop') and os.access(boardName,os.R_OK):
         valBoardName = readFile(boardName).strip()
         return valBoardName or "unknown"
     return ""
Exemplo n.º 12
0
 def dispatchConf(self,filesApply=None):
     """
     Common dispatch conf. Using if ._cfg files created.
     """
     ORIG,DATA=0,1
     MTIME,CFGFNAME=0,1
     FIRST=0
     cfgFiles = getCfgFiles().items()
     info = filter(lambda x:filesApply is None or \
                           x[DATA][FIRST][CFGFNAME] in filesApply,
            cfgFiles)
     maxInfo = len(info)
     for ind,data in enumerate(info):
         out = []
         orig,data = data
         data = data[FIRST]
         for i,s in enumerate(list(process("diff","-Nu",
                    orig,data[CFGFNAME]))):
             if s.startswith('+') and i>1:
                 out.append('<font color="green">%s</font>'%s)
             elif s.startswith('-') and i>1:
                 out.append('<font color="red">%s</font>'%s)
             else:
                 out.append(s)
         self.printPre("<br/>".join(out))
         self.printSUCCESS(_("({one} of {_all}) -- {fname}").format(
             one=ind+1,_all=maxInfo,fname=orig))
         answ = self.askChoice(_("Choice action with config:"),
                 answers=(("zap new",_("Zap new")),
                          ("use new",_("Use new")),
                          ("next",_("Next"))))
         if answ == "next":
             continue
         elif answ == "use new":
             try:
                 open(orig,'w').write(
                     readFile(data[CFGFNAME]))
                 os.unlink(data[CFGFNAME])
                 if not filesApply is None:
                     try:
                         i = filesApply.index(data[CFGFNAME])
                         filesApply[i] = orig
                     except Exception as e:
                         print str(e)
             except Exception as e:
                 print str(e)
                 self.printERROR(
                     _("Failed to copy {ffrom} to {fto}").format(
                      ffrom=data[CFGFNAME],fto=orig))
                 continue
         elif answ == "zap new":
             try:
                 os.unlink(data[CFGFNAME])
                 if not filesApply is None:
                     try:
                         filesApply.remove(data[CFGFNAME])
                     except Exception as e:
                         print str(e)
             except Exception as e:
                 self.printERROR(
                     _("Failed to remove %s")%data[CFGFNAME])
     return True