2008-09-07 01:48:05 +03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
2009-08-01 00:01:50 +03:00
|
|
|
# LADI Session Handler (ladish)
|
2008-09-07 01:48:05 +03:00
|
|
|
#
|
2009-08-01 00:01:50 +03:00
|
|
|
# Copyright (C) 2008, 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
2008-09-07 01:48:05 +03:00
|
|
|
#
|
2009-08-01 00:01:50 +03:00
|
|
|
#*************************************************************************
|
|
|
|
# This file contains code of the commandline control app
|
|
|
|
#*************************************************************************
|
2008-09-07 01:48:05 +03:00
|
|
|
#
|
2009-08-01 00:01:50 +03:00
|
|
|
# LADI Session Handler is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# LADI Session Handler is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
# or write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
2008-09-07 01:48:05 +03:00
|
|
|
|
2009-07-28 00:44:15 +03:00
|
|
|
service_name = 'org.ladish'
|
2009-08-30 17:42:39 +03:00
|
|
|
|
|
|
|
control_object_path = "/org/ladish/Control"
|
|
|
|
studio_object_path = "/org/ladish/Studio"
|
|
|
|
|
|
|
|
control_interface_name = 'org.ladish.Control'
|
|
|
|
studio_interface_name = 'org.ladish.Studio'
|
2008-09-07 01:48:05 +03:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
from traceback import print_exc
|
|
|
|
|
|
|
|
import dbus
|
|
|
|
|
|
|
|
def bool_convert(str_value):
|
|
|
|
if str_value.lower() == "false":
|
|
|
|
return False
|
|
|
|
|
|
|
|
if str_value.lower() == "off":
|
|
|
|
return False
|
|
|
|
|
|
|
|
if str_value.lower() == "no":
|
|
|
|
return False
|
|
|
|
|
|
|
|
if str_value == "0":
|
|
|
|
return False
|
|
|
|
|
|
|
|
if str_value.lower() == "(null)":
|
|
|
|
return False
|
|
|
|
|
|
|
|
return bool(str_value)
|
|
|
|
|
|
|
|
def dbus_type_to_python_type(dbus_value):
|
|
|
|
if type(dbus_value) == dbus.Boolean:
|
|
|
|
return bool(dbus_value)
|
|
|
|
if type(dbus_value) == dbus.Int32 or type(dbus_value) == dbus.UInt32:
|
|
|
|
return int(dbus_value)
|
|
|
|
return dbus_value
|
|
|
|
|
|
|
|
def dbus_type_to_type_string(dbus_value):
|
|
|
|
if type(dbus_value) == dbus.Boolean:
|
|
|
|
return "bool"
|
|
|
|
if type(dbus_value) == dbus.Int32:
|
|
|
|
return "sint"
|
|
|
|
if type(dbus_value) == dbus.UInt32:
|
|
|
|
return "uint"
|
|
|
|
if type(dbus_value) == dbus.Byte:
|
|
|
|
return "char"
|
|
|
|
if type(dbus_value) == dbus.String:
|
|
|
|
return "str"
|
|
|
|
|
|
|
|
return None # throw exception here?
|
|
|
|
|
|
|
|
def dbus_typesig_to_type_string(type_char):
|
|
|
|
type_char = str(type_char)
|
|
|
|
if type_char == 'i':
|
|
|
|
return "sint"
|
|
|
|
if type_char == 'u':
|
|
|
|
return "uint"
|
|
|
|
if type_char == 'y':
|
|
|
|
return "char"
|
|
|
|
if type_char == 's':
|
|
|
|
return "str"
|
|
|
|
if type_char == 'b':
|
|
|
|
return "bool"
|
|
|
|
|
|
|
|
print 'shit'
|
|
|
|
return None # throw exception here?
|
|
|
|
|
|
|
|
def main():
|
|
|
|
if len(sys.argv) == 1:
|
|
|
|
print "Usage: %s [command] [command] ..." % os.path.basename(sys.argv[0])
|
|
|
|
print "Commands:"
|
2009-07-31 01:44:51 +03:00
|
|
|
print " exit - exit ladish dbus service"
|
2009-08-30 17:42:39 +03:00
|
|
|
print " slist - list studios"
|
|
|
|
print " alist - list apps"
|
|
|
|
print " sload <studioname> - load studio"
|
|
|
|
print " sdel <studioname> - delete studio"
|
|
|
|
print " snew [studioname] - new studio"
|
|
|
|
print " sisloaded - is studio loaded?"
|
|
|
|
print " sname - get studio name"
|
|
|
|
print " ssave - save studio"
|
|
|
|
print " sunload - unload studio"
|
|
|
|
print " srename <studioname> - rename studio"
|
2008-09-07 01:48:05 +03:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
bus = dbus.SessionBus()
|
2009-08-30 17:42:39 +03:00
|
|
|
control_obj = None
|
|
|
|
studio_obj = None
|
2008-09-07 01:48:05 +03:00
|
|
|
|
|
|
|
# check arguments
|
|
|
|
index = 1
|
|
|
|
while index < len(sys.argv):
|
|
|
|
arg = sys.argv[index]
|
|
|
|
index += 1
|
|
|
|
try:
|
2009-08-30 17:42:39 +03:00
|
|
|
if not control_obj:
|
|
|
|
control_obj = bus.get_object(service_name, control_object_path)
|
|
|
|
control_iface = dbus.Interface(control_obj, control_interface_name)
|
2008-09-07 01:48:05 +03:00
|
|
|
|
|
|
|
if arg == "exit":
|
|
|
|
print "--- exit"
|
|
|
|
control_iface.Exit()
|
|
|
|
time.sleep(1)
|
|
|
|
# we have deactivated the object and we need to get new connection if there are more commands
|
2009-08-30 17:42:39 +03:00
|
|
|
control_obj = None
|
2008-09-07 01:48:05 +03:00
|
|
|
control_iface = None
|
2009-08-30 17:42:39 +03:00
|
|
|
elif arg == 'slist':
|
2009-07-31 01:44:51 +03:00
|
|
|
print "--- studio list"
|
|
|
|
for studio in control_iface.GetStudioList():
|
2009-08-24 03:16:05 +03:00
|
|
|
name = studio[0]
|
|
|
|
mtime = studio[1]['Modification Time']
|
|
|
|
print '"%s" last modified on %s' % (name, time.ctime(mtime))
|
2009-08-30 17:42:39 +03:00
|
|
|
elif arg == 'alist':
|
2009-07-31 01:44:51 +03:00
|
|
|
print "--- app list"
|
|
|
|
for app in control_iface.GetApplicationList():
|
|
|
|
print app
|
2009-08-30 17:42:39 +03:00
|
|
|
elif arg == 'sload':
|
|
|
|
print "--- studio load"
|
2008-09-07 01:48:05 +03:00
|
|
|
if index >= len(sys.argv):
|
2009-07-31 01:44:51 +03:00
|
|
|
print "load studio command requires studio name argument"
|
2008-09-07 01:48:05 +03:00
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
arg = sys.argv[index]
|
|
|
|
index += 1
|
|
|
|
|
|
|
|
open_options = {}
|
|
|
|
#open_options["option1"] = "asd"
|
|
|
|
#open_options["option2"] = True
|
|
|
|
|
2009-07-31 01:44:51 +03:00
|
|
|
control_iface.LoadStudio(arg, open_options)
|
2009-08-30 17:42:39 +03:00
|
|
|
elif arg == 'sdel':
|
|
|
|
print "--- studio delete"
|
|
|
|
if index >= len(sys.argv):
|
|
|
|
print "delete studio command requires studio name argument"
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
arg = sys.argv[index]
|
|
|
|
index += 1
|
|
|
|
|
|
|
|
control_iface.DeleteStudio(arg)
|
|
|
|
elif arg == 'snew':
|
|
|
|
print "--- studio new"
|
|
|
|
name = ""
|
|
|
|
if index < len(sys.argv):
|
|
|
|
name = sys.argv[index]
|
|
|
|
index += 1
|
|
|
|
|
|
|
|
control_iface.NewStudio(name)
|
|
|
|
elif arg == 'sisloaded':
|
|
|
|
print "--- studio is loaded"
|
|
|
|
if control_iface.IsStudioLoaded():
|
|
|
|
print "yes"
|
|
|
|
else:
|
|
|
|
print "no"
|
2008-09-07 01:48:05 +03:00
|
|
|
else:
|
2009-08-30 17:42:39 +03:00
|
|
|
if not studio_obj:
|
|
|
|
studio_obj = bus.get_object(service_name, studio_object_path)
|
|
|
|
studio_iface = dbus.Interface(studio_obj, studio_interface_name)
|
|
|
|
|
|
|
|
if arg == 'sname':
|
|
|
|
print "--- studio get name"
|
|
|
|
print "\"%s\"" % studio_iface.GetName()
|
|
|
|
elif arg == 'ssave':
|
|
|
|
print "--- studio save"
|
|
|
|
studio_iface.Save()
|
|
|
|
elif arg == 'sunload':
|
|
|
|
print "--- studio unload"
|
|
|
|
studio_iface.Unload()
|
|
|
|
studio_obj = None
|
|
|
|
studio_iface = None
|
|
|
|
elif arg == 'srename':
|
|
|
|
print "--- studio rename"
|
|
|
|
if index >= len(sys.argv):
|
|
|
|
print "rename studio command requires studio name argument"
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
arg = sys.argv[index]
|
|
|
|
index += 1
|
|
|
|
|
|
|
|
studio_iface.Rename(arg)
|
|
|
|
else:
|
|
|
|
print "Unknown command '%s'" % arg
|
2008-09-07 01:48:05 +03:00
|
|
|
except dbus.DBusException, e:
|
|
|
|
print "DBus exception: %s" % str(e)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|