You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
distros-overlay/sys-apps/calculate-lib/files/calculate-lib-3.2.0_alpha4-...

153 lines
6.6 KiB

diff --git calculate/lib/datavars.py calculate/lib/datavars.py
index 1881294..3690083 100644
--- calculate/lib/datavars.py
+++ calculate/lib/datavars.py
@@ -1017,9 +1017,10 @@ class DataVars(SimpleDataVars):
"""
if not self.iniCache:
# get initialized section names
- if os.path.exists('/etc/make.profile'):
+ make_profile = self.Get('main.cl_make_profile')
+ if os.path.exists(make_profile):
profiles = [('profile',
- path.join('/etc',os.readlink('/etc/make.profile')))]
+ path.join('/etc',os.readlink(make_profile)))]
else:
profiles = []
for iniName,iniFile in profiles+\
diff --git calculate/lib/variables/env.py calculate/lib/variables/env.py
index ab295ca..87d43cc 100644
--- calculate/lib/variables/env.py
+++ calculate/lib/variables/env.py
@@ -414,6 +414,17 @@ class VariableClMakeProfile(Variable):
"""
Путь до актуального make.profile
"""
+ systemRoot = "/"
+
+ def get_work_link(self, *links):
+ for link in links:
+ if path.exists(link):
+ return link
+
def get(self):
- # TODO: заглушка, нужно учитывать /etc/portage/make.profile
- return "/etc/make.profile"
+ files = ["etc/portage/make.profile", "etc/make.profile"]
+ val = self.get_work_link(
+ *[path.join(self.systemRoot, x) for x in files])
+ if not val:
+ raise VariableError(_("Failed to detect system profile"))
+ return val
diff --git calculate/lib/variables/linux.py calculate/lib/variables/linux.py
index 5d907f6..d49c773 100644
--- calculate/lib/variables/linux.py
+++ calculate/lib/variables/linux.py
@@ -18,10 +18,10 @@ import os
from os import path
import re
import platform
-from calculate.lib.datavars import Variable,ReadonlyVariable,SimpleDataVars
+from calculate.lib.datavars import Variable, SimpleDataVars
from calculate.lib.utils.portage import isPkgInstalled
-from calculate.lib.utils.files import countFiles,readFile
-import calculate.lib.cl_template as cl_template
+from calculate.lib.utils.files import readFile
+from env import VariableClMakeProfile
class Linux:
dictLinuxName = {"CLD":"Calculate Linux Desktop",
@@ -51,7 +51,7 @@ class Linux:
def getShortnameByMakeprofile(self,systemroot):
"""Get shortname by symlink of make.profile"""
- makeprofile = path.join(systemroot,'etc/make.profile')
+ makeprofile = self.Get('cl_make_profile')
if path.exists(makeprofile):
link = os.readlink(makeprofile)
reMakeProfileLink = re.compile('/calculate/(desktop|server)/(%s)/'%
@@ -78,11 +78,11 @@ class Linux:
def detectOtherShortname(self,systemroot):
"""Detect other system. Now only Gentoo."""
- gentooFile = path.join(systemroot,"etc/gentoo-release")
+ gentooFile = path.join(systemroot, "etc/gentoo-release")
if path.exists(gentooFile):
return "Gentoo"
- if all(map(lambda x:path.lexists(path.join(systemroot,x)),
- ['bin','var','lib','etc'])):
+ if all(map(lambda x: path.lexists(path.join(systemroot, x)),
+ ['bin', 'var', 'lib', 'etc'])):
return "Linux"
return None
@@ -92,17 +92,17 @@ class Linux:
"""
overlayPath = 'var/lib/layman/calculate'
releaseFile = 'profiles/calculate-release'
- return readFile(path.join(systemroot,overlayPath,releaseFile))
+ return readFile(path.join(systemroot, overlayPath, releaseFile))
def getVersionFromMetapackage(self,systemroot,shortname):
"""Get version from meta package"""
- for pkg in ("app-misc/calculate-meta","app-misc/%s-meta"%shortname):
- calcMeta = isPkgInstalled(pkg,systemroot)
+ for pkg in ("app-misc/calculate-meta", "app-misc/%s-meta" % shortname):
+ calcMeta = isPkgInstalled(pkg, systemroot)
if calcMeta:
return calcMeta[0]['PV']
return None
- def getVersionFromCalculateIni(self,systemroot):
+ def getVersionFromCalculateIni(self, systemroot):
"""Get version from calculate ini"""
pathname = path.join(systemroot,
'etc/calculate/calculate.ini')
@@ -124,11 +124,9 @@ class Linux:
def getVersionFromGentooFiles(self,systemroot):
"""Get version from gentoo files"""
gentooFile = path.join(systemroot,"etc/gentoo-release")
- systemVersion = ""
- flagGentoo = False
reVer=re.compile("^(\d+\.)*\d+$",re.S)
if path.exists(gentooFile):
- gentooLink = path.join(systemroot,"etc/make.profile")
+ gentooLink = self.Get('cl_make_profile')
if path.islink(gentooLink):
vers = filter(reVer.search,
os.readlink(gentooLink).split('/'))
@@ -227,9 +225,10 @@ class VariableOsLinuxFiles(Variable,Linux):
class LinuxDataVars(SimpleDataVars):
- def __init__(self,systemRoot="/"):
+ def __init__(self, systemRoot="/"):
self.systemRoot = systemRoot
SimpleDataVars.__init__(self,
+ VariableClMakeProfile(systemRoot=systemRoot),
VariableOsLinuxShortname(systemRoot=systemRoot),
VariableOsLinuxName(systemRoot=systemRoot),
VariableOsLinuxSubname(systemRoot=systemRoot),
@@ -238,14 +237,12 @@ class LinuxDataVars(SimpleDataVars):
VariableOsLinuxSystem(systemRoot=systemRoot),
VariableOsLinuxVer(systemRoot=systemRoot),
VariableOsLinuxBuild(systemRoot=systemRoot))
- makeprofile = path.join(systemRoot,'etc/make.profile')
+ makeprofile = self.Get('cl_make_profile')
if os.path.exists(makeprofile):
- inifile = path.join(systemRoot,'etc',
- os.readlink(path.join(systemRoot,'etc/make.profile')))
+ inifile = path.join(systemRoot, 'etc',
+ os.readlink(makeprofile))
self.flIniFileFrom(inifile)
- inifile = "etc/calculate/calculate.env"
- self.flIniFileFrom(path.join(systemRoot,inifile))
- iniFile = "etc/calculate/calculate3.env"
- self.flIniFileFrom(path.join(systemRoot,iniFile))
- iniFile = "etc/calculate/calculate2.env"
- self.flIniFileFrom(path.join(systemRoot,iniFile))
+ for inifile in ("etc/calculate/calculate.env",
+ "etc/calculate/calculate3.env",
+ "etc/calculate/calculate2.env"):
+ self.flIniFileFrom(path.join(systemRoot, inifile))