From 3cd692bbb34e3005615419f66c368038c7ec1bf5 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Fri, 4 May 2018 10:37:15 +0300 Subject: [PATCH 1/6] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20calculate-utils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Исправлена обработка параметров для функций mergepkg и merge --- pym/calculate/lib/cl_template.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pym/calculate/lib/cl_template.py b/pym/calculate/lib/cl_template.py index bf6a9f3..23dcb5e 100644 --- a/pym/calculate/lib/cl_template.py +++ b/pym/calculate/lib/cl_template.py @@ -3325,9 +3325,9 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction, :param nameTemp: :return: """ - terms = funArgv.replace(" ", "").split(",") - funcPkg = terms[0] - funcMerge = terms[0].partition(":")[0].partition("[")[0] + term = funArgv.replace(" ", "") + funcPkg = term + funcMerge = term.partition(":")[0].partition("[")[0] replace = self.funcMerge(funcMerge, resS, localVars, "", nameTemp) if replace == "1": replace = self.funcPkg(funcPkg, resS, localVars, "", nameTemp) @@ -3371,10 +3371,8 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction, return True return False - terms = funArgv.replace(" ", "").split(",") - if len(terms) != 1: - raise self.raiseErrTemplate() - funcPkg = terms[0] + term = funArgv.replace(" ", "") + funcPkg = term funcPkg, spl, uses = funcPkg.partition('[') if uses: uses = uses.rstrip("]") From 638b197406b6baaf772eb179a1cbf4d65cd977b0 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Wed, 20 Jun 2018 10:46:04 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D1=81=D1=80=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D0=B0=D0=BA=D0=B5=D1=82=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D1=91=D0=BD=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * IUSE сравнивается после сортировки --- pym/calculate/lib/utils/portage.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pym/calculate/lib/utils/portage.py b/pym/calculate/lib/utils/portage.py index ed94162..e2a0c9f 100644 --- a/pym/calculate/lib/utils/portage.py +++ b/pym/calculate/lib/utils/portage.py @@ -1289,7 +1289,6 @@ class SimpleRepositoryMapper(Mapping): class EbuildInfoError(Exception): pass - class EbuildInfo(object): """ Информация о ebuild (DEPEND) из metadata @@ -1303,7 +1302,12 @@ class EbuildInfo(object): self._meta_info_path = path.join(meta_path, atom) if not path.exists(self._meta_info_path): raise EbuildInfoError("Package is not found") - self._info = self._get_info() + self._info = self.prepare_use_flags(self._get_info()) + + @staticmethod + def prepare_use_flags(d): + d["IUSE"] = tuple(sorted(x for x in d.get("IUSE","").split(' ') if x )) + return d def _get_info(self): with open(self._meta_info_path, 'r') as f: @@ -1325,7 +1329,7 @@ class EbuildInfo(object): # if res: # for k in self.support_keys: # if other[k] != self[k]: - # print k,":", other[k], "!=", self[k] + # print "DEBUG:", k,":", other[k], "!=", self[k] return res @@ -1360,7 +1364,7 @@ class InstalledPackageInfo(object): info[key] = value.strip() rep_path = path.join(self._pkg_path, 'repository') info['repository'] = readFile(rep_path).strip() - return info + return EbuildInfo.prepare_use_flags(info) def __getitem__(self, item): return self._info[item] From 585133ab60b4870a4d23fcd1ccee97e46379b176 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Fri, 22 Jun 2018 10:07:31 +0300 Subject: [PATCH 3/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=20tim?= =?UTF-8?q?eout=20=D0=BD=D0=B0=20=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pym/calculate/lib/utils/files.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pym/calculate/lib/utils/files.py b/pym/calculate/lib/utils/files.py index d5ca057..ee7cbce 100644 --- a/pym/calculate/lib/utils/files.py +++ b/pym/calculate/lib/utils/files.py @@ -113,6 +113,8 @@ class PipeProcess(StdoutableProcess): def get_stdout(self): return PIPE +class ProcessTimeout(FilesError): + pass class process(StdoutableProcess): """Execute system command by Popen @@ -160,6 +162,7 @@ class process(StdoutableProcess): self.envdict = kwarg.get("envdict", os.environ.copy()) self.envdict["LANG"] = kwarg.get('lang', 'C') self.langc = "langc" in kwarg + self.timeout = kwarg.get("timeout", None) self.stderr = kwarg.get("stderr", PIPE) self.cwd = kwarg.get("cwd", None) @@ -226,7 +229,10 @@ class process(StdoutableProcess): _stderr = self.pipe.stderr.fileno() reads = [_stdout, _stderr] while True: - ret = select.select(reads, [], []) + ret = select.select(reads, [], [], self.timeout) + if not ret[0]: + self.kill() + raise ProcessTimeout() for fd in ret[0]: if fd == _stdout: s = self.pipe.stdout.readline() @@ -264,7 +270,11 @@ class process(StdoutableProcess): try: self._open() if self.cacheresult is None: - self.cacheresult, self.cacheerr = self.pipe.communicate() + if self.timeout is None: + self.cacheresult, self.cacheerr = self.pipe.communicate() + else: + for line in self.readByLine(): + pass return self.cacheresult except KeyboardInterrupt: self.kill() From de0e61426c5b2b3643cde7417e78dfbc402b5b14 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Fri, 22 Jun 2018 15:00:47 +0300 Subject: [PATCH 4/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D1=8B=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B7=D1=80=D0=B5=D1=88=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=84=D1=80=D0=B5=D0=B9=D0=BC=D0=B1=D1=83=D1=84=D1=84?= =?UTF-8?q?=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Так же добавлена функция для подбора наиболее подходящего среди доступных разрешений --- pym/calculate/lib/utils/device.py | 40 +++++++++++++++++++++++++++++++ pym/calculate/lib/utils/tools.py | 20 +++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/pym/calculate/lib/utils/device.py b/pym/calculate/lib/utils/device.py index 85b1cd0..b381759 100644 --- a/pym/calculate/lib/utils/device.py +++ b/pym/calculate/lib/utils/device.py @@ -720,3 +720,43 @@ devfs = Devfs() udev = Udev() lvm = Lvm(LvmCommand()) raid = Raid(MdadmCommand()) + +class HwinfoError(Exception): + pass + +class HwinfoTimeout(HwinfoError): + pass + +class HwinfoNotExists(HwinfoError): + pass + +class Hwinfo(object): + """ + Объект получения информации из hwinfo + """ + command_timeout = 20 + @property + def hwinfo_cmd(self): + return files.getProgPath("/usr/sbin/hwinfo") + + def framebuffer(self): + """ + Получить вывод hwinfo --framebuffer + """ + return self.run("--framebuffer") + + def run(self, *command): + if not self.hwinfo_cmd: + raise HwinfoNotExists() + try: + return files.process(*[self.hwinfo_cmd] + list(command), + **{'timeout':self.command_timeout}).read() + except files.ProcessTimeout: + raise HwinfoTimeout() + + def resolutions(self): + """ + Получить допустимые разрешения фреймбуффера + """ + re_modes = re.compile("^\s+Mode 0x[0-9a-f]+:\s+(\d+x\d+)\s",re.M) + return tuple(sorted(unique(re_modes.findall(self.framebuffer())))) diff --git a/pym/calculate/lib/utils/tools.py b/pym/calculate/lib/utils/tools.py index e4621ed..8028fac 100644 --- a/pym/calculate/lib/utils/tools.py +++ b/pym/calculate/lib/utils/tools.py @@ -27,7 +27,7 @@ from os import path import time from abc import ABCMeta, abstractmethod from types import GeneratorType - +from math import sqrt try: @@ -602,3 +602,21 @@ class Brokenable(object): return f(self, *args, **kw) return wrapper return decor + + +def get_best_nearest_resolution(preferred_res, support_res, aspect_only=False): + """ + Получить наилучшее ближайшее к preferred_res разрешенение из support_res. + """ + width, height = map(int, preferred_res.split('x')) + gep = sqrt(height ** 2 + width ** 2) + k = float(width) / float(height) + support_res_int = (tuple(map(int, x.split("x"))) for x in support_res) + if not aspect_only: + support_res_int = [(x,y) for x,y in support_res_int if x <= width and y <= height] + if not support_res_int: + return None + bestRes = min(support_res_int, + key=lambda x: (abs(x[0] / float(x[1]) - k), + abs(gep - sqrt(x[0] ** 2 + x[1] ** 2)))) + return "%sx%s" % bestRes From fdb7eb6b593ebc83ad469727f24608f0e79446e3 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Mon, 25 Jun 2018 14:06:01 +0300 Subject: [PATCH 5/6] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BE=D0=BF=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=80=D0=B0=D0=B7=D1=80=D0=B5=D1=88?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=20=D0=BB=D0=BE=D0=B3?= =?UTF-8?q?=D1=83=20Xorg=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pym/calculate/lib/variables/X11.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pym/calculate/lib/variables/X11.py b/pym/calculate/lib/variables/X11.py index 8dbc040..a5fe87b 100644 --- a/pym/calculate/lib/variables/X11.py +++ b/pym/calculate/lib/variables/X11.py @@ -62,17 +62,18 @@ class VariableOsX11Resolution(Variable): if self.Get('os_root_type') != 'usb-hdd': xlog = "/var/log/Xorg.0.log" if os.access(xlog, os.R_OK): - reXorgLogParser = re.compile( + logdata = open(xlog, 'r').read() + for re_pat in ( + "Output [\S]+ using initial mode (\d+)x(\d+)", "Virtual screen size determined to be" - " ([0-9]+)\s*x\s*([0-9]+)|" - 'Setting mode "(\d+)x(\d+)[0-9@]"|' - "Output [\S]+ using initial mode (\d+)x(\d+)|" - "Virtual size is (\d+)x(\d+)", re.S) - resXorgLogParser = reXorgLogParser.search( - open(xlog, 'r').read()) - if resXorgLogParser: - return "%sx%s" % filter(lambda x: x, - resXorgLogParser.groups())[:2] + " ([0-9]+)\s*x\s*([0-9]+)", + 'Setting mode "(\d+)x(\d+)[0-9@]"', + "Virtual size is (\d+)x(\d+)"): + reXorgLogParser = re.compile(re_pat, re.S) + resXorgLogParser = reXorgLogParser.search(logdata) + if resXorgLogParser: + return "%sx%s" % filter(lambda x: x, + resXorgLogParser.groups())[:2] # get resolution from xorg.conf xorgconf = "/etc/X11/xorg.conf" From d35d1d082ce6205ca3178f24406d4c1472b75217 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Thu, 28 Jun 2018 16:20:11 +0300 Subject: [PATCH 6/6] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D1=91=D0=BD?= =?UTF-8?q?=20=D0=B0=D0=BB=D0=B3=D0=BE=D1=80=D0=B8=D1=82=D0=BC=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=B4=D0=B1=D0=BE=D1=80=D0=B0=20?= =?UTF-8?q?=D0=B1=D0=BB=D0=B8=D0=B6=D0=B0=D0=B9=D1=88=D0=B5=D0=B3=D0=BE=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B7=D1=80=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20fb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pym/calculate/lib/utils/tools.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pym/calculate/lib/utils/tools.py b/pym/calculate/lib/utils/tools.py index 8028fac..373dee2 100644 --- a/pym/calculate/lib/utils/tools.py +++ b/pym/calculate/lib/utils/tools.py @@ -607,16 +607,22 @@ class Brokenable(object): def get_best_nearest_resolution(preferred_res, support_res, aspect_only=False): """ Получить наилучшее ближайшее к preferred_res разрешенение из support_res. + + Разрешение берётся ближайшее по размеру диагонали, с применением "штрафного" + коэфициента по разнице аспектов """ width, height = map(int, preferred_res.split('x')) gep = sqrt(height ** 2 + width ** 2) k = float(width) / float(height) + s = float(width) * float(height) support_res_int = (tuple(map(int, x.split("x"))) for x in support_res) + support_res_int = ((x, y, sqrt(y*y + x*x), abs(x/float(y)-k)) + for x, y in support_res_int) if not aspect_only: - support_res_int = [(x,y) for x,y in support_res_int if x <= width and y <= height] + support_res_int = [(x,y,g,dasp) + for x,y,g,dasp in support_res_int if x <= width and y <= height] if not support_res_int: return None - bestRes = min(support_res_int, - key=lambda x: (abs(x[0] / float(x[1]) - k), - abs(gep - sqrt(x[0] ** 2 + x[1] ** 2)))) - return "%sx%s" % bestRes + keyfunc = lambda x,y,g, dasp: g -g * dasp + bestRes = max(support_res_int, key=lambda x:keyfunc(*x) ) + return "%sx%s" % bestRes[0:2]