Browse Source

Добавлены различные переменные

master
parent
commit
d2723105fb
7 changed files with 206 additions and 25 deletions
  1. +12
    -0
      calculate/utils/files.py
  2. +53
    -0
      calculate/utils/system.py
  3. +29
    -17
      calculate/vars/install/os/__init__.py
  4. +5
    -1
      calculate/vars/main/cl/__init__.py
  5. +87
    -7
      calculate/vars/main/os/__init__.py
  6. +0
    -0
      calculate/vars/update/__init__.py
  7. +20
    -0
      calculate/vars/update/cl/__init__.py

+ 12
- 0
calculate/utils/files.py View File

@@ -8,6 +8,7 @@ from glob import glob
import os
import sys
import contextlib
import re


class FilesError(Exception):
@@ -354,6 +355,17 @@ def read_file(file_path):
format(str(error), mod, lineno))


def grep_file(file_path, regexp, flags=0):
"""
Получить из файла данные по регулярному выражению
"""
data = read_file(file_path)
m = re.search(regexp, data, flags=flags)
if m:
return m.group()
return ""


def write_file(file_path):
'''Функция для открытия и записи файлов. Создает директории на пути к
целевому файлу если это необходимо. Возвращает файловый объект.'''


+ 53
- 0
calculate/utils/system.py View File

@@ -0,0 +1,53 @@
from calculate.utils.files import grep_file
import os

class SystemType:
"""
Тип контейнера текущей системы
"""
Uml = "uml"
VServer = "vserver"
OpenVZ = "openvz"
LXC = "lxc"
Docker = "docker"
Xen0 = "xen0"
XenU = "xenU"
Rkt = "rkt"
SystemdNSpawn = "systemd-nspawn"
NotDetected = ""

@classmethod
def detect_container(cls):
if grep_file("/proc/cpuinfo", "UML"):
return cls.Uml
elif grep_file("/proc/self/status",
"(s_context|VxID):\s*[1-9]"):
return cls.VServer
elif (os.path.exists("/proc/vz/veinfo")
and not os.path.exists("/proc/vz/version")):
return cls.OpenVZ
elif grep_file("/proc/self/status", "envID:\s*[1-9]"):
return cls.OpenVZ
elif grep_file("/proc/1/environ", "container=lxc"):
return cls.LXC
elif grep_file("/proc/1/environ", "container=rkt"):
return cls.Rkt
elif grep_file("/proc/1/environ", "container=systemd-nspawn"):
return cls.SystemdNSpawn
elif os.path.exists("/.dockerenv"):
return cls.Docker
elif grep_file("/proc/1/environ", "container=docker"):
return cls.Docker
return cls.NotDetected

@classmethod
def detect_vm(cls):
if os.path.exists("/proc/xen"):
if grep_file("/proc/xen/capabilities", "control_d"):
return cls.Xen0
return cls.XenU
return cls.NotDetected

@classmethod
def detect(cls):
return cls.detect_container() or cls.detect_vm()

+ 29
- 17
calculate/vars/install/os/__init__.py View File

@@ -5,21 +5,33 @@ from calculate.vars.main.os.func import get_arch_gentoo
from calculate.vars.install.os.func import (get_audio_selected,
get_available_audio_system)

with Namespace("arch"):
# Variable("machine", type=StringType,
# source=Calculate(lambda x: x.value, "main.os.arch.machine"))
print('var: machine')
Variable("machine", type=StringType,
source=Copy("main.os.arch.machine"))
Variable("gentoo", type=StringType,
source=Calculate(get_arch_gentoo, ".machine"))

with Namespace("audio"):
Variable("available", type=ListType,
source=Calculate(
get_available_audio_system))
Variable("selected", type=StringType,
source=Calculate(
get_audio_selected,
".available",
"main.cl.cmdline.calculate.audio"))
def import_variables():
with Namespace("arch"):
Variable("machine", type=StringType,
source=Copy("main.os.arch.machine"))
Variable("gentoo", type=StringType,
source=Calculate(get_arch_gentoo, ".machine"))

with Namespace("audio"):
Variable("available", type=ListType,
source=Calculate(
get_available_audio_system))
Variable("selected", type=StringType,
source=Calculate(
get_audio_selected,
".available",
"main.cl.cmdline.calculate.audio"))

Variable("subsystem", type=StringType, source=Copy("main.os.subsystem"))

with Namespace("container"):
Variable("type", type=StringType, source=Copy("main.os.container.type"))

with Namespace("linux"):
Variable("shortname", type=StringType, source=Copy("main.os.linux.shortname"))
Variable("name", type=StringType, source=Copy("main.os.linux.name"))
Variable("subname", type=StringType, source=Copy("main.os.linux.subname"))
Variable("system", type=StringType, source=Copy("main.os.linux.system"))
Variable("ver", type=StringType, source=Copy("main.os.linux.ver"))
Variable("build", type=StringType, source=Copy("main.os.linux.build"))

+ 5
- 1
calculate/vars/main/cl/__init__.py View File

@@ -9,7 +9,6 @@ from calculate.variables.datavars import (
Calculate
)


def get_ebuild_phase():
return os.environ.get("EBUILD_PHASE", "")

@@ -105,6 +104,11 @@ def get_isoscan_fullpath(base_path, filename):


def import_variables():
Variable("chroot_path", type=StringType,
source=Calculate(lambda x:x.value, "main.cl_chroot_path"))
Variable("root_path", type=StringType,
source=Calculate(lambda x:x.value, "main.cl_root_path"))

Variable("ebuild_phase", type=StringType,
source=Calculate(get_ebuild_phase))



+ 87
- 7
calculate/vars/main/os/__init__.py View File

@@ -2,13 +2,93 @@ from calculate.variables.datavars import (
Variable,
Namespace,
StringType,
Calculate
Calculate,
Static
)
from .func import get_arch_machine, get_arch_gentoo
from calculate.vars.main.os.func import get_arch_machine, get_arch_gentoo
from calculate.utils.system import SystemType

with Namespace("arch"):
Variable("machine", type=StringType,
source=Calculate(get_arch_machine))
import os
import platform

Variable("gentoo", type=StringType,
source=Calculate(get_arch_gentoo, ".machine"))
dictLinuxName = {"CLD": "Calculate Linux Desktop",
"CLDX": "Calculate Linux Desktop",
"CLDG": "Calculate Linux Desktop",
"CDS": "Calculate Directory Server",
"CLS": "Calculate Linux Scratch",
"CSS": "Calculate Scratch Server",
"CMC": "Calculate Media Center",
"Gentoo": "Gentoo"}

dictLinuxSubName = {"CLD": "KDE", "CLDX": "XFCE", "CLDG": "GNOME"}

dictNameSystem = {'CDS': 'server',
'CLD': 'desktop',
'CLDG': 'desktop',
'CLDX': 'desktop',
'CLS': 'desktop',
'CMC': 'desktop',
'CSS': 'server'}

def dict_value(d, keyname, fallback_value):
return d.value.get(keyname.value, fallback_value.value)

def detect_other_shortname(systemroot):
"""Detect other system. Now only Gentoo."""
gentoo_file = os.path.join(systemroot.value, "etc/gentoo-release")
if os.path.exists(gentoo_file):
return "Gentoo"
return "Linux"

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)
if os.path.exists(gentoo_file):
gentoo_link = self.Get('cl_make_profile')
if os.path.islink(gentoo_link):
vers = filter(re_ver.search,
os.readlink(gentoo_link).split('/'))
if vers:
return vers[-1]

def get_version_from_uname():
"""Get version from uname"""
re_ver = re.search("^(\d+\.)*\d", platform.release(), re.S)
if re_ver:
return re_ver.group()

def get_linux_version(systemroot, make_profile):
return "21"

def import_variables():
with Namespace("arch"):
Variable("machine", type=StringType,
source=Calculate(get_arch_machine))

Variable("gentoo", type=StringType,
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("subsystem", type=StringType,
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"))
Variable("name", type=StringType,
source=Calculate(dict_value, dictLinuxName, ".shortname", Static("Linux")))
Variable("subname", type=StringType,
source=Calculate(dict_value, dictLinuxSubName, ".shortname", Static("")))
Variable("system", type=StringType,
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"))
Variable("build", type=StringType, source="")

+ 0
- 0
calculate/vars/update/__init__.py View File


+ 20
- 0
calculate/vars/update/cl/__init__.py View File

@@ -0,0 +1,20 @@
from calculate.variables.datavars import (
Variable,
Namespace,
StringType,
Calculate,
Static,
TableType
)

def get_repository_table():
return [
{'name':'gentoo',
'url': 'git://git.calculate-linux.org/calculate/gentoo-overlay.git'},
{'name':'calculate',
'url': 'git://git.calculate-linux.org/calculate/calculate-overlay.git'},
]

def import_variables():
Variable('repositories', type=TableType,
source=Calculate(get_repository_table))

Loading…
Cancel
Save