summaryrefslogtreecommitdiff
path: root/odoo/tools
diff options
context:
space:
mode:
Diffstat (limited to 'odoo/tools')
-rw-r--r--odoo/tools/config.py22
-rwxr-xr-xodoo/tools/graph.py38
-rw-r--r--odoo/tools/misc.py5
3 files changed, 44 insertions, 21 deletions
diff --git a/odoo/tools/config.py b/odoo/tools/config.py
index 25d62ef0cf7..1901620cf4e 100644
--- a/odoo/tools/config.py
+++ b/odoo/tools/config.py
@@ -14,6 +14,9 @@ import odoo
from .. import release, conf, loglevels
from . import appdirs, pycompat
+from passlib.context import CryptContext
+crypt_context = CryptContext(schemes=['pbkdf2_sha512', 'plaintext'],
+ deprecated=['plaintext'])
class MyOption (optparse.Option, object):
""" optparse Option with two additional attributes.
@@ -242,7 +245,9 @@ class configmanager(object):
security = optparse.OptionGroup(parser, 'Security-related options')
security.add_option('--no-database-list', action="store_false", dest='list_db', my_default=True,
- help="disable the ability to return the list of databases")
+ help="Disable the ability to obtain or view the list of databases. "
+ "Also disable access to the database manager and selector, "
+ "so be sure to set a proper --database parameter first")
parser.add_option_group(security)
# Advanced options
@@ -625,4 +630,19 @@ class configmanager(object):
def filestore(self, dbname):
return os.path.join(self['data_dir'], 'filestore', dbname)
+ def set_admin_password(self, new_password):
+ self.options['admin_passwd'] = crypt_context.encrypt(new_password)
+
+ def verify_admin_password(self, password):
+ """Verifies the super-admin password, possibly updating the stored hash if needed"""
+ stored_hash = self.options['admin_passwd']
+ if not stored_hash:
+ # empty password/hash => authentication forbidden
+ return False
+ result, updated_hash = crypt_context.verify_and_update(password, stored_hash)
+ if result:
+ if updated_hash:
+ self.options['admin_passwd'] = updated_hash
+ return True
+
config = configmanager()
diff --git a/odoo/tools/graph.py b/odoo/tools/graph.py
index d43088d97ab..0f7665f0624 100755
--- a/odoo/tools/graph.py
+++ b/odoo/tools/graph.py
@@ -257,7 +257,7 @@ class graph(object):
"""The ranks are normalized by setting the least rank to zero.
"""
- least_rank = min(x['x'] for x in self.result.values.values())
+ least_rank = min(x['x'] for x in self.result.values())
if least_rank!=0:
for node in self.result:
@@ -334,7 +334,7 @@ class graph(object):
"""
adj_nodes = self.adj_position(node, adj_rank)
l = len(adj_nodes)
- m = l/2
+ m = l // 2
if l==0:
return -1.0
@@ -381,7 +381,7 @@ class graph(object):
"""Finds actual-order of the nodes with respect to maximum number of nodes in a rank in component
"""
mid_pos = 0.0
- max_level = max(len(x) for x in self.levels.values.values())
+ max_level = max(len(x) for x in self.levels.values())
for level in self.levels:
if level:
@@ -391,16 +391,16 @@ class graph(object):
list.reverse()
if no%2==0:
- first_half = list[no/2:]
+ first_half = list[no // 2:]
factor = -factor
else:
- first_half = list[no/2+1:]
+ first_half = list[no // 2 + 1:]
if max_level==1:#for the case when horizontal graph is there
- self.result[list[no/2]]['y'] = mid_pos + (self.result[list[no/2]]['x']%2 * 0.5)
+ self.result[list[no // 2]]['y'] = mid_pos + (self.result[list[no // 2]]['x']%2 * 0.5)
else:
- self.result[list[no/2]]['y'] = mid_pos + factor
+ self.result[list[no // 2]]['y'] = mid_pos + factor
- last_half = list[:no/2]
+ last_half = list[:no // 2]
i=1
for node in first_half:
@@ -423,8 +423,8 @@ class graph(object):
no = len(l)
rest = no%2
- first_half = l[no/2+rest:]
- last_half = l[:no/2]
+ first_half = l[no // 2 + rest:]
+ last_half = l[:no // 2]
for i, child in enumerate(first_half):
self.result[child]['y'] = mid_pos - (i+1 - (0 if rest else 0.5))
@@ -435,7 +435,7 @@ class graph(object):
last = self.tree_order(child, last)
if rest:
- mid_node = l[no/2]
+ mid_node = l[no // 2]
self.result[mid_node]['y'] = mid_pos
if self.transitions.get(mid_node, False):
@@ -472,7 +472,7 @@ class graph(object):
"""
if self.Is_Cyclic:
- max_level = max(len(x) for x in self.levels.values.values())
+ max_level = max(len(x) for x in self.levels.values())
if max_level%2:
self.result[self.start]['y'] = (max_level+1)/2 + self.max_order + (self.max_order and 1)
@@ -484,7 +484,7 @@ class graph(object):
else:
self.result[self.start]['y'] = 0
self.tree_order(self.start, 0)
- min_order = math.fabs(min(x['y'] for x in self.result.values.values()))
+ min_order = math.fabs(min(x['y'] for x in self.result.values()))
index = self.start_nodes.index(self.start)
same = False
@@ -518,27 +518,27 @@ class graph(object):
no = len(roots)
- first_half = roots[:no/2]
+ first_half = roots[:no // 2]
if no%2==0:
- last_half = roots[no/2:]
+ last_half = roots[no // 2:]
else:
- last_half = roots[no/2+1:]
+ last_half = roots[no // 2 + 1:]
- factor = -math.floor(no/2)
+ factor = -math.floor(no // 2)
for start in first_half:
self.result[start]['y'] = base + factor
factor += 1
if no%2:
- self.result[roots[no/2]]['y'] = base + factor
+ self.result[roots[no // 2]]['y'] = base + factor
factor +=1
for start in last_half:
self.result[start]['y'] = base + factor
factor += 1
- self.max_order = max(x['y'] for x in self.result.values.values())
+ self.max_order = max(x['y'] for x in self.result.values())
def find_starts(self):
"""Finds other start nodes of the graph in the case when graph is disconneted
diff --git a/odoo/tools/misc.py b/odoo/tools/misc.py
index 7e796831f29..49f8024c5ed 100644
--- a/odoo/tools/misc.py
+++ b/odoo/tools/misc.py
@@ -215,7 +215,10 @@ def _fileopen(path, mode, basedir, pathinfo, basename=None):
# Give higher priority to module directories, which is
# a more common case than zipped modules.
if os.path.isfile(name):
- fo = open(name, mode)
+ if 'b' in mode:
+ fo = open(name, mode)
+ else:
+ fo = io.open(name, mode, encoding='utf-8')
if pathinfo:
return fo, name
return fo