Modified using some functions:

pathjoin as path.join
pathexists as path.exists
netsetup
Mike Hiretsky 14 years ago
parent 9ff8be29f4
commit 40c55d49c6

@ -14,9 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from os.path import exists as pathexists
from os.path import dirname as pathdirname
from os.path import join as pathjoin
from os import path
from random import choice
import string
import os
@ -110,7 +108,7 @@ class DistributiveRepository:
def _get_from_metapackage(self,directory,shortname):
"""Get version from meta package"""
metaPkgs = filter(lambda x:"%s-meta"%shortname.lower() in x,
os.listdir(pathjoin(directory,
os.listdir(path.join(directory,
'var/db/pkg/app-misc/')))
if metaPkgs:
reFindVer = re.compile("(?<=\-)\d+\.?\d*\.?\d*")
@ -121,7 +119,7 @@ class DistributiveRepository:
def _get_from_calculate_ini(self,directory):
"""Get version from calculate ini"""
path = pathjoin(directory,'/etc/calculate/calculate.ini')
path = path.join(directory,'etc/calculate/calculate.ini')
if os.path.exists(path):
FD = open(path)
data = FD.readlines()
@ -136,7 +134,7 @@ class DistributiveRepository:
def _getdistrshortname(self,directory='/'):
"""Get distributive shortname"""
makeprofile = pathjoin(directory,'etc/make.profile')
makeprofile = path.join(directory,'etc/make.profile')
if os.path.exists(makeprofile):
link = os.readlink(makeprofile)
reMakeProfileLink = re.compile('calculate/(desktop|server)/(%s)/'%
@ -144,9 +142,9 @@ class DistributiveRepository:
shortnameSearch = reMakeProfileLink.search(link)
if shortnameSearch:
return shortnameSearch.groups()[1]
path = pathjoin(directory,'etc/calculate/calculate.ini')
if os.path.exists(path):
FD = open(path)
pathini = path.join(directory,'etc/calculate/calculate.ini')
if os.path.exists(pathini):
FD = open(pathini)
data = FD.readlines()
FD.close()
shortNameList = filter(lambda y:y,
@ -156,18 +154,18 @@ class DistributiveRepository:
x.split("=")[1].strip(), data))
if shortNameList:
return shortNameList[0]
gentooFile = pathjoin(directory,"etc/gentoo-release")
gentooFile = path.join(directory,"etc/gentoo-release")
shortName = "Linux"
if os.path.exists(gentooFile):
if path.exists(gentooFile):
shortName = "Gentoo"
return shortName
def _getdistrinfo(self,filename):
"""Get information by distributive"""
if os.path.isdir(filename):
d = self.ini_to_dict(pathjoin(filename,
if path.isdir(filename):
d = self.ini_to_dict(path.join(filename,
'etc/calculate/calculate.ini'))
if d and pathexists(pathjoin(filename,'lib64')):
if d and path.exists(path.join(filename,'lib64')):
d['march'] = 'x86_64'
else:
d['march']= 'i686'
@ -200,15 +198,16 @@ class DistributiveRepository:
return False
else:
return True
def listdistr(path):
if pathexists(pathjoin(path,'etc/make.profile')):
return [path]
def listdistr(pathname):
if path.exists(path.join(pathname,'etc/make.profile')):
return [pathname]
else:
# discard inner directories
return filter(lambda x:not os.path.isdir(pathjoin(path,x)),
os.listdir(path))
return filter(lambda x:not path.isdir(
path.join(pathname,x)),
os.listdir(pathname))
# get lists files in directories
allFiles = map(lambda x: map(lambda y: pathjoin(x,y),
allFiles = map(lambda x: map(lambda y: path.join(x,y),
listdistr(x)),
# discard not exists distrib directories
filter(lambda x: os.access(x,os.R_OK),
@ -231,7 +230,7 @@ class DistributiveRepository:
return ArchiveDistributive(filename)
elif "Squashfs filesystem" in ftype:
return SquashDistributive(filename)
elif os.path.isdir(filename):
elif path.isdir(filename):
return DirectoryDistributive(filename)
else:
raise DistributiveError(_("Wrong distributive") + " '%s':\n%s"\
@ -358,22 +357,22 @@ class Distributive(object):
def getDirectory(self):
return self.convertToDirectory().directory
def _makeDirectory(self,path):
def _makeDirectory(self,pathname):
"""Make directory and parent.
If directory exists then return False else True"""
try:
parent = os.path.split(os.path.normpath(path))[0]
if not pathexists(parent):
parent = path.split(path.normpath(pathname))[0]
if not path.exists(parent):
self._makeDirectory(parent)
else:
if pathexists(path):
if path.exists(pathname):
return False
os.mkdir(path)
os.mkdir(pathname)
return True
except (Exception,KeyboardInterrupt),e:
raise DistributiveError(_("Cann't create directory") +" '%s':\n%s"
%(path,str(e)))
%(pathname,str(e)))
def _removeDirectory(self,directory):
"""Remove directory and files contained in it"""
@ -494,7 +493,7 @@ class Distributive(object):
If queried name is not free then to name append random string
"""
newDirectoryName = directory
while pathexists(newDirectoryName):
while path.exists(newDirectoryName):
newDirectoryName = "%s.%s"%(directory,self.rndString())
return newDirectoryName
@ -767,7 +766,7 @@ class PartitionDistributive(Distributive):
self.formatPartition(self.partition,format=self.fileSystem)
def changeSystemID(self,dev,systemid):
parentDir = os.path.split(dev)[0]
parentDir = path.split(dev)[0]
def detectDeviceForPartition(dev):
"""Detect parent device for partition by /sys/block (sysfs)"""
device = map(lambda x:filter(lambda x:x in dev,
@ -776,15 +775,15 @@ class PartitionDistributive(Distributive):
if device:
device = device[0]
parentdevices = \
filter(lambda x: os.path.split(dev)[-1] in \
filter(lambda x: path.split(dev)[-1] in \
reduce(lambda y,z:y+z[1],
os.walk(os.path.join('/sys/block',x)),[]), device)
os.walk(path.join('/sys/block',x)),[]), device)
if parentdevices:
return parentdevices[0]
return dev[:-1]
pipe = Popen(["/sbin/fdisk",
pathjoin('/dev',detectDeviceForPartition(dev))],
pipe = Popen(["/sbin/fdisk",
path.join('/dev',detectDeviceForPartition(dev))],
stdin=PIPE, stdout=PIPE,stderr=PIPE)
pipe.stdin.write("t\n%s\n%s\nw\n"%(dev[-1],systemid))
pipe.stdin.close()
@ -840,7 +839,7 @@ class ArchiveDistributive(Distributive):
def _unpackArchive(self,archfile,directory):
"""Unpack archive"""
# archive is exists
if not pathexists(archfile):
if not path.exists(archfile):
raise DistributiveError(_("File '%s' not found")%archfile)
# detect type archive
archiveType = self._detectArchive(archfile)
@ -973,18 +972,18 @@ class IsoDistributive(Distributive):
self._umountIso(mdirectory)
raise DistributiveError(_("Iso %s doesn't contain live image") %
self.file)
return SquashDistributive(pathjoin(mdirectory,fileLive),
return SquashDistributive(path.join(mdirectory,fileLive),
parent=self)
def getIsoContentDirectory(self):
"""Return directory with content of iso image"""
squash = self.convertToSquash()
return pathdirname(squash.file)
return path.dirname(squash.file)
def releaseChild(self,child):
"""Umount child Directory distributive"""
if isinstance(child,SquashDistributive):
self._umountIso(pathdirname(child.file))
self._umountIso(path.dirname(child.file))
child.directory = None
def convertToDirectory(self):
@ -992,14 +991,14 @@ class IsoDistributive(Distributive):
def prepareIso(self,directory):
print(_("apply iso templates to %s/")%directory)
self._makeDirectory(pathjoin(directory,"isolinux"))
self._makeDirectory(path.join(directory,"isolinux"))
self._copyfile("/usr/share/syslinux/isolinux.bin",
pathjoin(directory,"isolinux/isolinux.bin"))
path.join(directory,"isolinux/isolinux.bin"))
def packToIso(self,directory,file):
# remove previous version of iso
try:
if pathexists(file):
if path.exists(file):
os.unlink(file)
except (Exception,KeyboardInterrupt),e:
raise DistributiveError(_("Cann't remove") +\
@ -1030,11 +1029,11 @@ class IsoDistributive(Distributive):
# getting squash from source
if isinstance(source,SquashDistributive):
self._copyfile(source.file,
pathjoin(isoDirectory,"livecd.squashfs"))
path.join(isoDirectory,"livecd.squashfs"))
else:
distDirectory = source.convertToDirectory()
squashDistr = SquashDistributive(
pathjoin(isoDirectory,"livecd.squashfs"))
path.join(isoDirectory,"livecd.squashfs"))
squashDistr.installFrom(distDirectory)
# prepare iso
@ -1062,7 +1061,7 @@ class FlashDistributive(PartitionDistributive):
else:
distDirectory = source.convertToDirectory()
squashDistr = SquashDistributive(
pathjoin(isoDirectory,"livecd.squashfs"))
path.join(isoDirectory,"livecd.squashfs"))
squashDistr.installFrom(distDirectory)
class ScratchDistributive(Distributive):
@ -1071,9 +1070,9 @@ class ScratchDistributive(Distributive):
Distributive.__init__(self,parent=parent)
self.directory = directory
self.mdirectory = mdirectory
if check and not (pathexists(pathjoin(directory,"workspace")) and \
pathexists(pathjoin(directory,"delta")) and \
pathexists(pathjoin(directory,"calculate"))):
if check and not (path.exists(path.join(directory,"workspace")) and \
path.exists(path.join(directory,"delta")) and \
path.exists(path.join(directory,"calculate"))):
raise DistributiveError(
"Wrong scratch distributive in '%s'"%directory)
@ -1083,9 +1082,9 @@ class ScratchDistributive(Distributive):
self._mountToDirectory("none",target,
mountopts="-t aufs "+\
"-o udba=reval,br:%(work)s=rw:%(delta)s=ro+wh:%(static)s=ro" %\
{"work":pathjoin(source,"workspace"),
"delta":pathjoin(source,"delta"),
"static":pathjoin(source,"calculate")})
{"work":path.join(source,"workspace"),
"delta":path.join(source,"delta"),
"static":path.join(source,"calculate")})
def _umountLayers(self,directory):
self._umountDirectory(directory)
@ -1108,8 +1107,8 @@ class ScratchDistributive(Distributive):
return child
mdirectory = self._getMntDirectory(mdirectory)
liveFile = self._getLastLive(self.directory)
self._mountLiveImage(pathjoin(self.directory,liveFile),
pathjoin(self.directory,"calculate"))
self._mountLiveImage(path.join(self.directory,liveFile),
path.join(self.directory,"calculate"))
self._mountLayers(self.directory,mdirectory)
return DirectoryDistributive(mdirectory,parent=self)
@ -1117,7 +1116,7 @@ class ScratchDistributive(Distributive):
"""Umount child Directory distributive"""
if isinstance(child,DirectoryDistributive):
self._umountLayers(child.directory)
self._umountLiveImage(pathjoin(self.directory,"calculate"))
self._umountLiveImage(path.join(self.directory,"calculate"))
child.directory = None
def installFrom(self, source):
@ -1151,13 +1150,13 @@ class ScratchPartitionDistributive(PartitionDistributive):
def prepareScratch(self,directory):
for scrDirectory in ("calculate","delta","workspace"):
self._makeDirectory(pathjoin(directory,scrDirectory))
self._makeDirectory(path.join(directory,scrDirectory))
def postinstallMountBind(self):
dirDistr = self.convertToDirectory().directory
scrDir = self.convertToScratch().directory
self._copytree(pathjoin(dirDistr,"boot"),
pathjoin(scrDir,"boot"))
self._copytree(path.join(dirDistr,"boot"),
path.join(scrDir,"boot"))
def installFrom(self, source):
"""Install distributive to partition from source distributive"""
@ -1171,11 +1170,11 @@ class ScratchPartitionDistributive(PartitionDistributive):
source = source.convertToSquash()
if isinstance(source,SquashDistributive):
self._copyfile(source.file,
pathjoin(scratchDirectory,"livecd.squashfs"))
path.join(scratchDirectory,"livecd.squashfs"))
else:
distDirectory = source.convertToDirectory()
squashDistr = SquashDistributive(
pathjoin(scratchDirectory,"livecd.squashfs"))
path.join(scratchDirectory,"livecd.squashfs"))
squashDistr.installFrom(distDirectory)
# prepare scratch

@ -19,7 +19,7 @@ import re
from crypt import crypt
import cl_overriding
from cl_datavars import glob_attr
from os.path import join as pathjoin, exists as pathexists
from os import path
from os import readlink,listdir,access,R_OK
from cl_utils import isMount,typeFile,getTupleVersion
from cl_distr import DistributiveRepository
@ -70,7 +70,7 @@ class fillVars(object, glob_attr):
continue
fdhcpInfo = "/var/lib/dhcpcd/dhcpcd-%s.info"%interfaces
fdhcpLease = "/var/lib/dhcpcd/dhcpcd-%s.lease"%interfaces
if pathexists(fdhcpInfo) or pathexists(fdhcpLease):
if path.exists(fdhcpInfo) or path.exists(fdhcpLease):
listInterfacesInfo.append((interfaces, "DHCP"))
# Если интерфейс без DHCP
if not (interfaces, "DHCP") in listInterfacesInfo:
@ -90,9 +90,9 @@ class fillVars(object, glob_attr):
def get_os_device_hash(self):
diskIdPath = '/dev/disk/by-id'
if pathexists(diskIdPath):
if path.exists(diskIdPath):
usbdevices = \
map(lambda x: readlink(pathjoin(diskIdPath,x)).rpartition('/')[2],
map(lambda x: readlink(path.join(diskIdPath,x)).rpartition('/')[2],
filter(lambda x: x.startswith('usb-'),listdir(diskIdPath)))
else:
usbdevices = []
@ -261,12 +261,12 @@ class fillVars(object, glob_attr):
"""List mount options for partition devices of installed os"""
return self.Get('os_disk_options')
def isFstabMount(self,path):
def isFstabMount(self,pathname):
"""Get mount point or device from fstab"""
if path == "swap":
if pathname == "swap":
absPath = "swap"
else:
absPath = os.path.abspath(path)
absPath = path.abspath(pathname)
# convert fstab to
# [['/dev/sda3', '/', '', 'reiserfs', 'noatime', '', '', '0', '2\n'],
# ['/dev/sda5', '/var/calculate', 'reiserfs', 'noatime', '0', '0\n']]
@ -531,9 +531,9 @@ class fillVars(object, glob_attr):
res = DistributiveRepository.reDistName.search(imagename)
if res:
return res.groupdict()['ver']
elif os.path.isdir(imagename):
elif path.isdir(imagename):
calculateini = 'etc/calculate/calculate.ini'
d = self.calculateini_to_dict(pathjoin(imagename,calculateini))
d = self.calculateini_to_dict(path.join(imagename,calculateini))
if "linuxver" in d:
return d['linuxver']
else:
@ -629,10 +629,10 @@ class fillVars(object, glob_attr):
# try get timezone from kernel calculate param
timezone = self.getValueFromCmdLine("calculate",2)
if timezone and \
os.path.exists(os.path.join(zoneinfodir,timezone)):
path.exists(path.join(zoneinfodir,timezone)):
return timezone
# get timezone from localtime symlink
if os.path.islink(localtimefile):
if path.islink(localtimefile):
return os.readlink(localtimefile).replace(zoneinfodir,"")
return "UTC"
@ -816,7 +816,7 @@ class fillVars(object, glob_attr):
"""Detect previous system"""
calculate1ini = "/etc/calculate/calculate.ini"
calculate1param = "install.devfrom"
if pathexists(calculate1ini):
if path.exists(calculate1ini):
res = reduce(lambda x,y: [y.rpartition('=')[2].strip()],
filter(lambda x: x.partition("=")[0] == calculate1param,
open(calculate1ini,"r")),
@ -836,27 +836,27 @@ class fillVars(object, glob_attr):
reFindVer = re.compile(
"(?<=version )(\d+\.?\d*\.?\d*\.?\d*)([^\d* ])*(\d*)")
def getFilesByType(self,path,descr):
"""Get files from "path" has "descr" in descriptions"""
filelist = map(lambda x:pathjoin(path,x),os.listdir(path))
def getFilesByType(self,pathname,descr):
"""Get files from "pathname" has "descr" in descriptions"""
filelist = map(lambda x:path.join(pathname,x),os.listdir(pathname))
ftype = typeFile(magic=0x4).getMType
filesWithType = map(lambda x:(x,ftype(x)), filelist)
return filter(lambda x:descr in x[1],filesWithType)
def get_os_install_kernel(self):
bootdir = pathjoin(self.Get('cl_chroot_path'),'boot')
modulesdir = pathjoin(self.Get('cl_chroot_path'),'lib/modules')
bootdir = path.join(self.Get('cl_chroot_path'),'boot')
modulesdir = path.join(self.Get('cl_chroot_path'),'lib/modules')
validKernel = os.listdir(modulesdir)
kernelFiles = self.getFilesByType(bootdir,"Linux kernel")
kernelsWithVer = \
map(lambda x:(x[0],(getTupleVersion("".join(x[1].groups()[0:3:2])),
os.path.getmtime(x[0]))),
path.getmtime(x[0]))),
filter(lambda x:x[1] and x[1].group() in validKernel,
map(lambda x:(x[0],self.reFindVer.search(x[1])),
kernelFiles)))
if kernelsWithVer:
return os.path.split(max(kernelsWithVer,key=itemgetter(1))[0])[-1]
return path.split(max(kernelsWithVer,key=itemgetter(1))[0])[-1]
else:
return "vmlinuz"
@ -883,7 +883,7 @@ class fillVars(object, glob_attr):
return ""
ftype = typeFile(magic=0x4).getMType
kernelfile = pathjoin(self.Get('cl_chroot_path'),'boot',
kernelfile = path.join(self.Get('cl_chroot_path'),'boot',
self.Get('os_install_kernel'))
resKernelVer = self.reFindVer.search(ftype(kernelfile))
if resKernelVer:
@ -892,7 +892,7 @@ class fillVars(object, glob_attr):
self.Get('os_install_arch_machine'),
self.Get('os_install_linux_shortname'))
bootdir = pathjoin(self.Get('cl_chroot_path'),'boot')
bootdir = path.join(self.Get('cl_chroot_path'),'boot')
initramfsFiles = self.getFilesByType(bootdir,"ASCII cpio archive")
initramfsWithVer = \
filter(lambda x: kernelVersion in x[1] and \
@ -900,7 +900,7 @@ class fillVars(object, glob_attr):
map(lambda x:(x[0],initrd_version_by_name(x[0])),
initramfsFiles))
if initramfsWithVer:
return os.path.split(min(initramfsWithVer,
return path.split(min(initramfsWithVer,
key=itemgetter(0))[0])[-1]
if suffix:
return "initrd-%s"%suffix
@ -916,8 +916,8 @@ class fillVars(object, glob_attr):
def get_os_install_kernel_config(self):
configfile = self.Get('os_install_kernel').replace('vmlinuz', 'config')
if configfile.startswith('config') and pathexists(
pathjoin(self.Get('cl_chroot_path'),'boot',configfile)):
if configfile.startswith('config') and path.exists(
path.join(self.Get('cl_chroot_path'),'boot',configfile)):
return configfile
else:
return ""
@ -1003,7 +1003,7 @@ class fillVars(object, glob_attr):
def get_os_format_use(self):
"""Avialable format by mkfs utility"""
return map(lambda x:"yes"
if pathexists(convertDictOpt._fileSystemOpt[x]["makefs"])
if path.exists(convertDictOpt._fileSystemOpt[x]["makefs"])
else "no", self.Get('os_format_type'))
def get_os_install_lang(self):

@ -21,7 +21,7 @@ import os
import re
import sys
import traceback
from os.path import exists as pathexists,join as pathjoin,dirname
from os import path
from cl_utils import runOsCommand,appendProgramToEnvFile, \
removeProgramToEnvFile,pathJoin, \
scanDirectory,process
@ -358,7 +358,7 @@ class convertDictOpt:
def getAllAvailableFileSystemOpt(self):
return filter(lambda x: x in ("default","noformat","defaultflash") or
(not "makefs" in self._fileSystemOpt[x] or
pathexists(self._fileSystemOpt[x]["makefs"])),
path.exists(self._fileSystemOpt[x]["makefs"])),
self.getAllSupportFileSystemOpt())
def _getFileSystemData(self, realFileSystem):
@ -555,7 +555,7 @@ class convertDictOpt:
dictOptions = {}
optFileSystem = optProperties["fileSystem"]
if optProperties["mountPoint"]:
optMountPoint = os.path.normpath(optProperties["mountPoint"])
optMountPoint = path.normpath(optProperties["mountPoint"])
else:
optMountPoint = optProperties["mountPoint"]
# if specified mount point empty of default - it is /
@ -662,16 +662,16 @@ class cltCopy(scanDirectory):
performCopy = scanDirectory.scanningDirectory
def processingFile(self,path,prefix):
def processingFile(self,pathname,prefix):
try:
if path.endswith(".clt"):
targetDir = pathJoin(self.target,dirname(path))
if not pathexists(targetDir):
if pathname.endswith(".clt"):
targetDir = pathJoin(self.target,path.dirname(pathname))
if not path.exists(targetDir):
os.makedirs(targetDir)
copy2(path,pathJoin(self.target,path))
copy2(pathname,pathJoin(self.target,pathname))
except Exception,e:
raise InstallError(_("Can not copy '%s' to '%s'")%
(path,pathJoin(self.target,path)))
(pathname,pathJoin(self.target,pathname)))
return True
class cl_install(color_print):
@ -1410,9 +1410,9 @@ class cl_install(color_print):
def setupOpenGL(self):
defaultGL = "xorg-x11"
pathGlModules = pathjoin(self.clVars.Get('cl_chroot_path'),
pathGlModules = path.join(self.clVars.Get('cl_chroot_path'),
'usr/lib/opengl')
openGLenv = pathjoin(self.clVars.Get('cl_chroot_path'),
openGLenv = path.join(self.clVars.Get('cl_chroot_path'),
'etc/env.d/03opengl')
openGlMods = filter(lambda x:x != "global",
@ -1450,8 +1450,8 @@ class cl_install(color_print):
# install desktop package
if linuxShortname in ("CLD","CLS","CLDG","CLDX"):
desktopLib = '/usr/lib/calculate-2.2/calculate-desktop/pym'
if pathexists(desktopLib):
sys.path.insert(0, os.path.abspath(desktopLib))
if path.exists(desktopLib):
sys.path.insert(0, path.abspath(desktopLib))
from cl_desktop import desktop
objDesktop = desktop()
objDesktop.createClVars()
@ -1460,8 +1460,8 @@ class cl_install(color_print):
# install client package
if linuxShortname in ("CLD","CLDG","CLDX"):
clientLib = '/usr/lib/calculate-2.2/calculate-client/pym'
if pathexists(clientLib):
sys.path.insert(0, os.path.abspath(clientLib))
if path.exists(clientLib):
sys.path.insert(0, path.abspath(clientLib))
from cl_client import client
objClient = client()
objClient.createClVars()
@ -1478,9 +1478,9 @@ class cl_install(color_print):
self.printMessageForTest(_("Adding guest user"))
self.printByResult(objUsers.addUsers("guest","guest"))
pathGlModules = pathjoin(self.clVars.Get('cl_chroot_path'),
pathGlModules = path.join(self.clVars.Get('cl_chroot_path'),
'usr/lib/opengl')
if pathexists(pathGlModules):
if path.exists(pathGlModules):
self.printMessageForTest(_("Configure OpenGL"))
self.printByResult(self.setupOpenGL())
@ -1513,7 +1513,7 @@ class cl_install(color_print):
if not self.clVars.Get('os_install_kernel_config'):
return True
newConfig = KernelConfig( configFile=
pathjoin(self.clVars.Get('cl_chroot_path'),
path.join(self.clVars.Get('cl_chroot_path'),
'boot',self.clVars.Get('os_install_kernel_config')))
newConfig = newConfig.getSectionParams(*importantSections)
conflictOptions = filter(lambda x: x[1]=="M" and
@ -1522,7 +1522,7 @@ class cl_install(color_print):
newConfig)
if conflictOptions:
return True
initrdPath = pathjoin(self.clVars.Get('cl_chroot_path'),
initrdPath = path.join(self.clVars.Get('cl_chroot_path'),
'boot',self.clVars.Get('os_install_initrd'))
return InitRamFs(initrdPath).cleanInitRamFs()

@ -18,7 +18,7 @@ from cl_utils import typeFile,runOsCommand,process
import gzip
import re
import os
from os.path import join as pathjoin
from os import path
from os import access,R_OK
from subprocess import PIPE
from shutil import rmtree
@ -85,12 +85,13 @@ class KernelModules:
def _initModulesData(self):
def holderlistdir(dirpath):
dirs = os.listdir(pathjoin(sysModules,dirpath,"holders"))
return reduce(lambda x,y:x+[y]+holderlistdir(pathjoin(dirpath,"holders",y)),
dirs = os.listdir(path.join(sysModules,dirpath,"holders"))
return reduce(lambda x,y:x+[y]+holderlistdir(path.join(dirpath,
"holders",y)),
dirs, [])
sysModules = '/sys/module'
holderPath = lambda x: pathjoin(sysModules,x,"holders")
refPath = lambda x: pathjoin(sysModules,x,"refcnt")
holderPath = lambda x: path.join(sysModules,x,"holders")
refPath = lambda x: path.join(sysModules,x,"refcnt")
self.loadModules = filter(lambda x: access(holderPath(x),R_OK) and
access(refPath(x),R_OK),
os.listdir(sysModules))
@ -117,12 +118,12 @@ class KernelModules:
class InitRamFs:
def __init__(self,initRamFsFile):
self.initrdFile = initRamFsFile
self.tmpPath = pathjoin('/tmp',os.path.basename(self.initrdFile))
self.tmpPath = path.join('/tmp',path.basename(self.initrdFile))
def _unpackInitRamfs(self):
"""Unpack initramfs"""
self.prevDir = os.getcwd()
if not os.path.exists(self.tmpPath):
if not path.exists(self.tmpPath):
os.mkdir(self.tmpPath)
os.chdir(self.tmpPath)
cpioProcess = process("cpio", "-di")
@ -138,8 +139,8 @@ class InitRamFs:
try:
# get file list for pack
fileList = reduce(lambda x,y: x
+map(lambda z:pathjoin(y[0],z),y[1])
+map(lambda z:pathjoin(y[0],z),y[2]),
+map(lambda z:path.join(y[0],z),y[1])
+map(lambda z:path.join(y[0],z),y[2]),
os.walk(self.tmpPath),
[])
fileList = map(lambda x:x[len(self.tmpPath)+1:],fileList)
@ -190,7 +191,7 @@ class InitRamFs:
# get full path for all delete modules
deleteModulesData = \
reduce(lambda x,y:x+y,
map(lambda x:map(lambda y:pathjoin(x[0],y),x[2]),
map(lambda x:map(lambda y:path.join(x[0],y),x[2]),
deleteModulesData),
[])
map(lambda x:os.unlink(x),deleteModulesData)

Loading…
Cancel
Save