only scan/sync active volumes

This commit is contained in:
j 2012-11-01 12:53:02 +01:00
parent 9e8b14bd7f
commit 0ce16b5c2b

View file

@ -303,11 +303,20 @@ class Client(object):
self._config['volumes'][name] = path self._config['volumes'][name] = path
def scan(self, args): def active_volumes(self):
print "checking for new files ..." volumes = {}
for name in sorted(self._config['volumes']): for name in sorted(self._config['volumes']):
path = self._config['volumes'][name] path = self._config['volumes'][name]
path = os.path.normpath(path) path = os.path.normpath(path)
if os.path.exists(path):
volumes[name] = path
return volumes
def scan(self, args):
print "checking for new files ..."
volumes = self.active_volumes()
for name in sorted(volumes):
path = volumes[name]
conn, c = self._conn() conn, c = self._conn()
c.execute('SELECT path FROM file WHERE path LIKE ? AND deleted < 0', ["%s%%"%path]) c.execute('SELECT path FROM file WHERE path LIKE ? AND deleted < 0', ["%s%%"%path])
known_files = [r[0] for r in c.fetchall()] known_files = [r[0] for r in c.fetchall()]
@ -383,55 +392,43 @@ class Client(object):
return return
conn, c = self._conn() conn, c = self._conn()
volumes = {} volumes = self.active_volumes()
for name in sorted(self._config['volumes']):
path = self._config['volumes'][name]
path = os.path.normpath(path)
volumes[name] = {}
volumes[name]['path'] = path
if os.path.exists(path):
volumes[name]['available'] = True
else:
volumes[name]['available'] = False
for name in sorted(volumes): for name in sorted(volumes):
if volumes[name]['available']: prefix = volumes[name]
prefix = volumes[name]['path'] files = self.files(prefix)
files = self.files(prefix) post = {}
post = {} post['files'] = files['files']
post['files'] = files['files'] post['volume'] = name
post['volume'] = name print 'sending list of files in %s (%s total)' % (name, len(post['files']))
print 'sending list of files in %s (%s total)' % (name, len(post['files'])) r = self.api.update(post)
r = self.api.update(post) if r['status']['code'] == 200:
if r['status']['code'] == 200: #backend works on update request asyncronously, wait for it to finish
#backend works on update request asyncronously, wait for it to finish if 'taskId' in r['data']:
if 'taskId' in r['data']: t = self.api.taskStatus(task_id=r['data']['taskId'])
print 'waiting for server ...'
while t['data']['status'] == 'PENDING':
time.sleep(5)
t = self.api.taskStatus(task_id=r['data']['taskId']) t = self.api.taskStatus(task_id=r['data']['taskId'])
print 'waiting for server ...' #send empty list to get updated list of requested info/files/data
while t['data']['status'] == 'PENDING': post = {'info': {}}
time.sleep(5) r = self.api.update(post)
t = self.api.taskStatus(task_id=r['data']['taskId'])
#send empty list to get updated list of requested info/files/data
post = {'info': {}}
r = self.api.update(post)
if r['data']['info']: if r['data']['info']:
info = r['data']['info'] info = r['data']['info']
max_info = 100 max_info = 100
total = len(info) total = len(info)
sent = 0 sent = 0
for offset in range(0, total, max_info): for offset in range(0, total, max_info):
post = {'info': {}, 'upload': True} post = {'info': {}, 'upload': True}
for oshash in info[offset:offset+max_info]: for oshash in info[offset:offset+max_info]:
_info = self.info(oshash) _info = self.info(oshash)
if _info: if _info:
post['info'][oshash] = _info post['info'][oshash] = _info
if len(post['info']): if len(post['info']):
r = self.api.update(post) r = self.api.update(post)
sent += len(post['info']) sent += len(post['info'])
if sent: if sent:
print 'sent info for %s files' % sent print 'sent info for %s files' % sent
if not 'data' in r: if not 'data' in r:
print r print r