Merge master

master3.3
Mike Hiretsky 11 years ago
commit 21527e6343

@ -2185,7 +2185,7 @@ class _file(_error):
F_TEMPL = open(nameFileTemplate, "r") F_TEMPL = open(nameFileTemplate, "r")
except: except:
self.setError(_("unable to open the file:") self.setError(_("unable to open the file:")
+ nameFileConfig) + nameFileTemplate)
return False return False
return F_TEMPL return F_TEMPL
@ -2786,7 +2786,7 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction):
if os.path.exists(fileName): if os.path.exists(fileName):
FD = open(fileName) FD = open(fileName)
replace = FD.read().strip() replace = FD.read().strip()
FD.close FD.close()
if replace and lenTerms >= 2 and terms[0] == "empty": if replace and lenTerms >= 2 and terms[0] == "empty":
replace ="\n".join(filter(lambda x: not self.reEmptyLoad.search(x), replace ="\n".join(filter(lambda x: not self.reEmptyLoad.search(x),
replace.split("\n"))) replace.split("\n")))
@ -3091,7 +3091,7 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction):
return textTemplateTmp return textTemplateTmp
self.printERROR(_(funArgv)) self.printERROR(_(funArgv))
raise TemplatesInterrupt(_("Execution of templates was " raise TemplatesInterrupt(_("Execution of templates was "
"interrupted with the error"), "interrupted with an error"),
TemplatesInterrupt.ABORT) TemplatesInterrupt.ABORT)
def getElogTimestamp(self): def getElogTimestamp(self):
@ -3113,18 +3113,25 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction):
return int(val) return int(val)
return 0 return 0
elogFile = '/var/log/emerge.log'
@classmethod
def getLastElog(cls):
# get last timestamp
lastStr = ""
for l in readLinesFile(cls.elogFile):
lastStr = l
return lastStr.partition(':')[0]
def funcElog(self,funArgv, resS, localVars, textTemplateTmp, nameTemp): def funcElog(self,funArgv, resS, localVars, textTemplateTmp, nameTemp):
"""Function for work with emerge.log""" """Function for work with emerge.log"""
# TODO: need remove
return textTemplateTmp
funArgv = funArgv.strip() funArgv = funArgv.strip()
rePkg = re.compile(r'completed emerge \(\d+ of \d+\) (\S+)\s',re.S) rePkg = re.compile(r'completed emerge \(\d+ of \d+\) (\S+)\s',re.S)
logFile = '/var/log/emerge.log'
replace = "" replace = ""
if funArgv: if funArgv:
lastTimestamp = self.getElogTimestamp() lastTimestamp = self.getElogTimestamp()
skip = True skip = True
for line in reversed(list(readLinesFile(logFile))): for line in reversed(list(readLinesFile(self.elogFile))):
timestamp,op,info = line.partition(':') timestamp,op,info = line.partition(':')
if timestamp.isdigit() and lastTimestamp and \ if timestamp.isdigit() and lastTimestamp and \
int(timestamp) < lastTimestamp: int(timestamp) < lastTimestamp:
@ -3136,9 +3143,7 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction):
replace = pkgInfo['PVR'] replace = pkgInfo['PVR']
break break
else: else:
# get last timestamp replace = self.getLastElog()
replace = readFile(logFile).rpartition(
'\n')[2].lpartition(':')[0]
textTemplateTmp = textTemplateTmp[:resS.start()] + replace + \ textTemplateTmp = textTemplateTmp[:resS.start()] + replace + \
textTemplateTmp[resS.end():] textTemplateTmp[resS.end():]
return textTemplateTmp return textTemplateTmp
@ -3441,8 +3446,7 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction):
for portdir in queuePortdir(): for portdir in queuePortdir():
if not portdir in self.cachePortdir: if not portdir in self.cachePortdir:
lPortdir = len(portdir)+1 lPortdir = len(portdir)+1
self.cachePortdir[portdir] = \ self.cachePortdir[portdir] = list(set(
list(set(
map(lambda x:x[lPortdir:].rpartition('/')[0], map(lambda x:x[lPortdir:].rpartition('/')[0],
glob.glob("%s/*/*/*.ebuild"%portdir)))) glob.glob("%s/*/*/*.ebuild"%portdir))))
if package in self.cachePortdir[portdir]: if package in self.cachePortdir[portdir]:
@ -4313,7 +4317,7 @@ gettext -d cl_template "$*"
self.printWARNING("") self.printWARNING("")
self.printWARNING(_("Headers of directory templates and headers " self.printWARNING(_("Headers of directory templates and headers "
"of files on the first level should include " "of files on the first level should include "
"an action variable.")) "an action variable"))
self.printWARNING(_("Example:")) self.printWARNING(_("Example:"))
self.printWARNING("# Calculate ac_install_merge==on") self.printWARNING("# Calculate ac_install_merge==on")
return skipDirs + skipTemplates return skipDirs + skipTemplates
@ -4574,7 +4578,7 @@ gettext -d cl_template "$*"
self.filesApply = map(lambda x:autoUpdateDict.get(x,x),self.filesApply) self.filesApply = map(lambda x:autoUpdateDict.get(x,x),self.filesApply)
if filter(lambda x:"._cfg" in x, self.filesApply): if filter(lambda x:"._cfg" in x, self.filesApply):
self.printWARNING(_("Some config files need updating. " self.printWARNING(_("Some config files need updating. "
"Perform dispatch-conf.")) "Perform run dispatch-conf."))
if self.dispatchConf and \ if self.dispatchConf and \
self.objVar.Get('cl_dispatch_conf') == 'dispatch' and \ self.objVar.Get('cl_dispatch_conf') == 'dispatch' and \
self.objVar.Get('cl_ebuild_phase') == '': self.objVar.Get('cl_ebuild_phase') == '':
@ -4809,7 +4813,7 @@ gettext -d cl_template "$*"
if not objHead.headerTerm: if not objHead.headerTerm:
if objHead.getError(): if objHead.getError():
self.setError(_("Incorrect template") + ": " +\ self.setError(_("Incorrect template") + ": " +\
templateDirFile) templateDirFile)
return ("", False, []) return ("", False, [])
# add packeges for reconfigure # add packeges for reconfigure
@ -4819,7 +4823,7 @@ gettext -d cl_template "$*"
if not self.functObj.checkCorrectPkgName(x)): if not self.functObj.checkCorrectPkgName(x)):
self.printWARNING( self.printWARNING(
_("Wrong package '%s' for 'merge' in the template")% _("Wrong package '%s' for 'merge' in the template")%
wrongPkg + ": " + nameFileTemplate) wrongPkg + ": " + templateDirFile)
for pkg in mergePkgs: for pkg in mergePkgs:
if not pkg in self.objVar.Get('cl_merge_pkg_new') and \ if not pkg in self.objVar.Get('cl_merge_pkg_new') and \
not pkg in self.objVar.Get('cl_merge_pkg_pass') and \ not pkg in self.objVar.Get('cl_merge_pkg_pass') and \
@ -5133,7 +5137,7 @@ gettext -d cl_template "$*"
self.F_TEMPL = self.openTemplFile(self.nameFileTemplate) self.F_TEMPL = self.openTemplFile(self.nameFileTemplate)
if not self.F_TEMPL: if not self.F_TEMPL:
self.setError(_("Failed to open the template") + ": " +\ self.setError(_("Failed to open the template") + ": " +\
templateDirFile) self.nameFileTemplate)
return False return False
self.textTemplate = self.F_TEMPL.read() self.textTemplate = self.F_TEMPL.read()
self.closeTemplFile() self.closeTemplFile()
@ -5589,7 +5593,9 @@ gettext -d cl_template "$*"
optFile) optFile)
if not objHeadNew: if not objHeadNew:
return filesApply return filesApply
self.templateModify() if filesApply and not filter(lambda x:"calculate/ini.env" in x,
filesApply):
self.templateModify()
if templateFileType != "bin": if templateFileType != "bin":
# Вычисляем условные блоки # Вычисляем условные блоки
objHeadNew.body = self.applyTermsTemplate(objHeadNew.body, objHeadNew.body = self.applyTermsTemplate(objHeadNew.body,

@ -49,7 +49,7 @@ class diff(_error):
if patchDryRun.success(): if patchDryRun.success():
return "" return ""
else: else:
self.setError(_("Patch failed")) self.setError(_("Correction failed"))
return False return False
patchRun = process('/usr/bin/patch', patchRun = process('/usr/bin/patch',
'-p%d'%i,cwd=rootPath) '-p%d'%i,cwd=rootPath)

@ -28,6 +28,9 @@ import string
from calculate.lib.cl_lang import setLocalTranslate from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_lib3',sys.modules[__name__]) setLocalTranslate('cl_lib3',sys.modules[__name__])
class CommonError(Exception):
pass
class _error: class _error:
# Здесь ошибки, если они есть # Здесь ошибки, если они есть
error = [] error = []
@ -418,3 +421,74 @@ def getPagesInterval(count,offset,length):
lt = int(math.ceil(float(lt)/count)) lt = int(math.ceil(float(lt)/count))
rt = int(math.ceil(float(rt)/count)) rt = int(math.ceil(float(rt)/count))
return (lt + 1, rt + lt + 1) return (lt + 1, rt + lt + 1)
def mountEcryptfs(userName,userPwd,userDir):
"""
Подключить ecryptfs
Args:
userName: логин пользователя
userPwd: пароль пользователя
userDir: домашний каталог пользователя
"""
from calculate.lib.utils.files import (process,readLinesFile,STDOUT,
isMount)
if ".Private" in isMount(userDir):
return True
# расшифровать passphrase
ecryptUserName = path.join('/home/.ecryptfs', userName)
wrappedPassphraseFile = path.join(ecryptUserName,
".ecryptfs/wrapped-passphrase")
p = process('/usr/bin/ecryptfs-unwrap-passphrase',wrappedPassphraseFile)
p.write(userPwd)
try:
if p.failed():
raise Exception
result = p.readlines()
if len(result) > 1 and "Passphrase:" in result[0] and result[1]:
passphrase = result[1]
else:
raise Exception
except:
raise CommonError(_("Failed to unwrap the passphrase"))
# добавить passphrase в ключи ядра
p = process('/usr/bin/ecryptfs-add-passphrase', '--fnek', '-',stderr=STDOUT)
p.write(passphrase)
if not p.success():
raise CommonError(p.read()+"Failed to add passphrase")
# получить сигнатуры шифрования содержимого файлов и имен файлов
try:
ecryptfs_sig, ecryptfs_fnek_sig = \
readLinesFile(path.join(ecryptUserName,".ecryptfs/Private.sig"))
except ValueError:
raise CommonError(_("Failed to parse Private.sig"))
# подключить шифрованный раздел
mountProcess = process('/sbin/mount.ecryptfs',
path.join(ecryptUserName,'.Private'),
userDir,
'-o','ecryptfs_passthrough=n,'
'ecryptfs_cipher=aes,'
'ecryptfs_key_bytes=16,'
'no_sig_cache,'
'ecryptfs_enable_filename_crypto=y,'
'ecryptfs_sig={ecryptfs_sig},'
'ecryptfs_fnek_sig={ecryptfs_fnek_sig},'
'passphrase_passwd_fd=0'.format(
ecryptfs_sig=ecryptfs_sig,
ecryptfs_fnek_sig=ecryptfs_fnek_sig),stderr=STDOUT)
# отправить пароль через stdin
mountProcess.write("passphrase_passwd="+userPwd)
return mountProcess.success()
def isBootstrapDataOnly(directory):
"""
Каталог содержит только сертификат, созданный командой cl-core
"""
from calculate.lib.utils.files import (process,readLinesFile,STDOUT,
isMount)
userCalculate = path.join(directory,".calculate")
return (set(listDirectory(directory)) == set([".calculate"]) and
set(listDirectory(userCalculate)) == set(["client_cert"]))

@ -327,7 +327,10 @@ class Pinger:
""" """
Send one ping to the given >destIP<. Send one ping to the given >destIP<.
""" """
destIP = socket.gethostbyname(destIP) try:
destIP = socket.gethostbyname(destIP)
except socket.gaierror as e:
raise IPError(e.strerror)
# Header is type (8), code (8), checksum (16), id (16), sequence (16) # Header is type (8), code (8), checksum (16), id (16), sequence (16)
myChecksum = 0 myChecksum = 0

@ -25,4 +25,4 @@ class VariableClVer(ReadonlyVariable):
""" """
Package version Package version
""" """
value = "3.1.5.1" value = "3.1.6"

@ -200,10 +200,8 @@ class VariableClAutoupdateSet(Variable):
def get(self): def get(self):
if self.Get('cl_dispatch_conf') == 'usenew': if self.Get('cl_dispatch_conf') == 'usenew':
print "ON"
return "on" return "on"
else: else:
print "OFF"
return "off" return "off"
class VariableClDispatchConf(Variable): class VariableClDispatchConf(Variable):
@ -217,14 +215,14 @@ class VariableClDispatchConf(Variable):
metavalue = "METHOD" metavalue = "METHOD"
def init(self): def init(self):
self.help = "'usenew' - " +_("use new config files") +\ self.help = "'usenew' - " +_("use the new config files") +\
",\n'skip' - " + _("skip the update config files") +\ ",\n'skip' - " + _("skip the update of config files") +\
",\n'dispatch' - " + _("manually update config files") ",\n'dispatch' - " + _("manually update config files")
self.label = _("Update config files method") self.label = _("Method for updating config files")
def choice(self): def choice(self):
return [("usenew",_("Use new config files")), return [("usenew",_("Use the new config files")),
("skip",_("Skip the update config files")), ("skip",_("Skip the update of config files")),
("dispatch",_("Manually update config files"))] ("dispatch",_("Manually update config files"))]
class VariableClWsdl(Variable): class VariableClWsdl(Variable):

@ -18,10 +18,11 @@ import os
import socket import socket
import pwd import pwd
import grp import grp
from os import environ from os import environ,path
from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable
from calculate.lib.cl_vars_share import varsShare from calculate.lib.cl_vars_share import varsShare
from calculate.lib.utils.common import getPasswdUsers from calculate.lib.utils.common import getPasswdUsers,isBootstrapDataOnly
from calculate.lib.utils.files import listDirectory
import sys import sys
from calculate.lib.cl_lang import setLocalTranslate from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_lib3',sys.modules[__name__]) setLocalTranslate('cl_lib3',sys.modules[__name__])
@ -206,3 +207,34 @@ class VariableUrMail(ReadonlyVariable,LdapHelper):
if userInfo: if userInfo:
userMail = userInfo["mail"] userMail = userInfo["mail"]
return userMail return userMail
class VariableClHomeCryptSet(Variable):
"""
Вкл/выкл шифрование пользовательских профилей
"""
value = "off"
type = "bool"
class VariableUrHomeCryptSet(ReadonlyVariable):
"""
Шифрованный или нет пользовательский профиль
"""
type = "bool"
def get(self):
# если у пользователский профиль настроен как шифрованный
login = self.Get('ur_login')
if login == "root":
return "off"
cryptPath = path.join('/home/.ecryptfs',login,'.ecryptfs')
if path.exists(cryptPath):
return "on"
# если пользовательского профиля нет, то шифровать ли профиль
# узнаем на уровне системы
homeDir = self.Get('ur_home_path')
if (not path.exists(homeDir) or not listDirectory(homeDir) or
isBootstrapDataOnly(homeDir)):
return self.Get('cl_home_crypt_set')
# профиль не шифрованный
return "off"

@ -22,7 +22,7 @@ from distutils.core import setup
from distutils.command.build_scripts import build_scripts from distutils.command.build_scripts import build_scripts
from distutils.command.install_scripts import install_scripts from distutils.command.install_scripts import install_scripts
__version__ = "3.1.4" __version__ = "3.1.6"
__app__ = "calculate-lib" __app__ = "calculate-lib"
module_name = "calculate.lib" module_name = "calculate.lib"

Loading…
Cancel
Save