diff --git a/calculate/vars/install/os/__init__.py b/calculate/vars/install/os/__init__.py new file mode 100644 index 0000000..b977023 --- /dev/null +++ b/calculate/vars/install/os/__init__.py @@ -0,0 +1,10 @@ +import os +from calculate.variables.datavars import Variable, Namespace, Dependence, \ + StringType, BooleanType, HashType, Calculate, Copy +from calculate.vars.main.os.func import get_arch_gentoo + +with Namespace("arch"): + Variable("machine", type=StringType, + source=Copy("main.os.arch.machine")) + Variable("gentoo", type=StringType, + source=Calculate(get_arch_gentoo, ".machine")) diff --git a/calculate/vars/main/os/__init__.py b/calculate/vars/main/os/__init__.py new file mode 100644 index 0000000..e226b54 --- /dev/null +++ b/calculate/vars/main/os/__init__.py @@ -0,0 +1,9 @@ +from calculate.variables.datavars import Variable, Namespace, Dependence, \ + StringType, BooleanType, HashType, Calculate +from .func import * + +with Namespace("arch"): + Variable("machine", type=StringType, + source=Calculate(get_arch_machine)) + Variable("gentoo", type=StringType, + source=Calculate(get_arch_gentoo, ".machine")) diff --git a/calculate/vars/main/os/func.py b/calculate/vars/main/os/func.py new file mode 100644 index 0000000..d42632b --- /dev/null +++ b/calculate/vars/main/os/func.py @@ -0,0 +1,14 @@ +import re +import platform + +def get_arch_machine(): + return platform.machine() + +def get_arch_gentoo(arch_machine): + arch = arch_machine.value + if re.search("i.86", arch): + return "x86" + else: + return { + "x86_64": "amd64" + }.get(arch,arch) diff --git a/tests/vars/test_vars.py b/tests/vars/test_vars.py index 348431f..46e87e8 100644 --- a/tests/vars/test_vars.py +++ b/tests/vars/test_vars.py @@ -1,6 +1,7 @@ import pytest import calculate.vars.main.os.x11 as main_os_x11 import calculate.vars.main.cl as main_cl +import calculate.vars.main.os as main_os from calculate.vars.main.cl import CmdlineParams import mock from itertools import chain @@ -90,3 +91,27 @@ def test_main_cl_cmdline(case): with mock.patch('calculate.vars.main.cl.readFile') as readFile: readFile.return_value = case["data"] assert main_cl.get_calculate_cmdline() == case["result"] + + +@pytest.mark.parametrize('case', + [ + { + "source": "i686", + "result": "x86" + }, + { + "source": "i386", + "result": "x86" + }, + { + "source": "x86_64", + "result": "amd64" + }, + ], + ids=lambda x:"{}->{}".format(x["source"],x["result"])) +@pytest.mark.calculate_vars +def test_main_os_get_arch_gentoo(case): + class Var: + def __init__(self, value): + self.value = value + assert main_os.get_arch_gentoo(Var(case["source"])) == case["result"]