add upload_document action

This commit is contained in:
j 2014-01-03 01:09:21 +05:30
parent c7b396d004
commit 60622ee843
2 changed files with 38 additions and 2 deletions

View file

@ -37,7 +37,7 @@ if __name__ == '__main__':
parser.print_help() parser.print_help()
sys.exit(1) sys.exit(1)
actions = ('scan', 'sync', 'upload', 'upload_frames', 'extract', 'clean', 'cmd', 'import_srt') actions = ('scan', 'sync', 'upload', 'upload_frames', 'extract', 'clean', 'cmd', 'import_srt', 'upload_document')
config = ('config', 'add_volume') config = ('config', 'add_volume')
server = ('server', 'client') server = ('server', 'client')
if not args or args[0] not in actions + config + server: if not args or args[0] not in actions + config + server:

View file

@ -724,6 +724,42 @@ class Client(object):
if r.get('status', {}).get('code') != 200: if r.get('status', {}).get('code') != 200:
print r print r
def upload_document(self, args):
if not self.user:
print "you need to login"
return
conn, c = self._conn()
for f in args:
if f.split('.')[-1] not in ('jpg', 'pdf', 'png'):
print 'unsupported format', f
continue
url = '%supload/document/' % self._config['url']
r = self.api.upload_chunks(url, f, {
'filename': os.path.basename(f)
})
'''
if r:
oshash = ox.oshash(f)
r = self.api.findDocuments({
"keys": ['id'],
"query": {
"conditions": [{"key": 'oshash', "value": oshash, "operator": '=='}],
"operator": '&'
}
})
did = r['data']['items'][0]['id']
if description:
r = api.editDocument({
'id': did,
'description': descriptoin
})
if item:
r = api.addDocument({
'id': did,
'item': item
})
'''
def files(self, prefix): def files(self, prefix):
if not prefix.endswith('/'): if not prefix.endswith('/'):
prefix += '/' prefix += '/'