|
|
|
@ -14,7 +14,6 @@
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__version__ = "2.2.0.0"
|
|
|
|
|
__app__ = "calculate-lib"
|
|
|
|
|
|
|
|
|
@ -35,16 +34,6 @@ tr.setLanguage(sys.modules[__name__])
|
|
|
|
|
cl_overriding.printERROR = lambda x:filter(lambda y:color_print().printERROR(y),
|
|
|
|
|
str(x).splitlines())
|
|
|
|
|
|
|
|
|
|
packagePath = "/usr/lib/calculate-2.2"
|
|
|
|
|
for path in os.listdir(packagePath):
|
|
|
|
|
realPath = os.path.join(packagePath,path)
|
|
|
|
|
if os.path.isdir(realPath):
|
|
|
|
|
pymPath = os.path.join(realPath,"pym")
|
|
|
|
|
if len(filter(lambda x:x.startswith("cl_vars_") and\
|
|
|
|
|
x.endswith(".py") or x.startswith("cl_fill_") and\
|
|
|
|
|
x.endswith(".py"), os.listdir(pymPath)))==2:
|
|
|
|
|
sys.path.insert(0, os.path.abspath(pymPath))
|
|
|
|
|
|
|
|
|
|
class writeLog:
|
|
|
|
|
"""Класс логгирования"""
|
|
|
|
|
logger = log("apply-templates",
|
|
|
|
@ -88,69 +77,41 @@ class color_print(old_color_print, writeLog):
|
|
|
|
|
|
|
|
|
|
class DataVarsObject(cl_datavars.DataVars):
|
|
|
|
|
"""Класс переменных для десктопа"""
|
|
|
|
|
def __init__(self, section):
|
|
|
|
|
packagePath = "/usr/lib/calculate-2.2"
|
|
|
|
|
|
|
|
|
|
def __init__(self, nameProgram):
|
|
|
|
|
cl_datavars.DataVars.__init__(self)
|
|
|
|
|
self.section=section
|
|
|
|
|
self.nameProgram = nameProgram
|
|
|
|
|
|
|
|
|
|
def findPathVars(self):
|
|
|
|
|
pymPath = os.path.join(self.packagePath, self.nameProgram, "pym")
|
|
|
|
|
if os.path.isdir(pymPath) and\
|
|
|
|
|
len(filter(lambda x:x.startswith("cl_vars_") and\
|
|
|
|
|
x.endswith(".py") or x.startswith("cl_fill_") and\
|
|
|
|
|
x.endswith(".py"), os.listdir(pymPath)))==2:
|
|
|
|
|
importPath = os.path.abspath(pymPath)
|
|
|
|
|
if not importPath in sys.path:
|
|
|
|
|
sys.path.insert(0, importPath)
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def importDataObject(self, **args):
|
|
|
|
|
'''Заполнить конфигурацию переменных, для десктопа'''
|
|
|
|
|
# Имя секции в calculate.env
|
|
|
|
|
#envSection = "calculate-desktop"
|
|
|
|
|
# заполнить переменные окружения алгоритмом по умолнанию
|
|
|
|
|
self.importData(self.section, ('cl_vars_%s' %self.section,
|
|
|
|
|
'cl_fill_%s' %self.section))
|
|
|
|
|
sectName = self.nameProgram.rpartition("-")[2]
|
|
|
|
|
self.importData(sectName, ('cl_vars_%s' %sectName,
|
|
|
|
|
'cl_fill_%s' %sectName))
|
|
|
|
|
self.flIniFile()
|
|
|
|
|
|
|
|
|
|
class shareUpdateConfigs(color_print, writeLog):
|
|
|
|
|
"""Общие методы для обновления конфигурационных файлов"""
|
|
|
|
|
patternBelongDir = re.compile("belong\(\)")
|
|
|
|
|
patternBelongName = re.compile("belong\(([^\(\)]+)\)")
|
|
|
|
|
patternSect = re.compile("^\s*\[([^\[\]]+)\]\s*")
|
|
|
|
|
templatePaths = ['/usr/share/calculate/templates',
|
|
|
|
|
'/var/calculate/templates',
|
|
|
|
|
'/var/calculate/remote/templates']
|
|
|
|
|
firstEnvFile = "/etc/calculate/calculate2.env"
|
|
|
|
|
|
|
|
|
|
reCleanVer = re.compile("\d+\.?\d*\.?\d*")
|
|
|
|
|
|
|
|
|
|
def _isApplyTemplateDir(self, scanDir, nameProgram, flagSkipDesktop=True,
|
|
|
|
|
flagDir=False):
|
|
|
|
|
"""Есть ли шаблоны в директории scanDir для пакета nameProgram
|
|
|
|
|
|
|
|
|
|
выдает True, False
|
|
|
|
|
"""
|
|
|
|
|
ret = False
|
|
|
|
|
if flagDir or stat.S_ISDIR(os.stat(scanDir)[stat.ST_MODE]):
|
|
|
|
|
for fileOrDir in sorted(os.listdir(scanDir)):
|
|
|
|
|
absPath = os.path.join(scanDir,fileOrDir)
|
|
|
|
|
statInfo = os.stat(absPath)[stat.ST_MODE]
|
|
|
|
|
if stat.S_ISREG(statInfo):
|
|
|
|
|
textFile = open(absPath).read()
|
|
|
|
|
if flagSkipDesktop and\
|
|
|
|
|
"cl_pass_action==desktop" in textFile:
|
|
|
|
|
break
|
|
|
|
|
if self.patternBelongDir.search(textFile):
|
|
|
|
|
ret = os.path.basename(os.path.dirname(absPath))
|
|
|
|
|
if ret == nameProgram:
|
|
|
|
|
ret = True
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|
ret = False
|
|
|
|
|
else:
|
|
|
|
|
searchObj = self.patternBelongName.search(textFile)
|
|
|
|
|
if searchObj:
|
|
|
|
|
ret = searchObj.group(1)
|
|
|
|
|
if ret == nameProgram:
|
|
|
|
|
ret = True
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|
ret = False
|
|
|
|
|
elif stat.S_ISDIR(statInfo):
|
|
|
|
|
ret = self._isApplyTemplateDir(absPath, nameProgram, True,
|
|
|
|
|
flagSkipDesktop)
|
|
|
|
|
if ret:
|
|
|
|
|
break
|
|
|
|
|
return ret
|
|
|
|
|
def getPrograms(self):
|
|
|
|
|
"""Получаем установленные программы работающие с шаблонами"""
|
|
|
|
|
clVars = cl_datavars.DataVars()
|
|
|
|
|
clVars.flIniFile()
|
|
|
|
|
return clVars.GetList("cl_merges")
|
|
|
|
|
|
|
|
|
|
class updateUserConfigs(shareUpdateConfigs):
|
|
|
|
|
"""Обновление пользовательских конфигурационных файлов"""
|
|
|
|
@ -172,25 +133,6 @@ class updateUserConfigs(shareUpdateConfigs):
|
|
|
|
|
return False
|
|
|
|
|
return xUsers
|
|
|
|
|
|
|
|
|
|
def _getUserTemplateDirs(self, scanDir, userTemplDirs=[], flagDir=False):
|
|
|
|
|
"""Находит в директории scanDir директории шаблонов для пользователя
|
|
|
|
|
|
|
|
|
|
выдает найденные директории.
|
|
|
|
|
"""
|
|
|
|
|
if flagDir or stat.S_ISDIR(os.stat(scanDir)[stat.ST_MODE]):
|
|
|
|
|
for fileOrDir in sorted(os.listdir(scanDir)):
|
|
|
|
|
absPath = os.path.join(scanDir,fileOrDir)
|
|
|
|
|
statInfo = os.stat(absPath)[stat.ST_MODE]
|
|
|
|
|
if stat.S_ISREG(statInfo):
|
|
|
|
|
textFile = open(absPath).read()
|
|
|
|
|
if "cl_pass_action==desktop" in textFile:
|
|
|
|
|
userTemplDirs.append(scanDir)
|
|
|
|
|
break
|
|
|
|
|
elif stat.S_ISDIR(statInfo):
|
|
|
|
|
self._getUserTemplateDirs(absPath, userTemplDirs, True)
|
|
|
|
|
return userTemplDirs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def updateConfig(self, nameProgram, category, version, xUsers):
|
|
|
|
|
"""Обновление конфигурационных файлов у пользователей"""
|
|
|
|
|
cleanVer = self.reCleanVer.search(version)
|
|
|
|
@ -198,57 +140,43 @@ class updateUserConfigs(shareUpdateConfigs):
|
|
|
|
|
version = cleanVer.group()
|
|
|
|
|
self.logger.info(_("Package %s") %nameProgram)
|
|
|
|
|
self.logger.info(_("Update desktop configuration files"))
|
|
|
|
|
if not os.path.exists(self.firstEnvFile):
|
|
|
|
|
self.printWARNING(_("File '%s' does not exist")%self.firstEnvFile)
|
|
|
|
|
return True
|
|
|
|
|
if not os.access(self.firstEnvFile, os.R_OK):
|
|
|
|
|
self.printWARNING(_("Permission denied: '%s'")%self.firstEnvFile)
|
|
|
|
|
return True
|
|
|
|
|
sectionsWork = []
|
|
|
|
|
for line in open(self.firstEnvFile).readlines():
|
|
|
|
|
sRet = self.patternSect.search(line)
|
|
|
|
|
if sRet:
|
|
|
|
|
sectionsWork.append(sRet.group(1))
|
|
|
|
|
sectName = "desktop"
|
|
|
|
|
# Программы используемые для наложения шаблонов
|
|
|
|
|
mergePrograms = self.getPrograms()
|
|
|
|
|
if "calculate-desktop" in mergePrograms:
|
|
|
|
|
mergePrograms = ["calculate-desktop"]
|
|
|
|
|
else:
|
|
|
|
|
mergePrograms = []
|
|
|
|
|
dictPakkages = {}
|
|
|
|
|
# Если установлен calculate-desktop
|
|
|
|
|
if sectName in sectionsWork:
|
|
|
|
|
section = ""
|
|
|
|
|
for templatePath in self.templatePaths:
|
|
|
|
|
fullPath = os.path.join(templatePath,sectName)
|
|
|
|
|
if os.path.isdir(fullPath):
|
|
|
|
|
for foundUserPath in self._getUserTemplateDirs(fullPath):
|
|
|
|
|
if self._isApplyTemplateDir(foundUserPath, nameProgram,
|
|
|
|
|
flagSkipDesktop=False):
|
|
|
|
|
section = sectName
|
|
|
|
|
break
|
|
|
|
|
if section:
|
|
|
|
|
# Добавление условия, что программа category/nameProgram
|
|
|
|
|
# установлена
|
|
|
|
|
cl_template.templateFunction.installProg.update(\
|
|
|
|
|
# Добавление условия, что программа category/nameProgram
|
|
|
|
|
# установлена
|
|
|
|
|
cl_template.templateFunction.installProg.update(\
|
|
|
|
|
{"%s/%s"%(category,nameProgram):[version],
|
|
|
|
|
"%s"%(nameProgram):[version]})
|
|
|
|
|
for userName in xUsers:
|
|
|
|
|
clVars = DataVarsObject(section)
|
|
|
|
|
clVars.importDataObject()
|
|
|
|
|
clVars.Set("ur_login", userName, True)
|
|
|
|
|
clVars.Set("cl_pass_action", section, True)
|
|
|
|
|
clVars.Set("cl_belong_pkg", nameProgram, True)
|
|
|
|
|
clTempl = cl_template.template(clVars)
|
|
|
|
|
dirsFiles = clTempl.applyTemplates()
|
|
|
|
|
if dirsFiles is False:
|
|
|
|
|
self.printERROR(\
|
|
|
|
|
_("Error using templates for the user %s")%userName)
|
|
|
|
|
for errMess in clTempl.getError().splitlines():
|
|
|
|
|
self.printERROR(errMess)
|
|
|
|
|
return False
|
|
|
|
|
if dirsFiles and dirsFiles[1]:
|
|
|
|
|
nameAndVerPkg = clVars.Get("cl_name")+"-"+\
|
|
|
|
|
clVars.Get("cl_ver")
|
|
|
|
|
if not nameAndVerPkg in dictPakkages:
|
|
|
|
|
dictPakkages[nameAndVerPkg] = []
|
|
|
|
|
dictPakkages[nameAndVerPkg].append((userName,
|
|
|
|
|
sorted(list(set(dirsFiles[1])))))
|
|
|
|
|
for mergeProgram in mergePrograms:
|
|
|
|
|
for userName in xUsers:
|
|
|
|
|
clVars = DataVarsObject(mergeProgram)
|
|
|
|
|
if not clVars.findPathVars():
|
|
|
|
|
continue
|
|
|
|
|
clVars.importDataObject()
|
|
|
|
|
clVars.Set("ur_login", userName, True)
|
|
|
|
|
clVars.Set("cl_action", "desktop", True)
|
|
|
|
|
clVars.Set("cl_belong_pkg", nameProgram, True)
|
|
|
|
|
clTempl = cl_template.template(clVars)
|
|
|
|
|
dirsFiles = clTempl.applyTemplates()
|
|
|
|
|
if dirsFiles is False:
|
|
|
|
|
self.printERROR(\
|
|
|
|
|
_("Error using templates for the user %s")\
|
|
|
|
|
%userName)
|
|
|
|
|
for errMess in clTempl.getError().splitlines():
|
|
|
|
|
self.printERROR(errMess)
|
|
|
|
|
return False
|
|
|
|
|
if dirsFiles and dirsFiles[1]:
|
|
|
|
|
nameAndVerPkg = clVars.Get("cl_name")+"-"+\
|
|
|
|
|
clVars.Get("cl_ver")
|
|
|
|
|
if not nameAndVerPkg in dictPakkages:
|
|
|
|
|
dictPakkages[nameAndVerPkg] = []
|
|
|
|
|
dictPakkages[nameAndVerPkg].append((userName,
|
|
|
|
|
sorted(list(set(dirsFiles[1])))))
|
|
|
|
|
if dictPakkages:
|
|
|
|
|
for calcPkg in dictPakkages:
|
|
|
|
|
self.printWARNING(_("Package %s has changed files")\
|
|
|
|
@ -292,37 +220,21 @@ class updateSystemConfigs(shareUpdateConfigs):
|
|
|
|
|
if not os.path.exists(configPath):
|
|
|
|
|
self.printERROR(_("Path '%s' does not exist")%configPath)
|
|
|
|
|
return False
|
|
|
|
|
if not os.path.exists(self.firstEnvFile):
|
|
|
|
|
self.printWARNING(_("File '%s' does not exist")%self.firstEnvFile)
|
|
|
|
|
return True
|
|
|
|
|
if not os.access(self.firstEnvFile, os.R_OK):
|
|
|
|
|
self.printWARNING(_("Permission denied: '%s'")%self.firstEnvFile)
|
|
|
|
|
return True
|
|
|
|
|
sections = []
|
|
|
|
|
sectionsWork = []
|
|
|
|
|
for line in open(self.firstEnvFile).readlines():
|
|
|
|
|
sRet = self.patternSect.search(line)
|
|
|
|
|
if sRet:
|
|
|
|
|
sectionsWork.append(sRet.group(1))
|
|
|
|
|
#sectionsWork = os.listdir(self.templatePaths[0])
|
|
|
|
|
for sectName in sectionsWork:
|
|
|
|
|
for templatePath in self.templatePaths:
|
|
|
|
|
fullPath = os.path.join(templatePath,sectName)
|
|
|
|
|
if not sectName in sections and os.path.isdir(fullPath):
|
|
|
|
|
if self._isApplyTemplateDir(fullPath, nameProgram):
|
|
|
|
|
sections.append(sectName)
|
|
|
|
|
|
|
|
|
|
# Программы используемые для наложения шаблонов
|
|
|
|
|
mergePrograms = self.getPrograms()
|
|
|
|
|
dictPakkages = {}
|
|
|
|
|
if sections:
|
|
|
|
|
# Добавление условия, что программа category/nameProgram установлена
|
|
|
|
|
cl_template.templateFunction.installProg.update(\
|
|
|
|
|
{"%s/%s"%(category,nameProgram):[version],
|
|
|
|
|
"%s"%(nameProgram):[version]})
|
|
|
|
|
for sectName in sections:
|
|
|
|
|
clVars = DataVarsObject(sectName)
|
|
|
|
|
# Добавление условия, что программа category/nameProgram установлена
|
|
|
|
|
cl_template.templateFunction.installProg.update(\
|
|
|
|
|
{"%s/%s"%(category,nameProgram):[version],
|
|
|
|
|
"%s"%(nameProgram):[version]})
|
|
|
|
|
for mergeProgram in mergePrograms:
|
|
|
|
|
clVars = DataVarsObject(mergeProgram)
|
|
|
|
|
if not clVars.findPathVars():
|
|
|
|
|
continue
|
|
|
|
|
clVars.importDataObject()
|
|
|
|
|
clVars.Set("cl_root_path",configPath, True)
|
|
|
|
|
clVars.Set("cl_belong_pkg",nameProgram, True)
|
|
|
|
|
clVars.Set("cl_root_path", configPath, True)
|
|
|
|
|
clVars.Set("cl_belong_pkg", nameProgram, True)
|
|
|
|
|
clVars.Set("cl_action", 'merge', True)
|
|
|
|
|
clTempl = cl_template.template(clVars)
|
|
|
|
|
dirsFiles = clTempl.applyTemplates()
|
|
|
|
|
nameAndVerPkg = clVars.Get("cl_name")+"-"+clVars.Get("cl_ver")
|
|
|
|
|