Merge master

master3.3
Mike Hiretsky 11 years ago
commit 21527e6343

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

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

@ -28,6 +28,9 @@ import string
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_lib3',sys.modules[__name__])
class CommonError(Exception):
pass
class _error:
# Здесь ошибки, если они есть
error = []
@ -418,3 +421,74 @@ def getPagesInterval(count,offset,length):
lt = int(math.ceil(float(lt)/count))
rt = int(math.ceil(float(rt)/count))
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<.
"""
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)
myChecksum = 0

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

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

@ -18,10 +18,11 @@ import os
import socket
import pwd
import grp
from os import environ
from os import environ,path
from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable
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
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_lib3',sys.modules[__name__])
@ -206,3 +207,34 @@ class VariableUrMail(ReadonlyVariable,LdapHelper):
if userInfo:
userMail = userInfo["mail"]
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.install_scripts import install_scripts
__version__ = "3.1.4"
__version__ = "3.1.6"
__app__ = "calculate-lib"
module_name = "calculate.lib"

Loading…
Cancel
Save