#!/usr/bin/python

import sys
try:
  import dbus
except ImportError:
  print "In order to use %s, you must have the DBUS python bindings installed. See http://www.freedesktop.org/wiki/Software/dbus for more information." % sys.argv[0]
  exit()


if len(sys.argv) < 2:
  print """Usage: %s <command>
  Where <command> is either 'magnify' or 'select_color'""" % sys.argv[0]
  exit(1)

try:
  bus = dbus.SessionBus()
except dbus.DBusException:
  print "Unable to connect to DBUS session bus. Is it currently running?"
  exit()

try:
  obj = bus.get_object('com.rephorm.elicit', '/com/rephorm/Elicit')
except dbus.DBusException:
  print "Unable to connect to elicit. It is possible that the .service file that came with elicit has not been installed correctly."
  exit()

command = sys.argv[1]
args = sys.argv[2:]

commands = {
    'magnify': obj.Magnify,
    'select_color': obj.SelectColor,
    'set_hex': obj.SetHex,
    'get_hex': obj.GetHex,
    }

if command in commands:
  ret = commands[command](*args)
  if ret is not None:
    print ret
else:
  print "Command '{command}' is unknown".format(command=command)

