diff --git a/hooks/config-changed b/hooks/config-changed index bfdac9a..7a9db07 100755 --- a/hooks/config-changed +++ b/hooks/config-changed @@ -256,7 +256,7 @@ targets = {os.path.join(target_prefix, 'binlog.cnf'): binlog_cnf, } need_restart = False -for target,content in targets.iteritems(): +for target,content in targets.items(): tdir = os.path.dirname(target) if len(content) == 0 and os.path.exists(target): os.unlink(target) diff --git a/hooks/shared_db_relations.py b/hooks/shared_db_relations.py index 3c34b13..615fd55 100755 --- a/hooks/shared_db_relations.py +++ b/hooks/shared_db_relations.py @@ -9,6 +9,7 @@ import subprocess import json +from collections import defaultdict import lib.utils as utils import lib.cluster_utils as cluster @@ -33,8 +34,7 @@ def relation_get(): def unit_sorted(units): """Return a sorted list of unit names.""" - return sorted( - units, lambda a, b: cmp(int(a.split('/')[-1]), int(b.split('/')[-1]))) + return sorted(units, lambda name: int(name.split('/')[-1])) def get_unit_addr(relid, unitid): @@ -109,12 +109,9 @@ def shared_db_changed(): # } # } # - databases = {} - for k, v in settings.iteritems(): - db = k.split('_')[0] - x = '_'.join(k.split('_')[1:]) - if db not in databases: - databases[db] = {} + databases = defaultdict(dict) + for k, v in settings.items(): + db, x = k.split('_', 1) databases[db][x] = v return_data = {} diff --git a/scripts/charm_helpers_sync.py b/scripts/charm_helpers_sync.py index 3249f1e..ebfb5f1 100755 --- a/scripts/charm_helpers_sync.py +++ b/scripts/charm_helpers_sync.py @@ -159,7 +159,7 @@ def sync_helpers(include, src, dest, options=None): sync(src, dest, inc, opts) elif isinstance(inc, dict): # could also do nested dicts here. - for k, v in inc.iteritems(): + for k, v in inc.items(): if isinstance(v, list): for m in v: inc, opts = extract_options(m, global_options)