From 8702d692e6bf7797907b789db06bebdb83d473d7 Mon Sep 17 00:00:00 2001 From: Giorgos Korfiatis <gkorf@grnet.gr> Date: Thu, 14 May 2015 12:50:03 +0300 Subject: [PATCH] determine instance id --- agkyra/protocol.py | 1 - agkyra/syncer/setup.py | 29 +++++++++++++++++++++-------- agkyra/syncer/syncer.py | 5 ++--- agkyra/syncer/utils.py | 8 ++++++++ 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/agkyra/protocol.py b/agkyra/protocol.py index 23e7c8a..156b9fd 100644 --- a/agkyra/protocol.py +++ b/agkyra/protocol.py @@ -314,7 +314,6 @@ class WebSocketProtocol(WebSocket): pass syncer_settings = setup.SyncerSettings( - sync, self.settings['url'], self.settings['token'], self.settings['container'], self.settings['directory'], **kwargs) diff --git a/agkyra/syncer/setup.py b/agkyra/syncer/setup.py index 78e18c8..b35b024 100644 --- a/agkyra/syncer/setup.py +++ b/agkyra/syncer/setup.py @@ -20,6 +20,7 @@ import logging from agkyra.syncer.utils import join_path, ThreadSafeDict from agkyra.syncer.database import SqliteFileStateDB from agkyra.syncer.messaging import Messager +from agkyra.syncer import utils from kamaki.clients import ClientError @@ -39,17 +40,22 @@ DEFAULT_DBNAME = "syncer.db" DEFAULT_ACTION_MAX_WAIT = 10 DEFAULT_PITHOS_LIST_INTERVAL = 5 DEFAULT_CONNECTION_RETRY_LIMIT = 3 +INSTANCES_NAME = 'instances' thread_local_data = threading.local() +def get_instance(elems): + data = "".join(elems) + return utils.hash_string(data) + + class SyncerSettings(): - def __init__(self, instance, auth_url, auth_token, container, - local_root_path, + def __init__(self, auth_url, auth_token, container, local_root_path, *args, **kwargs): - self.auth_url = auth_url + self.auth_url = utils.normalize_standard_suffix(auth_url) self.auth_token = auth_token - self.container = container + self.container = utils.normalize_standard_suffix(container) self.ignore_ssl = kwargs.get("ignore_ssl", False) if self.ignore_ssl: @@ -65,16 +71,23 @@ class SyncerSettings(): self.settings_path = kwargs.get("agkyra_path", default_settings_path) self.create_dir(self.settings_path) - self.instance_path = join_path(self.settings_path, instance) + self.instances_path = join_path(self.settings_path, INSTANCES_NAME) + self.create_dir(self.instances_path) + + self.local_root_path = utils.normalize_local_suffix(local_root_path) + self.create_dir(self.local_root_path) + + self.user_id = self.endpoint.account + self.instance = get_instance( + [self.auth_url, self.user_id, + self.container, self.local_root_path]) + self.instance_path = join_path(self.instances_path, self.instance) self.create_dir(self.instance_path) self.dbname = kwargs.get("dbname", DEFAULT_DBNAME) self.full_dbname = join_path(self.instance_path, self.dbname) self.get_db(initialize=True) - self.local_root_path = local_root_path - self.create_dir(self.local_root_path) - self.cache_name = kwargs.get("cache_name", DEFAULT_CACHE_NAME) self.cache_path = join_path(self.local_root_path, self.cache_name) self.create_dir(self.cache_path) diff --git a/agkyra/syncer/syncer.py b/agkyra/syncer/syncer.py index 8bf4025..8d39117 100644 --- a/agkyra/syncer/syncer.py +++ b/agkyra/syncer/syncer.py @@ -406,9 +406,8 @@ class FileSyncer(object): # deleted = master_deleted.intersection(client_deleted) -def conf(instance, auth_url, auth_token, container, local_root_path, **kwargs): - settings = SyncerSettings(instance=instance, - auth_url=auth_url, +def conf(auth_url, auth_token, container, local_root_path, **kwargs): + settings = SyncerSettings(auth_url=auth_url, auth_token=auth_token, container=container, local_root_path=local_root_path, diff --git a/agkyra/syncer/utils.py b/agkyra/syncer/utils.py index 619aaf7..7e02fe6 100644 --- a/agkyra/syncer/utils.py +++ b/agkyra/syncer/utils.py @@ -42,6 +42,14 @@ def join_objname(prefix, filename): return prefix + filename +def normalize_standard_suffix(path): + return path.rstrip(OBJECT_DIRSEP) + OBJECT_DIRSEP + + +def normalize_local_suffix(path): + return path.rstrip(os.path.sep) + os.path.sep + + def hash_string(s): return hashlib.sha256(s).hexdigest() -- GitLab