From 18df9f853affee8c33c4a05cd2b1b24aa08aa4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=81?= Date: Wed, 9 Dec 2020 15:31:00 +0300 Subject: [PATCH] Fixed importing of the variables modules. fixed #52 --- calculate/variables/loader.py | 6 ++---- calculate/vars/main/os/__init__.py | 31 ++++++++++++++++++------------ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/calculate/variables/loader.py b/calculate/variables/loader.py index c0dacb3..140202c 100644 --- a/calculate/variables/loader.py +++ b/calculate/variables/loader.py @@ -516,10 +516,8 @@ class VariableLoader: self.logger = datavars.logger self.ini_filler = NamespaceIniFiller() - self.variables_path = variables_path - self.variables_package = '.'.join( - variables_path[len(__file__) - - len('calculate/variables/loader.py'):].split('/')) + self.variables_path = os.path.normpath(variables_path) + self.variables_package = '.'.join(self.variables_path.split("/")) self.repository_map = repository_map def load_variables_package(self, package_name: str) -> None: diff --git a/calculate/vars/main/os/__init__.py b/calculate/vars/main/os/__init__.py index 2c11101..6dc6ffa 100644 --- a/calculate/vars/main/os/__init__.py +++ b/calculate/vars/main/os/__init__.py @@ -5,9 +5,10 @@ from calculate.variables.datavars import ( Calculate, Static ) -from calculate.vars.main.os.func import get_arch_machine, get_arch_gentoo +from .func import get_arch_machine, get_arch_gentoo from calculate.utils.system import SystemType +import re import os import platform @@ -47,7 +48,7 @@ def get_version_from_gentoo_files(systemroot, profilefile): """Get version from gentoo files""" systemroot = systemroot.value gentoo_file = os.path.join(systemroot, "etc/gentoo-release") - re_ver = re.compile("^(\d+\.)*\d+$", re.S) + re_ver = re.compile(r"^(\d+\.)*\d+$", re.S) if os.path.exists(gentoo_file): gentoo_link = self.Get('cl_make_profile') if os.path.islink(gentoo_link): @@ -59,7 +60,7 @@ def get_version_from_gentoo_files(systemroot, profilefile): def get_version_from_uname(): """Get version from uname""" - re_ver = re.search("^(\d+\.)*\d", platform.release(), re.S) + re_ver = re.search(r"^(\d+\.)*\d", platform.release(), re.S) if re_ver: return re_ver.group() @@ -77,24 +78,30 @@ def import_variables(): source=Calculate(get_arch_gentoo, ".machine")) with Namespace("gentoo"): - Variable('make_profile', type=StringType, source=Calculate(lambda x:x.value, - "os.gentoo.make_profile")) + Variable('make_profile', type=StringType, + source=Calculate(lambda x: x.value, + "os.gentoo.make_profile")) Variable("subsystem", type=StringType, - source=Calculate(lambda : SystemType.detect())) + source=Calculate(lambda: SystemType.detect())) with Namespace("container"): Variable("type", type=StringType, source="") - + with Namespace("linux"): Variable("shortname", type=StringType, - source=Calculate(detect_other_shortname, "main.cl.chroot_path")) + source=Calculate(detect_other_shortname, + "main.cl.chroot_path")) Variable("name", type=StringType, - source=Calculate(dict_value, dictLinuxName, ".shortname", Static("Linux"))) + source=Calculate(dict_value, dictLinuxName, + ".shortname", Static("Linux"))) Variable("subname", type=StringType, - source=Calculate(dict_value, dictLinuxSubName, ".shortname", Static(""))) + source=Calculate(dict_value, dictLinuxSubName, + ".shortname", Static(""))) Variable("system", type=StringType, - source=Calculate(dict_value, dictNameSystem, ".shortname", Static(""))) + source=Calculate(dict_value, dictNameSystem, + ".shortname", Static(""))) Variable("ver", type=StringType, - source=Calculate(get_linux_version, "main.cl.chroot_path", "main.os.gentoo.make_profile")) + source=Calculate(get_linux_version, "main.cl.chroot_path", + "main.os.gentoo.make_profile")) Variable("build", type=StringType, source="")