pandora_client/bin/pandora_client

72 lines
2.6 KiB
Text
Raw Normal View History

2010-11-18 14:46:19 +00:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
2012-02-21 09:45:27 +00:00
# GPL 2012
2010-11-18 14:46:19 +00:00
import os
import sys
from optparse import OptionParser
2012-02-21 09:45:27 +00:00
import json
2010-11-18 14:46:19 +00:00
root = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
if os.path.exists(os.path.join(root, 'pandora_client')):
sys.path.insert(0, root)
import pandora_client
if __name__ == '__main__':
usage = "usage: %prog [options] action"
parser = OptionParser(usage=usage)
2013-05-14 10:10:18 +00:00
parser.add_option('-v', '--version', dest='version', action="store_true")
2012-03-06 16:52:35 +00:00
parser.add_option('-c', '--config', dest='config',
help='config.json containing config', default='~/.ox/client.json', type='string')
parser.add_option('-d', '--debug', dest='debug',
help='output debug information', action="store_true")
2010-11-18 14:46:19 +00:00
(opts, args) = parser.parse_args()
2013-05-14 10:10:18 +00:00
if opts.version:
print "%s %s" % (os.path.basename(sys.argv[0]), pandora_client.__version__)
sys.exit(0)
2010-11-18 14:46:19 +00:00
opts.config = os.path.expanduser(opts.config)
2013-04-28 21:11:10 +00:00
if (args and args[0] not in ('config', 'client') and not os.path.exists(opts.config)):
print 'no configuration found, run "%s config" or specify one with -c' % sys.argv[0]
sys.exit(1)
if None in (opts.config, ):
2010-11-18 14:46:19 +00:00
parser.print_help()
2013-05-14 10:10:18 +00:00
sys.exit(1)
2010-11-18 14:46:19 +00:00
actions = ('scan', 'sync', 'upload', 'upload_frames', 'extract', 'clean', 'cmd', 'import_srt', 'upload_document', 'install_programs')
2012-02-21 09:45:27 +00:00
config = ('config', 'add_volume')
server = ('server', 'client')
if not args or args[0] not in actions + config + server:
parser.error('''you must specify a valid action.
\t\tknown actions are: %s
\t\tconfiguration: config, add_volume
\t\tdistributed encoding: server, client
for more information visit https://wiki.0x2620.org/wiki/pandora_client''' % ', '.join(actions))
2010-11-18 14:46:19 +00:00
action = args[0]
offline = action in config or action == 'client' or \
(action == 'extract' and len(args) == 2 and args[1] in ('offline', 'all'))
2013-04-28 21:11:10 +00:00
if action == 'client':
opts.config = {'url': '', 'cache': '~/.ox/client.sqlite', 'media-cache': '~/.ox/media'}
2012-02-21 09:45:27 +00:00
if action == 'config':
if not os.path.exists(opts.config):
with open(opts.config, 'w') as f:
json.dump({
"url": "",
"username": "",
"password": "",
"cache": "~/.ox/client.sqlite",
2012-04-19 15:47:51 +00:00
"media-cache": '~/.ox/media',
2012-02-21 09:45:27 +00:00
"volumes": {}
}, f, indent=2)
2012-03-06 16:52:35 +00:00
pandora_client.DEBUG = opts.debug
c = pandora_client.Client(opts.config, offline)
args = [a.decode('utf-8') if isinstance(a, str) else a for a in args[1:]]
getattr(c, action)(args)
2010-11-18 14:46:19 +00:00