|
|
|
@ -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):
|
|
|
|
|
"""Применяет функции к тексту шаблона"""
|
|
|
|
|