diff --git a/celigo/core.py b/celigo/core.py index 6006f55..e4c55e5 100644 --- a/celigo/core.py +++ b/celigo/core.py @@ -80,10 +80,8 @@ class BackupCeligo(object): def ensure_directories_exist(self, subdirs=None): """ Make the directory if it doesn't exist """ - if not subdirs: - subdirs = ('integrations', 'connections') - for subdir in subdirs: + L.info("Creating subdir: `%s`", subdir) _dir = os.path.join(self.data_dir, subdir) if not os.path.exists(_dir): os.makedirs(_dir) @@ -147,12 +145,6 @@ class BackupCeligo(object): L.info("Got all imports, writing now") for integration_id, integration in self.imports_cache.items(): - # Make sure the integration directories exist - base = "integrations/"+integration_id - subdirs = (base + "imports", base + "exports") - self.ensure_directories_exist(subdirs=subdirs) - - # save the files for flow in integration['flows']: self.save_flow(integration_id, flow, auto) @@ -190,6 +182,7 @@ class BackupCeligo(object): self.restore_to_celigo(action) del self.imports_cache[action] + def cache_import_remote(self, flow): """ Stores the import in self.imports_cache before write. @@ -198,7 +191,8 @@ class BackupCeligo(object): import_id = flow['_importId'] integration_id = flow['_integrationId'] import_conf = self._celigo_api_get( - "imports/{id}/distributed".format(id=import_id)) + "imports/{id}/distributed".format( + id=import_id)) self.imports_cache[integration_id]['flows'].append({ "name": flow_name, @@ -218,11 +212,16 @@ class BackupCeligo(object): flow_id = flow['id'] flow_conf = flow['configuration'] - filename = os.path.join(self.data_dir, - "integrations", - integration_id, - "imports", - "%s_%s.json" % (slugify(flow_name), flow_id)) + filedir = os.path.join(self.data_dir, + "integrations", + integration_id, + "imports") + + self.ensure_directories_exist((filedir,)) + + filename = os.path.join( + filedir, + "%s_%s.json" % (slugify(flow_name), flow_id)) write = True # By default, we prompt for overwrites