Рефакторинг: работа с файлами

migr_to_suds 3.6.2.1
parent 0c9437a4bc
commit c306cec3c2

@ -31,7 +31,7 @@ from calculate.core.datavars import DataVarsCore
from calculate.core.server.methods_func import get_password
from calculate.lib.cl_lang import setLocalTranslate
from calculate.lib.utils.common import getpass
from calculate.lib.utils.files import listDirectory
from calculate.lib.utils.files import listDirectory, readFile
_ = lambda x: x
setLocalTranslate('cl_console3', sys.modules[__name__])
@ -137,7 +137,7 @@ def client_post_request(cert_path, args):
if os.path.exists(cert_path + 'req_id'):
print \
_("You already sent a certificate signature request.")
_print(_("Request ID = %s") % open(cert_path + 'req_id', 'r').read())
_print(_("Request ID = %s") % readFile(cert_path + 'req_id'))
ans = raw_input(_("Send a new request? y/[n]: "))
if not ans.lower() in ['y', 'yes']:
return 0
@ -177,7 +177,7 @@ def client_post_request(cert_path, args):
private_key_passwd=passwd)
ip, mac, client_type = get_ip_mac_type()
data = open(csr_file).read()
data = readFile(csr_file)
res = client.service.post_client_request(request=data, ip=ip,
mac=mac, client_type=client_type)
if int(res) < 0:
@ -226,7 +226,7 @@ def client_get_cert(cert_path, args):
print _("Request %s not found on the client's side") \
% (os.path.join(cert_path, server_host_name + '.csr'))
return 1
request = open(os.path.join(cert_path, server_host_name + '.csr')).read()
request = readFile(os.path.join(cert_path, server_host_name + '.csr'))
md5 = hashlib.md5()
md5.update(request)
md5sum = md5.hexdigest()
@ -273,7 +273,7 @@ def client_get_cert(cert_path, args):
if ca_root:
system_ca_db = clVars.Get('core.cl_glob_root_cert')
if os.path.exists(system_ca_db):
if ca_root in open(system_ca_db, 'r').read():
if ca_root in readFile(system_ca_db):
return 0
cl_client_cert_dir = clVars.Get('core.cl_client_cert_dir')
@ -359,7 +359,7 @@ def getRunProc():
cmdLineFile = '/proc/%s/cmdline' % procNum
try:
if os.path.exists(cmdLineFile):
return [open(cmdLineFile, 'r').read().strip(), procNum]
return [readFile(cmdLineFile).strip(), procNum]
except:
pass
return ["", procNum]
@ -442,7 +442,7 @@ def clear_password(server_host, server_port):
try:
while connect_error < 10:
if os.path.isfile(file_path):
serv_port, hash_val = open(file_path, 'r').read().split()
serv_port, hash_val = readFile(file_path).split()
s.connect(('localhost', int(serv_port)))
req = 'delete,%s,%s,%s,%s' % (server_host, str(server_port),
username, hash_val)
@ -463,7 +463,7 @@ def socket_connect(s, file_path):
try:
while connect_error < 10:
if os.path.isfile(file_path):
serv_port, hash_val = open(file_path, 'r').read().split()
serv_port, hash_val = readFile(file_path).split()
s.connect(('localhost', int(serv_port)))
return s, hash_val
else:

@ -21,6 +21,7 @@ import OpenSSL
from calculate.console.application.function import _print
from calculate.core.datavars import DataVarsCore
from calculate.lib.utils.files import readFile
from calculate.lib.cl_lang import setLocalTranslate
_ = lambda x: x
@ -121,11 +122,11 @@ def get_CRL(path_to_cert):
glob_root_cert = clVars.Get('core.cl_glob_root_cert')
if os.path.exists(user_root_cert):
user_ca_certs = open(user_root_cert, 'r').read()
user_ca_certs = readFile(user_root_cert)
else:
user_ca_certs = ''
if os.path.exists(glob_root_cert):
glob_ca_certs = open(glob_root_cert, 'r').read()
glob_ca_certs = readFile(glob_root_cert)
else:
glob_ca_certs = ''
@ -177,17 +178,16 @@ def get_CRL(path_to_cert):
host = last_subj[1].split(':')[0]
CRL_file = CRL_path + host
if new_crl == ' ':
open(CRL_file, 'w')
open(CRL_file, 'w').close()
# if os.path.exists(CRL_file):
# os.unlink(CRL_file)
continue
if os.path.exists(CRL_file):
if open(CRL_file, 'r').read() == new_crl:
if readFile(CRL_file) == new_crl:
continue
fd = open(CRL_file, 'w')
fd.write(new_crl)
fd.close()
with open(CRL_file, 'w') as fd:
fd.write(new_crl)
print _("CRL added")
find_ca_in_crl(CRL_path, all_ca_certs_list)
@ -257,7 +257,7 @@ def rm_ca_from_trusted(ca_cert):
words = line.split()
if words[0] == md5sum:
filename = os.path.join(user_ca_dir, words[1])
if ca_cert == open(filename, 'r').read():
if ca_cert == readFile(filename):
try:
os.unlink(filename)
except OSError, e:
@ -275,7 +275,7 @@ def rm_ca_from_trusted(ca_cert):
p = re.compile('[-]+[\w ]+[-]+\n+[\w\n\+\\=/]+[-]+[\w ]+[-]+\n?')
# open, write and split user ca certificates
user_ca_certs = open(user_ca_db, 'r').read()
user_ca_certs = readFile(user_ca_db)
user_ca_certs_list = p.findall(user_ca_certs)
if ca_cert in user_ca_certs_list:
@ -293,9 +293,9 @@ def rm_ca_from_trusted(ca_cert):
fd.close()
if not os.path.exists(system_ca_db):
open(system_ca_db, 'w')
open(system_ca_db, 'w').close()
system_ca_certs = open(system_ca_db, 'r').read()
system_ca_certs = readFile(system_ca_db)
system_ca_certs_list = p.findall(system_ca_certs)
if ca_cert in system_ca_certs_list:

@ -40,6 +40,7 @@ from logging import getLogger
from calculate.console.datavars import DataVarsConsole
from calculate.lib.cl_lang import setLocalTranslate
from calculate.console.application.sid_func import SessionId
from calculate.lib.utils.files import readFile
_ = lambda x: x
setLocalTranslate('cl_console3', sys.modules[__name__])
@ -110,7 +111,7 @@ class CheckingClientHTTPSConnection(CheckingHTTPSConnection):
if not filename:
return None
except:
print _("Certificate not found on the clients side")
print _("Certificate not found on the client`s side")
return None
try:
fd = open(self.trusted_path + filename, 'r')
@ -143,11 +144,11 @@ class CheckingClientHTTPSConnection(CheckingHTTPSConnection):
for cert in list_ca_certs:
if os.path.exists(system_ca_db):
if cert in open(system_ca_db, 'r').read():
if cert in readFile(system_ca_db):
continue
if os.path.exists(user_root_cert):
if cert in open(user_root_cert, 'r').read():
if cert in readFile(user_root_cert):
continue
md5 = hashlib.md5()

@ -26,6 +26,7 @@ from calculate.core.server.api_types import ArrayReturnedMessage, TableAdapter
from calculate.core.server.cert_cmd import getHwAddr, getIpLocal
from calculate.core.server.local_call import print_brief_group
from calculate.lib.cl_lang import setLocalTranslate
from calculate.lib.utils.files import readFile
from sudsds import MethodNotFound
_ = lambda x: x
@ -85,7 +86,7 @@ def print_brief(view, brief_label):
def _return_revoked_serials(crlfile):
try:
serials = []
crltext = open(crlfile, 'r').read()
crltext = readFile(crlfile)
crl = crypto.load_crl(crypto.FILETYPE_PEM, crltext)
revs = crl.get_revoked()
for revoked in revs:

Loading…
Cancel
Save