From 4456a88895c3b31c42af5add029e6532a5189212 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Fri, 13 Dec 2019 12:51:45 +0300 Subject: [PATCH] Add python var and lib var --- pym/calculate/lib/variables/env.py | 40 ++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/pym/calculate/lib/variables/env.py b/pym/calculate/lib/variables/env.py index ba8c938..1c19999 100644 --- a/pym/calculate/lib/variables/env.py +++ b/pym/calculate/lib/variables/env.py @@ -21,8 +21,10 @@ from itertools import * from calculate.lib.datavars import (TableVariable, Variable, ReadonlyVariable, VariableError, ReadonlyTableVariable, FieldValue, HumanReadable) -from calculate.lib.utils.files import listDirectory, process, PIPE, pathJoin -from calculate.lib.utils.portage import isPkgInstalled, RepositoryPath +from calculate.lib.utils.files import (listDirectory, process, PIPE, pathJoin, + readFileEx) +from calculate.lib.utils.portage import (isPkgInstalled, RepositoryPath, + getInstalledAtom) from calculate.lib.utils.common import cmpVersion from calculate.lib.datavars import DataVars from itertools import dropwhile @@ -796,3 +798,37 @@ class VariableClClientType(ReadonlyVariable): Тип клиента получающего информацию от core """ value = "" + +class VariableOsLibPath(ReadonlyVariable): + """ + Использовать lib или lib64 + """ + def get(self): + if self.Get('os_arch_machine') == 'x86_64': + return "lib64" + else: + return "lib" + +class VariableOsPython(ReadonlyVariable): + """ + Путь до модулей синхронизации + """ + def get_root(self): + return "/" + + def get_usrlib(self): + return "/usr/%s" % self.Get('os_lib_path') + + def get(self): + chroot_path = self.get_root() + pythons = readFileEx(pathJoin(chroot_path, + "/etc/python-exec/python-exec.conf"), grab=True).split() + if pythons: + for python in pythons: + libpath = self.get_usrlib() + if path.exists(pathJoin(chroot_path, libpath, python)): + return python + for atom in sorted( + getInstalledAtom("dev-lang/python",prefix=chroot_path), + reverse=True): + return "python{SLOT}".format(**atom)