diff --git a/agkyra/protocol.py b/agkyra/protocol.py index 23e7c8a9f26cca04610a1ba25ce0b564bd78e2a6..156b9fd4a3df5eb8e454785c7c95dd652b0e6e05 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 78e18c876897e140e2a5261245e476eaf7f5e60b..b35b024ffcb813ee1a18e36d2f4e81e1e33d5692 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 8bf40259b9bd29feae000d6b247d50f6d28287fc..8d391179b02697a678aafd85c00ca476d3d0e147 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 619aaf79f244cd315464c750066f42dca52fc032..7e02fe6db67aa57e1fd84506a604bdfeba206819 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()