more options

This commit is contained in:
j 2011-08-23 21:20:16 +02:00
parent 0de6a5c1c5
commit bfe27b3848
2 changed files with 49 additions and 33 deletions

View file

@ -25,7 +25,7 @@ if __name__ == '__main__':
parser.print_help() parser.print_help()
sys.exit() sys.exit()
actions = ('scan', 'extract', 'sync', 'clean') actions = ('scan', 'sync', 'upload', 'extract', 'clean')
if not args or args[0] not in actions: if not args or args[0] not in actions:
parser.error('you must specify a valid action. \n\t\tknown actions are: %s' % ', '.join(actions)) parser.error('you must specify a valid action. \n\t\tknown actions are: %s' % ', '.join(actions))

View file

@ -264,40 +264,56 @@ class Client(object):
print 'sending info for new files', len(post['info']), offset, total print 'sending info for new files', len(post['info']), offset, total
r = self.api.update(post) r = self.api.update(post)
#send empty list to get updated list of requested info/files/data def upload(self):
post = {'info': {}} if not self.user:
r = self.api.update(post) print "you need to login"
return
conn, c = self._conn()
filenames = {} volumes = {}
for f in files['files']: for name in self._config['volumes']:
filenames[f['oshash']] = f['path'] path = self._config['volumes'][name]
path = os.path.normpath(path)
print 'uploading files', len(r['data']['file']) volumes[name] = {}
if r['data']['file']: volumes[name]['path'] = path
for oshash in r['data']['file']: if os.path.exists(path):
if oshash in filenames: volumes[name]['available'] = True
filename = filenames[oshash] else:
self.api.uploadData(os.path.join(prefix, filename), oshash) volumes[name]['available'] = False
print 'encoding videos', len(r['data']['data']) profile = self.api.encodingProfile()['data']['profile']
if r['data']['data']: for name in volumes:
for oshash in r['data']['data']: if volumes[name]['available']:
data = {} prefix = volumes[name]['path']
if oshash in filenames: files = self.files(prefix)
filename = filenames[oshash]
info = files['info'][oshash]
if not self.api.uploadVideo(os.path.join(prefix, filename),
data, profile, info):
if not self.signin():
print "failed to login again"
return
else: filenames = {}
pass for f in files['files']:
#print oshash, "missing" filenames[f['oshash']] = f['path']
else: #send empty list to get updated list of requested info/files/data
print "updating volume", name, "failed" post = {'info': {}}
print r r = self.api.update(post)
print 'uploading files', len(r['data']['file'])
if r['data']['file']:
for oshash in r['data']['file']:
if oshash in filenames:
filename = filenames[oshash]
self.api.uploadData(os.path.join(prefix, filename), oshash)
print 'encoding videos', len(r['data']['data'])
if r['data']['data']:
for oshash in r['data']['data']:
data = {}
if oshash in filenames:
filename = filenames[oshash]
info = files['info'][oshash]
if not self.api.uploadVideo(os.path.join(prefix, filename),
data, profile, info):
if not self.signin():
print "failed to login again"
return
def files(self, prefix): def files(self, prefix):
conn, c = self._conn() conn, c = self._conn()