From 662c8569fbbcde342fa3f61c55bd478680c0ec78 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 27 Oct 2016 14:15:07 +0200 Subject: [PATCH] only look for images in available volumes --- pandora_client/__init__.py | 80 ++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/pandora_client/__init__.py b/pandora_client/__init__.py index 1ded002..97d00e1 100755 --- a/pandora_client/__init__.py +++ b/pandora_client/__init__.py @@ -667,6 +667,7 @@ class Client(object): if not self.user: print("you need to login") return + documents = [] if args: data = [] @@ -694,6 +695,9 @@ class Client(object): files = [] info = [] else: + if not self.active_volumes(): + print("no volumes found, mount volumes and run again") + return # send empty list to get updated list of requested info/files/data post = {'info': {}} r = self.api.update(post) @@ -784,48 +788,47 @@ class Client(object): print(r) def _get_documents(self): - query = { - 'conditions': [ - {'key': 'filename', 'operator': '', 'value': value} - for value in DOCUMENT_FORMATS - ], - 'operator': '|' - } - n = self.api.findMedia({'query': query})['data']['items'] - if n: - o = 0 - chunk = 5000 - files = [] - while o < n: - files += self.api.findMedia({ - 'query': { + files = [] + for volume in self.active_volumes(): + query = { + 'conditions': [ + {'key': 'list', 'value': volume, 'operator': '=='}, + { 'conditions': [ {'key': 'filename', 'operator': '', 'value': value} for value in DOCUMENT_FORMATS ], 'operator': '|' - }, - 'keys': ['item', 'id', 'extension'], - 'range': [o, o+chunk] - })['data']['items'] - o += chunk - d = [] - o = 0 - while o < len(files): - d += self.api.findDocuments({ - 'query': { - 'conditions': [ - {'key': 'oshash', 'operator': '==', 'value': f['id']} - for f in files[o:o+chunk] - ], - 'operator': '|' - }, - 'keys': ['id', 'oshash', 'extension'], - 'range': [0, chunk] - })['data']['items'] - o += chunk - else: - d = [] + } + ], + 'operator': '&' + } + n = self.api.findMedia({'query': query})['data']['items'] + if n: + o = 0 + chunk = 5000 + while o < n: + files += self.api.findMedia({ + 'query': query, + 'keys': ['item', 'id', 'extension'], + 'range': [o, o+chunk] + })['data']['items'] + o += chunk + d = [] + o = 0 + while o < len(files): + d += self.api.findDocuments({ + 'query': { + 'conditions': [ + {'key': 'oshash', 'operator': '==', 'value': f['id']} + for f in files[o:o+chunk] + ], + 'operator': '|' + }, + 'keys': ['id', 'oshash', 'extension'], + 'range': [0, chunk] + })['data']['items'] + o += chunk available = set(f['oshash'] for f in d if f['extension'] in DOCUMENT_FORMATS) missing = [(f['id'], f['item']) for f in files @@ -847,7 +850,8 @@ class Client(object): return None def _add_document(self, f, item=None): - if f.split('.')[-1] not in DOCUMENT_FORMATS: + if f.split('.')[-1].lower() not in DOCUMENT_FORMATS: + print('skip, not a document', f) return False oshash = ox.oshash(f) did = self.find_document(oshash)