|
|
|
@ -10,7 +10,7 @@ import types
|
|
|
|
|
from time import sleep
|
|
|
|
|
import re
|
|
|
|
|
import sys
|
|
|
|
|
from cl_utils import runOsCommand,isMount,removeDir
|
|
|
|
|
from cl_utils import runOsCommand,isMount,removeDir,typeFile
|
|
|
|
|
from shutil import copyfile
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -42,7 +42,6 @@ class DistributiveRepository:
|
|
|
|
|
'march':"|".join(marches),
|
|
|
|
|
'ext':"|".join(extensiton)
|
|
|
|
|
}, re.X)
|
|
|
|
|
|
|
|
|
|
def __init__(self,directory):
|
|
|
|
|
self.root = directory
|
|
|
|
|
|
|
|
|
@ -63,10 +62,31 @@ class DistributiveRepository:
|
|
|
|
|
return True
|
|
|
|
|
return [ dist for dist in os.listdir(self.root) if distfilter(dist) ]
|
|
|
|
|
|
|
|
|
|
def _getDistributiveByFile(self,filename):
|
|
|
|
|
# MAGIC_COMPRESS 0x000004 Check inside compressed files
|
|
|
|
|
tf = typeFile(magic=0x4)
|
|
|
|
|
ftype = tf.getMType(filename)
|
|
|
|
|
if "ISO 9660 CD-ROM" in ftype:
|
|
|
|
|
return IsoDistributive(filename)
|
|
|
|
|
elif "7-zip" in ftype or \
|
|
|
|
|
"POSIX tar archive" in ftype:
|
|
|
|
|
return ArchiveDistributive(filename)
|
|
|
|
|
elif "Squashfs filesystem" in ftype:
|
|
|
|
|
return SquashDistributive(filename)
|
|
|
|
|
else:
|
|
|
|
|
raise DistributiveError("Wrong distributive '%s':\n%s"%
|
|
|
|
|
(filename,ftype))
|
|
|
|
|
|
|
|
|
|
def getLastDistributive(self,system=None,shortname=None,march=None,
|
|
|
|
|
version=None):
|
|
|
|
|
return self._getAvailableDistributives(system,shortname,march,
|
|
|
|
|
version)[0]
|
|
|
|
|
availDistrs = self._getAvailableDistributives(system,shortname,
|
|
|
|
|
march,version)
|
|
|
|
|
# TODO: add priority for select actualy distributive
|
|
|
|
|
if availDistrs:
|
|
|
|
|
return self._getDistributiveByFile(
|
|
|
|
|
pathjoin(self.root,availDistrs[0]))
|
|
|
|
|
else:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
class Distributive(object):
|
|
|
|
|
"""Distributive object. Parent object for all distributive."""
|
|
|
|
@ -118,7 +138,7 @@ class Distributive(object):
|
|
|
|
|
self.childs = []
|
|
|
|
|
# if has parent
|
|
|
|
|
if self.parent:
|
|
|
|
|
self.parent().releaseChild(self)
|
|
|
|
|
self.parent(None).releaseChild(self)
|
|
|
|
|
self.parent = None
|
|
|
|
|
|
|
|
|
|
def releaseChild(self,child):
|
|
|
|
@ -148,6 +168,9 @@ class Distributive(object):
|
|
|
|
|
# instance"""
|
|
|
|
|
# self.close()
|
|
|
|
|
|
|
|
|
|
def getDirectory(self):
|
|
|
|
|
return self.convertTo(DirectoryDistributive).directory
|
|
|
|
|
|
|
|
|
|
def _makeDirectory(self,path):
|
|
|
|
|
"""Make directory and parent.
|
|
|
|
|
|
|
|
|
@ -258,12 +281,20 @@ class DirectoryDistributive(Distributive):
|
|
|
|
|
class PartitionDistributive(Distributive):
|
|
|
|
|
reRightPartition = re.compile(r"^/dev/(sd[a-z]\d+|cciss/c\d+d\d+)$")
|
|
|
|
|
|
|
|
|
|
def __init__(self,partition,parent=None,mdirectory="/mnt/calculate"):
|
|
|
|
|
"""Raise DistributiveError if partition has bad name"""
|
|
|
|
|
def __init__(self,partition,parent=None,mdirectory="/mnt/calculate",
|
|
|
|
|
check=False):
|
|
|
|
|
"""Initialize partition distributive
|
|
|
|
|
|
|
|
|
|
mdirectory - directory for mount
|
|
|
|
|
check - check partition name and raise DistributiveError if partition
|
|
|
|
|
has bad name
|
|
|
|
|
"""
|
|
|
|
|
Distributive.__init__(self,parent=parent)
|
|
|
|
|
self.partition = partition
|
|
|
|
|
self.mdirectory = mdirectory
|
|
|
|
|
if not self.reRightPartition.match(partition):
|
|
|
|
|
if check and not partition is None and \
|
|
|
|
|
(not self.reRightPartition.match(partition) or \
|
|
|
|
|
not pathexists(partition)):
|
|
|
|
|
raise DistributiveError("Wrong partition name '%s'"%partition)
|
|
|
|
|
|
|
|
|
|
def _mountPartition(self,partition,directory):
|
|
|
|
@ -326,26 +357,30 @@ class ArchiveDistributive(Distributive):
|
|
|
|
|
else:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
def _unpackArchive(self,file,directory):
|
|
|
|
|
def _unpackArchive(self,archfile,directory):
|
|
|
|
|
"""Unpack archive"""
|
|
|
|
|
# archive is exists
|
|
|
|
|
if not pathexists(file):
|
|
|
|
|
raise DistributiveError("File '%s' not found"%file)
|
|
|
|
|
if not pathexists(archfile):
|
|
|
|
|
raise DistributiveError("File '%s' not found"%archfile)
|
|
|
|
|
# detect type archive
|
|
|
|
|
archiveType = self._detectArchive(file)
|
|
|
|
|
archiveType = self._detectArchive(archfile)
|
|
|
|
|
# make directory if archive was detected normally
|
|
|
|
|
if archiveType:
|
|
|
|
|
self._makeDirectory(directory)
|
|
|
|
|
# unpack archive
|
|
|
|
|
if archiveType == "7z":
|
|
|
|
|
res,mes = runOsCommand("7za x -so %s | tar xf - -C %s/"%
|
|
|
|
|
(file,directory))
|
|
|
|
|
(archfile,directory))
|
|
|
|
|
elif archiveType == "bzip2":
|
|
|
|
|
res,mes = runOsCommand("tar xjf %s -C %s/"% (file,directory))
|
|
|
|
|
res,mes = runOsCommand("tar xjf %s -C %s/"%
|
|
|
|
|
(archfile,directory))
|
|
|
|
|
elif archiveType == "gzip":
|
|
|
|
|
res,mes = runOsCommand("tar xf %s -C %s/"%(file,directory))
|
|
|
|
|
res,mes = runOsCommand("tar xf %s -C %s/"%
|
|
|
|
|
(archfile,directory))
|
|
|
|
|
else:
|
|
|
|
|
raise DistributiveError("Unknown archive type by '%s'"%file)
|
|
|
|
|
if res != 0:
|
|
|
|
|
raise DistributiveError("Error during unpacking\n%s"%mes)
|
|
|
|
|
|
|
|
|
|
def unpackTo(self,directory):
|
|
|
|
|
"""Unpack currect archive to directory"""
|
|
|
|
@ -400,7 +435,7 @@ class SquashDistributive(Distributive):
|
|
|
|
|
def _mountSquash(self,file,directory):
|
|
|
|
|
"""Mount squashfs to directory"""
|
|
|
|
|
self._makeDirectory(directory)
|
|
|
|
|
self._mountPartition(file,directory,mountopts="-o loop -t squashfs")
|
|
|
|
|
self._mountToDirectory(file,directory,mountopts="-o loop -t squashfs")
|
|
|
|
|
|
|
|
|
|
def _umountSquash(self,directory):
|
|
|
|
|
self._umountDirectory(directory)
|
|
|
|
@ -464,7 +499,7 @@ class IsoDistributive(Distributive):
|
|
|
|
|
curfile = None
|
|
|
|
|
curnum = -1
|
|
|
|
|
for file in os.listdir(directory):
|
|
|
|
|
res = self.reLive.search(i)
|
|
|
|
|
res = self.reLive.search(file)
|
|
|
|
|
if res:
|
|
|
|
|
if res.groups()[1]:
|
|
|
|
|
num = int(res.groups()[1])
|
|
|
|
@ -557,3 +592,6 @@ class IsoDistributive(Distributive):
|
|
|
|
|
except KeyboardInterrupt,e:
|
|
|
|
|
self._removeDirectory(isoDirectory)
|
|
|
|
|
raise DistributiveError("Keyboard interrupt")
|
|
|
|
|
|
|
|
|
|
class ScratchDistributive(Distributive):
|
|
|
|
|
pass
|
|
|
|
|