|
|
|
@ -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
|
|
|
|
|