diff --git a/pym/calculate/lib/cl_template.py b/pym/calculate/lib/cl_template.py index caf2fec..a0f773f 100644 --- a/pym/calculate/lib/cl_template.py +++ b/pym/calculate/lib/cl_template.py @@ -34,6 +34,7 @@ import time import glob import hashlib import fcntl +from math import sqrt from itertools import * # < <= == != >= > from operator import lt, le, eq, ne, ge, gt @@ -3136,7 +3137,7 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction): @classmethod def getLastElog(cls): - # get last timestamp + # get last timestamp (of ::completed emerge) entry = EmergeLog(EmergeLogPackageTask()).get_last_time() if entry: return entry.partition(":")[0] @@ -3146,7 +3147,7 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction): def funcElog(self,funArgv, resS, localVars, textTemplateTmp, nameTemp): """Function for work with emerge.log""" funArgv = funArgv.strip() - rePkg = re.compile(r'completed emerge \(\d+ of \d+\) (\S+)\s',re.S) + rePkg = re.compile(r'\) Merging (?:Binary )?\((\S+)::',re.S) replace = "" if funArgv: lastTimestamp = self.getElogTimestamp() @@ -3207,6 +3208,44 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction): return self.timeConfigsIni[nameEnvFile] return 0 + def funcWallpaper(self, funArgv, resS, localVars, textTemplateTmp, + nameTemp): + """ + Получить наиболее близкое к заданному разрешение из списка обоев + """ + terms = funArgv.replace(" ", "").split(",") + if len(terms) != 2: + self.raiseErrTemplate(_("funtion takes only two parameters")) + resol, wpath = terms + + re_resol = re.compile("^(\d+)x(\d+)$") + resol = re_resol.match(resol) + if not resol: + self.raiseErrTemplate(_("first parameter must be resolution")) + + re_resol = re.compile(".*?(\d+)x(\d+).*") + res = map(lambda x:(int(x.group(1)),int(x.group(2)),x.group()), + filter(None, + map(re_resol.search, + listDirectory(wpath)))) + width = int(resol.group(1)) + height = int(resol.group(2)) + gep = sqrt(height**2+width**2) + k = float(width)/float(height) + if res: + # наиболее подходящее разрешение: + # минимальная разность между пропорциями (отношение ширины к высоте) + # минимальная разность между размерами (гепотенуза) + near_res = min(res, + key=lambda x:(abs(x[0]/float(x[1])-k), + abs(gep-sqrt(x[0]**2+x[1]**2)))) + replace = near_res[2] + else: + replace = "" + textTemplateTmp = textTemplateTmp[:resS.start()] + replace + \ + textTemplateTmp[resS.end():] + return textTemplateTmp + def funcIni(self, funArgv, resS, localVars, textTemplateTmp, nameTemp): """локальная функция записывает и считывает значение переменной @@ -3684,7 +3723,7 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction): raise TemplatesError( _("error in template %s")%self.nameTemplate + "\n" + \ _("error, template term '%s'")%str(self.functText) + \ - message) + " " + message) def applyFuncTemplate(self, textTemplate, nameTemplate): """Применяет функции к тексту шаблона""" diff --git a/pym/calculate/lib/utils/portage.py b/pym/calculate/lib/utils/portage.py index 73a2b3b..2c31fea 100644 --- a/pym/calculate/lib/utils/portage.py +++ b/pym/calculate/lib/utils/portage.py @@ -989,7 +989,7 @@ class EmergeLogPackageTask(EmergeLogTask): """ Определить есть ли в строке маркер завершения сборки пакета """ - return "::: completed emerge" in line + return ") Merging " in line class EmergeLog: """ diff --git a/pym/calculate/lib/variables/__init__.py b/pym/calculate/lib/variables/__init__.py index 602fc6d..1a24bb7 100644 --- a/pym/calculate/lib/variables/__init__.py +++ b/pym/calculate/lib/variables/__init__.py @@ -41,4 +41,4 @@ class VariableClVer(ReadonlyVariable): """ Package version """ - value = "3.2.2" + value = "3.2.2.1"