Merge branch 'master' of git.calculate.ru:/calculate-lib

develop
Самоукин Алексей 14 years ago
commit 561abab937

@ -368,32 +368,43 @@ class fillVars(glob_attr):
FD = open(path)
data = FD.readlines()
FD.close()
shortNameList = filter(lambda y:y,
verList = filter(lambda y:y,
map(lambda x:\
len(x.split("="))==2 and\
x.split("=")[0]=="linuxver" and\
x.split("=")[1].strip(), data))
if shortNameList:
return shortNameList[0]
if verList:
reVer=re.compile("^(\d+\.)*\d$",re.S)
reRes = filter(reVer.search,verList)
if reRes:
return reRes[0]
def get_from_gentoo_files():
"""Get version from gentoo files"""
gentooFile = "/etc/gentoo-release"
systemVersion = ""
flagGentoo = False
reVer=re.compile("^(\d+\.)*\d$",re.S)
if os.path.exists(gentooFile):
gentooLink = "/etc/make.profile"
if os.path.islink(gentooLink):
return os.readlink(gentooLink).rpartition("/")[2]
vers = filter(reVer.search,
os.readlink(gentooLink).split('/'))
if vers:
return vers[-1]
def get_from_uname():
"""Get version from uname"""
textLines = self._runos("uname -r")
reVer=re.compile("^(\d+\.)*\d",re.S)
kernelVersion = ""
if textLines:
kernelVersion = textLines[0]
if kernelVersion:
return kernelVersion.partition("-")[0]
reRes = reVer.search(kernelVersion)
if reRes:
return reRes.group()
return get_from_metapackage() or get_from_calculate_ini() or \
get_from_gentoo_files() or get_from_uname() or "0"
@ -487,18 +498,33 @@ class fillVars(glob_attr):
def get_os_root_dev(self):
"""корневой раздел файловой системы"""
for record in open('/proc/cmdline','rb').readlines():
re_res=re.search('^root=(\/dev\/[a-z]+[0-9]).*',record.strip())
re_res=re.search('(?:^|\s)root=(\S+)(\s|$)',record.strip())
if re_res:
return re_res.group(1)
else:
mountLunes = self._runos("mount")
if not mountLunes:
return ""
if type(mountLunes) == types.ListType:
root_dev = mountLunes[0].split("on / type")[0].strip()
if root_dev:
return root_dev
rootparam=re_res.group(1)
# check root for /dev/sd view
if re.match("^\/dev\/[a-z]+[0-9]$",rootparam):
return rootparam
# check root set by uuid
uuidpath = '/dev/disk/by-uuid'
if os.access(uuidpath,os.R_OK):
uuidDevs = filter(os.path.islink,
map(lambda x: os.path.join(uuidpath,x),
os.listdir(uuidpath)))
mapUuidDev = dict(map(lambda x:(os.path.basename(x),
os.path.normpath(os.path.join(uuidpath,
os.readlink(x)))), uuidDevs))
if re.match("^UUID=.*$",rootparam):
uuid = rootparam[5:]
if uuid in mapUuidDev:
return mapUuidDev[uuid]
mountLunes = self._runos("mount")
if not mountLunes:
return ""
if type(mountLunes) == types.ListType:
root_dev = mountLunes[0].split("on / type")[0].strip()
if root_dev:
return root_dev
return ""
def get_os_root_type(self):
"""тип носителя (ram, hdd, livecd)"""
@ -859,20 +885,17 @@ class fillVars(glob_attr):
return state or "off"
def get_hr_laptop(self):
"""Если компьютер ноутбук, то его производитель"""
textLines = self._runos("hal-get-property --udi \
/org/freedesktop/Hal/devices/computer --key system.formfactor")
if not textLines:
return ""
formfactor = textLines[0]
if formfactor == 'laptop':
textLines = self._runos("hal-get-property --udi \
/org/freedesktop/Hal/devices/computer --key system.hardware.vendor")
if textLines:
vendor = textLines[0].split(" ")[0]
else:
vendor = "unknown"
return vendor.lower()
"""Vendor of laptop"""
chassisType = '/sys/class/dmi/id/chassis_type'
boardVendor = '/sys/class/dmi/id/board_vendor'
if os.access(chassisType,os.R_OK) and \
os.access(boardVendor,os.R_OK):
chassis = open(chassisType,'r').read().strip()
notebookChassis = ['1','8','10']
if chassis in notebookChassis:
valBoardVendor = open(boardVendor,'r').read().strip()
return valBoardVendor.split(" ")[0].lower() or \
"unknown"
return ""
def get_hr_video(self):

@ -527,9 +527,10 @@ def pathJoin(*paths):
if len(paths)==1:
return paths[0]
return os.path.join(paths[0],
reduce(os.path.join,
map(lambda x: x.startswith("/") and x[1:] or x,
paths[1:]),''))
reduce(os.path.join,
filter(lambda x:x and x != "/",
map(lambda x: x.startswith("/") and x[1:] or x,
paths[1:])),''))
def getUserPassword(flag="dialog", pwDialog=False):

@ -73,7 +73,7 @@ class xml_gconf(xml_xfce):
try:
self.doc = xml.dom.minidom.parseString(self.text)
except:
self.setError(_("Can not text template is XML"))
self.setError(_("Template text is not XML"))
return False
self.rootNode = self.doc.documentElement
self.bodyNode = self.rootNode

@ -72,7 +72,7 @@ class xml_xfce(_error):
try:
self.doc = xml.dom.minidom.parseString(self.text)
except:
self.setError(_("Can not text template is XML"))
self.setError(_("Template text is not XML"))
return False
self.rootNode = self.doc.documentElement
self.bodyNode = self.rootNode
@ -245,10 +245,10 @@ the same nodes at one level")
def joinDoc(self, doc):
"""Объединение документа шаблона и документа файла"""
if not self.doc:
self.setError(_("Can not text file is XML"))
self.setError(_("Text file is not XML"))
return False
if not doc:
self.setError(_("Can not text template is XML"))
self.setError(_("Text file is not XML"))
return False
# Импортируем корневую ноду нового документа в текущий документ
#newImportBodyNode = self.doc.importNode(doc.documentElement, True)

@ -43,7 +43,7 @@ class xml_xfcepanel(xml_xfce):
try:
self.doc = xml.dom.minidom.parseString(self.text)
except:
self.setError(_("Can not text template is XML"))
self.setError(_("Template text is not XML"))
return False
self.rootNode = self.doc.documentElement
self.bodyNode = self.rootNode

Loading…
Cancel
Save