#!/usr/bin/env python
#
# Autogenerated by Thrift Compiler (0.9.0-dev)
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#
#  options string: py:slots,dynamic
#

import sys
import pprint
from urlparse import urlparse
from thrift.transport import TTransport
from thrift.transport import TSocket
from thrift.transport import THttpClient
from thrift.protocol import TBinaryProtocol

import Pyload
from ttypes import *

if len(sys.argv) <= 1 or sys.argv[1] == '--help':
  print ''
  print 'Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
  print ''
  print 'Functions:'
  print '  string getConfigValue(string category, string option, string section)'
  print '  void setConfigValue(string category, string option, string value, string section)'
  print '   getConfig()'
  print '   getPluginConfig()'
  print '  void pauseServer()'
  print '  void unpauseServer()'
  print '  bool togglePause()'
  print '  ServerStatus statusServer()'
  print '  i64 freeSpace()'
  print '  string getServerVersion()'
  print '  void kill()'
  print '  void restart()'
  print '   getLog(i32 offset)'
  print '  bool isTimeDownload()'
  print '  bool isTimeReconnect()'
  print '  bool toggleReconnect()'
  print '   generatePackages(LinkList links)'
  print '   checkURLs(LinkList urls)'
  print '   parseURLs(string html, string url)'
  print '  OnlineCheck checkOnlineStatus(LinkList urls)'
  print '  OnlineCheck checkOnlineStatusContainer(LinkList urls, string filename, string data)'
  print '  OnlineCheck pollResults(ResultID rid)'
  print '   statusDownloads()'
  print '  PackageData getPackageData(PackageID pid)'
  print '  PackageData getPackageInfo(PackageID pid)'
  print '  FileData getFileData(FileID fid)'
  print '   getQueue()'
  print '   getCollector()'
  print '   getQueueData()'
  print '   getCollectorData()'
  print '   getPackageOrder(Destination destination)'
  print '   getFileOrder(PackageID pid)'
  print '   generateAndAddPackages(LinkList links, Destination dest)'
  print '  PackageID addPackage(string name, LinkList links, Destination dest)'
  print '  void addFiles(PackageID pid, LinkList links)'
  print '  void uploadContainer(string filename, string data)'
  print '  void deleteFiles( fids)'
  print '  void deletePackages( pids)'
  print '  void pushToQueue(PackageID pid)'
  print '  void pullFromQueue(PackageID pid)'
  print '  void restartPackage(PackageID pid)'
  print '  void restartFile(FileID fid)'
  print '  void recheckPackage(PackageID pid)'
  print '  void stopAllDownloads()'
  print '  void stopDownloads( fids)'
  print '  void setPackageName(PackageID pid, string name)'
  print '  void movePackage(Destination destination, PackageID pid)'
  print '  void moveFiles( fids, PackageID pid)'
  print '  void orderPackage(PackageID pid, i16 position)'
  print '  void orderFile(FileID fid, i16 position)'
  print '  void setPackageData(PackageID pid,  data)'
  print '   deleteFinished()'
  print '  void restartFailed()'
  print '   getEvents(string uuid)'
  print '   getAccounts(bool refresh)'
  print '   getAccountTypes()'
  print '  void updateAccount(PluginName plugin, string account, string password,  options)'
  print '  void removeAccount(PluginName plugin, string account)'
  print '  bool login(string username, string password)'
  print '  UserData getUserData(string username, string password)'
  print '   getAllUserData()'
  print '   getServices()'
  print '  bool hasService(PluginName plugin, string func)'
  print '  string call(ServiceCall info)'
  print '   getAllInfo()'
  print '   getInfoByPlugin(PluginName plugin)'
  print '  bool isCaptchaWaiting()'
  print '  CaptchaTask getCaptchaTask(bool exclusive)'
  print '  string getCaptchaTaskStatus(TaskID tid)'
  print '  void setCaptchaResult(TaskID tid, string result)'
  print ''
  sys.exit(0)

pp = pprint.PrettyPrinter(indent = 2)
host = 'localhost'
port = 9090
uri = ''
framed = False
http = False
argi = 1

if sys.argv[argi] == '-h':
  parts = sys.argv[argi+1].split(':')
  host = parts[0]
  if len(parts) > 1:
    port = int(parts[1])
  argi += 2

if sys.argv[argi] == '-u':
  url = urlparse(sys.argv[argi+1])
  parts = url[1].split(':')
  host = parts[0]
  if len(parts) > 1:
    port = int(parts[1])
  else:
    port = 80
  uri = url[2]
  if url[4]:
    uri += '?%s' % url[4]
  http = True
  argi += 2

if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
  framed = True
  argi += 1

cmd = sys.argv[argi]
args = sys.argv[argi+1:]

if http:
  transport = THttpClient.THttpClient(host, port, uri)
else:
  socket = TSocket.TSocket(host, port)
  if framed:
    transport = TTransport.TFramedTransport(socket)
  else:
    transport = TTransport.TBufferedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = Pyload.Client(protocol)
transport.open()

if cmd == 'getConfigValue':
  if len(args) != 3:
    print 'getConfigValue requires 3 args'
    sys.exit(1)
  pp.pprint(client.getConfigValue(args[0],args[1],args[2],))

elif cmd == 'setConfigValue':
  if len(args) != 4:
    print 'setConfigValue requires 4 args'
    sys.exit(1)
  pp.pprint(client.setConfigValue(args[0],args[1],args[2],args[3],))

elif cmd == 'getConfig':
  if len(args) != 0:
    print 'getConfig requires 0 args'
    sys.exit(1)
  pp.pprint(client.getConfig())

elif cmd == 'getPluginConfig':
  if len(args) != 0:
    print 'getPluginConfig requires 0 args'
    sys.exit(1)
  pp.pprint(client.getPluginConfig())

elif cmd == 'pauseServer':
  if len(args) != 0:
    print 'pauseServer requires 0 args'
    sys.exit(1)
  pp.pprint(client.pauseServer())

elif cmd == 'unpauseServer':
  if len(args) != 0:
    print 'unpauseServer requires 0 args'
    sys.exit(1)
  pp.pprint(client.unpauseServer())

elif cmd == 'togglePause':
  if len(args) != 0:
    print 'togglePause requires 0 args'
    sys.exit(1)
  pp.pprint(client.togglePause())

elif cmd == 'statusServer':
  if len(args) != 0:
    print 'statusServer requires 0 args'
    sys.exit(1)
  pp.pprint(client.statusServer())

elif cmd == 'freeSpace':
  if len(args) != 0:
    print 'freeSpace requires 0 args'
    sys.exit(1)
  pp.pprint(client.freeSpace())

elif cmd == 'getServerVersion':
  if len(args) != 0:
    print 'getServerVersion requires 0 args'
    sys.exit(1)
  pp.pprint(client.getServerVersion())

elif cmd == 'kill':
  if len(args) != 0:
    print 'kill requires 0 args'
    sys.exit(1)
  pp.pprint(client.kill())

elif cmd == 'restart':
  if len(args) != 0:
    print 'restart requires 0 args'
    sys.exit(1)
  pp.pprint(client.restart())

elif cmd == 'getLog':
  if len(args) != 1:
    print 'getLog requires 1 args'
    sys.exit(1)
  pp.pprint(client.getLog(eval(args[0]),))

elif cmd == 'isTimeDownload':
  if len(args) != 0:
    print 'isTimeDownload requires 0 args'
    sys.exit(1)
  pp.pprint(client.isTimeDownload())

elif cmd == 'isTimeReconnect':
  if len(args) != 0:
    print 'isTimeReconnect requires 0 args'
    sys.exit(1)
  pp.pprint(client.isTimeReconnect())

elif cmd == 'toggleReconnect':
  if len(args) != 0:
    print 'toggleReconnect requires 0 args'
    sys.exit(1)
  pp.pprint(client.toggleReconnect())

elif cmd == 'generatePackages':
  if len(args) != 1:
    print 'generatePackages requires 1 args'
    sys.exit(1)
  pp.pprint(client.generatePackages(eval(args[0]),))

elif cmd == 'checkURLs':
  if len(args) != 1:
    print 'checkURLs requires 1 args'
    sys.exit(1)
  pp.pprint(client.checkURLs(eval(args[0]),))

elif cmd == 'parseURLs':
  if len(args) != 2:
    print 'parseURLs requires 2 args'
    sys.exit(1)
  pp.pprint(client.parseURLs(args[0],args[1],))

elif cmd == 'checkOnlineStatus':
  if len(args) != 1:
    print 'checkOnlineStatus requires 1 args'
    sys.exit(1)
  pp.pprint(client.checkOnlineStatus(eval(args[0]),))

elif cmd == 'checkOnlineStatusContainer':
  if len(args) != 3:
    print 'checkOnlineStatusContainer requires 3 args'
    sys.exit(1)
  pp.pprint(client.checkOnlineStatusContainer(eval(args[0]),args[1],args[2],))

elif cmd == 'pollResults':
  if len(args) != 1:
    print 'pollResults requires 1 args'
    sys.exit(1)
  pp.pprint(client.pollResults(eval(args[0]),))

elif cmd == 'statusDownloads':
  if len(args) != 0:
    print 'statusDownloads requires 0 args'
    sys.exit(1)
  pp.pprint(client.statusDownloads())

elif cmd == 'getPackageData':
  if len(args) != 1:
    print 'getPackageData requires 1 args'
    sys.exit(1)
  pp.pprint(client.getPackageData(eval(args[0]),))

elif cmd == 'getPackageInfo':
  if len(args) != 1:
    print 'getPackageInfo requires 1 args'
    sys.exit(1)
  pp.pprint(client.getPackageInfo(eval(args[0]),))

elif cmd == 'getFileData':
  if len(args) != 1:
    print 'getFileData requires 1 args'
    sys.exit(1)
  pp.pprint(client.getFileData(eval(args[0]),))

elif cmd == 'getQueue':
  if len(args) != 0:
    print 'getQueue requires 0 args'
    sys.exit(1)
  pp.pprint(client.getQueue())

elif cmd == 'getCollector':
  if len(args) != 0:
    print 'getCollector requires 0 args'
    sys.exit(1)
  pp.pprint(client.getCollector())

elif cmd == 'getQueueData':
  if len(args) != 0:
    print 'getQueueData requires 0 args'
    sys.exit(1)
  pp.pprint(client.getQueueData())

elif cmd == 'getCollectorData':
  if len(args) != 0:
    print 'getCollectorData requires 0 args'
    sys.exit(1)
  pp.pprint(client.getCollectorData())

elif cmd == 'getPackageOrder':
  if len(args) != 1:
    print 'getPackageOrder requires 1 args'
    sys.exit(1)
  pp.pprint(client.getPackageOrder(eval(args[0]),))

elif cmd == 'getFileOrder':
  if len(args) != 1:
    print 'getFileOrder requires 1 args'
    sys.exit(1)
  pp.pprint(client.getFileOrder(eval(args[0]),))

elif cmd == 'generateAndAddPackages':
  if len(args) != 2:
    print 'generateAndAddPackages requires 2 args'
    sys.exit(1)
  pp.pprint(client.generateAndAddPackages(eval(args[0]),eval(args[1]),))

elif cmd == 'addPackage':
  if len(args) != 3:
    print 'addPackage requires 3 args'
    sys.exit(1)
  pp.pprint(client.addPackage(args[0],eval(args[1]),eval(args[2]),))

elif cmd == 'addFiles':
  if len(args) != 2:
    print 'addFiles requires 2 args'
    sys.exit(1)
  pp.pprint(client.addFiles(eval(args[0]),eval(args[1]),))

elif cmd == 'uploadContainer':
  if len(args) != 2:
    print 'uploadContainer requires 2 args'
    sys.exit(1)
  pp.pprint(client.uploadContainer(args[0],args[1],))

elif cmd == 'deleteFiles':
  if len(args) != 1:
    print 'deleteFiles requires 1 args'
    sys.exit(1)
  pp.pprint(client.deleteFiles(eval(args[0]),))

elif cmd == 'deletePackages':
  if len(args) != 1:
    print 'deletePackages requires 1 args'
    sys.exit(1)
  pp.pprint(client.deletePackages(eval(args[0]),))

elif cmd == 'pushToQueue':
  if len(args) != 1:
    print 'pushToQueue requires 1 args'
    sys.exit(1)
  pp.pprint(client.pushToQueue(eval(args[0]),))

elif cmd == 'pullFromQueue':
  if len(args) != 1:
    print 'pullFromQueue requires 1 args'
    sys.exit(1)
  pp.pprint(client.pullFromQueue(eval(args[0]),))

elif cmd == 'restartPackage':
  if len(args) != 1:
    print 'restartPackage requires 1 args'
    sys.exit(1)
  pp.pprint(client.restartPackage(eval(args[0]),))

elif cmd == 'restartFile':
  if len(args) != 1:
    print 'restartFile requires 1 args'
    sys.exit(1)
  pp.pprint(client.restartFile(eval(args[0]),))

elif cmd == 'recheckPackage':
  if len(args) != 1:
    print 'recheckPackage requires 1 args'
    sys.exit(1)
  pp.pprint(client.recheckPackage(eval(args[0]),))

elif cmd == 'stopAllDownloads':
  if len(args) != 0:
    print 'stopAllDownloads requires 0 args'
    sys.exit(1)
  pp.pprint(client.stopAllDownloads())

elif cmd == 'stopDownloads':
  if len(args) != 1:
    print 'stopDownloads requires 1 args'
    sys.exit(1)
  pp.pprint(client.stopDownloads(eval(args[0]),))

elif cmd == 'setPackageName':
  if len(args) != 2:
    print 'setPackageName requires 2 args'
    sys.exit(1)
  pp.pprint(client.setPackageName(eval(args[0]),args[1],))

elif cmd == 'movePackage':
  if len(args) != 2:
    print 'movePackage requires 2 args'
    sys.exit(1)
  pp.pprint(client.movePackage(eval(args[0]),eval(args[1]),))

elif cmd == 'moveFiles':
  if len(args) != 2:
    print 'moveFiles requires 2 args'
    sys.exit(1)
  pp.pprint(client.moveFiles(eval(args[0]),eval(args[1]),))

elif cmd == 'orderPackage':
  if len(args) != 2:
    print 'orderPackage requires 2 args'
    sys.exit(1)
  pp.pprint(client.orderPackage(eval(args[0]),eval(args[1]),))

elif cmd == 'orderFile':
  if len(args) != 2:
    print 'orderFile requires 2 args'
    sys.exit(1)
  pp.pprint(client.orderFile(eval(args[0]),eval(args[1]),))

elif cmd == 'setPackageData':
  if len(args) != 2:
    print 'setPackageData requires 2 args'
    sys.exit(1)
  pp.pprint(client.setPackageData(eval(args[0]),eval(args[1]),))

elif cmd == 'deleteFinished':
  if len(args) != 0:
    print 'deleteFinished requires 0 args'
    sys.exit(1)
  pp.pprint(client.deleteFinished())

elif cmd == 'restartFailed':
  if len(args) != 0:
    print 'restartFailed requires 0 args'
    sys.exit(1)
  pp.pprint(client.restartFailed())

elif cmd == 'getEvents':
  if len(args) != 1:
    print 'getEvents requires 1 args'
    sys.exit(1)
  pp.pprint(client.getEvents(args[0],))

elif cmd == 'getAccounts':
  if len(args) != 1:
    print 'getAccounts requires 1 args'
    sys.exit(1)
  pp.pprint(client.getAccounts(eval(args[0]),))

elif cmd == 'getAccountTypes':
  if len(args) != 0:
    print 'getAccountTypes requires 0 args'
    sys.exit(1)
  pp.pprint(client.getAccountTypes())

elif cmd == 'updateAccount':
  if len(args) != 4:
    print 'updateAccount requires 4 args'
    sys.exit(1)
  pp.pprint(client.updateAccount(eval(args[0]),args[1],args[2],eval(args[3]),))

elif cmd == 'removeAccount':
  if len(args) != 2:
    print 'removeAccount requires 2 args'
    sys.exit(1)
  pp.pprint(client.removeAccount(eval(args[0]),args[1],))

elif cmd == 'login':
  if len(args) != 2:
    print 'login requires 2 args'
    sys.exit(1)
  pp.pprint(client.login(args[0],args[1],))

elif cmd == 'getUserData':
  if len(args) != 2:
    print 'getUserData requires 2 args'
    sys.exit(1)
  pp.pprint(client.getUserData(args[0],args[1],))

elif cmd == 'getAllUserData':
  if len(args) != 0:
    print 'getAllUserData requires 0 args'
    sys.exit(1)
  pp.pprint(client.getAllUserData())

elif cmd == 'getServices':
  if len(args) != 0:
    print 'getServices requires 0 args'
    sys.exit(1)
  pp.pprint(client.getServices())

elif cmd == 'hasService':
  if len(args) != 2:
    print 'hasService requires 2 args'
    sys.exit(1)
  pp.pprint(client.hasService(eval(args[0]),args[1],))

elif cmd == 'call':
  if len(args) != 1:
    print 'call requires 1 args'
    sys.exit(1)
  pp.pprint(client.call(eval(args[0]),))

elif cmd == 'getAllInfo':
  if len(args) != 0:
    print 'getAllInfo requires 0 args'
    sys.exit(1)
  pp.pprint(client.getAllInfo())

elif cmd == 'getInfoByPlugin':
  if len(args) != 1:
    print 'getInfoByPlugin requires 1 args'
    sys.exit(1)
  pp.pprint(client.getInfoByPlugin(eval(args[0]),))

elif cmd == 'isCaptchaWaiting':
  if len(args) != 0:
    print 'isCaptchaWaiting requires 0 args'
    sys.exit(1)
  pp.pprint(client.isCaptchaWaiting())

elif cmd == 'getCaptchaTask':
  if len(args) != 1:
    print 'getCaptchaTask requires 1 args'
    sys.exit(1)
  pp.pprint(client.getCaptchaTask(eval(args[0]),))

elif cmd == 'getCaptchaTaskStatus':
  if len(args) != 1:
    print 'getCaptchaTaskStatus requires 1 args'
    sys.exit(1)
  pp.pprint(client.getCaptchaTaskStatus(eval(args[0]),))

elif cmd == 'setCaptchaResult':
  if len(args) != 2:
    print 'setCaptchaResult requires 2 args'
    sys.exit(1)
  pp.pprint(client.setCaptchaResult(eval(args[0]),args[1],))

else:
  print 'Unrecognized method %s' % cmd
  sys.exit(1)

transport.close()
