|
|
from calculate.vars.datavars import Variable, ChoiceVariable, HashVariable, TableVariable, Namespace
|
|
|
from calculate.utils.files import stderr_devnull
|
|
|
import calculate.utils.fs as fs
|
|
|
import os
|
|
|
|
|
|
"""
|
|
|
gentoo
|
|
|
make_profile
|
|
|
profile.path
|
|
|
profile.name
|
|
|
repositories[*].name
|
|
|
repositories[*].path
|
|
|
config
|
|
|
"""
|
|
|
|
|
|
class MakeProfile(Variable):
|
|
|
"""
|
|
|
Путь до файла, указывающего на активный профиль
|
|
|
"""
|
|
|
value = '/etc/portage/make.profile'
|
|
|
|
|
|
class Profile(Namespace):
|
|
|
"""
|
|
|
Параметры текущего профиля
|
|
|
"""
|
|
|
class Path(Variable):
|
|
|
"""
|
|
|
Абсолютный путь до профиля
|
|
|
"""
|
|
|
def get(self):
|
|
|
make_profile = self.vars.parent.make_profile.getValue(self)
|
|
|
make_profile_dir = os.path.dirname(make_profile)
|
|
|
profileLink = fs.readlink(make_profile)
|
|
|
if profileLink:
|
|
|
profileLink = os.path.normpath(
|
|
|
os.path.join(make_profile_dir,profileLink))
|
|
|
return profileLink
|
|
|
else:
|
|
|
return ""
|
|
|
|
|
|
class Name(Variable):
|
|
|
"""
|
|
|
Название профиля
|
|
|
"""
|
|
|
def get(self):
|
|
|
profile_path = self.vars.path.getValue(self)
|
|
|
if not profile_path:
|
|
|
return ""
|
|
|
repositories = self.vars.parent.repositories
|
|
|
for rep in repositories:
|
|
|
reppath = rep.path.getValue(self)
|
|
|
repname = rep.name.getValue(self)
|
|
|
removepart = os.path.normpath(os.path.join(reppath,"profiles"))
|
|
|
if profile_path.startswith(removepart):
|
|
|
return "%s:%s"%(
|
|
|
repname,
|
|
|
profile_path[len(removepart)+1:])
|
|
|
return profile_path
|
|
|
|
|
|
class Repositories(TableVariable):
|
|
|
"""
|
|
|
Информация о репозиториях
|
|
|
|
|
|
name: имя репозитория
|
|
|
path: полный путь до репозитория
|
|
|
"""
|
|
|
class Data(TableVariable.Data):
|
|
|
def get(self):
|
|
|
config = self.vars.config.getValue(self)
|
|
|
return [
|
|
|
{
|
|
|
'name': name,
|
|
|
'path': path
|
|
|
}
|
|
|
for path, name in config.repositories.location_map.items()
|
|
|
]
|
|
|
hash_vars = ["name", "path"]
|
|
|
|
|
|
class Config(Variable):
|
|
|
"""
|
|
|
Объект текущей конфигурации Portage
|
|
|
"""
|
|
|
def get(self):
|
|
|
from portage.package.ebuild.config import config
|
|
|
chroot_path = self.vars.root.main.chroot.getValue(self)
|
|
|
if chroot_path == '/':
|
|
|
with stderr_devnull():
|
|
|
return config()
|