3 # LADI Session Handler (ladish)
5 # Copyright (C) 2008, 2009 Nedko Arnaudov <nedko@arnaudov.name>
7 #*************************************************************************
8 # This file contains code of the commandline control app
9 #*************************************************************************
11 # LADI Session Handler is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # LADI Session Handler is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
23 # or write to the Free Software Foundation, Inc.,
24 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26 control_interface_name
= 'org.ladish.Control'
27 service_name
= 'org.ladish'
28 dbus_object_path
= "/org/ladish/Control"
33 from traceback
import print_exc
37 def bool_convert(str_value
):
38 if str_value
.lower() == "false":
41 if str_value
.lower() == "off":
44 if str_value
.lower() == "no":
50 if str_value
.lower() == "(null)":
53 return bool(str_value
)
55 def dbus_type_to_python_type(dbus_value
):
56 if type(dbus_value
) == dbus
.Boolean
:
57 return bool(dbus_value
)
58 if type(dbus_value
) == dbus
.Int32
or type(dbus_value
) == dbus
.UInt32
:
59 return int(dbus_value
)
62 def dbus_type_to_type_string(dbus_value
):
63 if type(dbus_value
) == dbus
.Boolean
:
65 if type(dbus_value
) == dbus
.Int32
:
67 if type(dbus_value
) == dbus
.UInt32
:
69 if type(dbus_value
) == dbus
.Byte
:
71 if type(dbus_value
) == dbus
.String
:
74 return None # throw exception here?
76 def dbus_typesig_to_type_string(type_char
):
77 type_char
= str(type_char
)
90 return None # throw exception here?
93 if len(sys
.argv
) == 1:
94 print "Usage: %s [command] [command] ..." % os
.path
.basename(sys
.argv
[0])
96 print " exit - exit ladish dbus service"
97 print " studios - list studios"
98 print " apps - list apps"
99 print " load <studioname> - load studio"
102 bus
= dbus
.SessionBus()
107 while index
< len(sys
.argv
):
108 arg
= sys
.argv
[index
]
112 lash
= bus
.get_object(service_name
, dbus_object_path
)
113 control_iface
= dbus
.Interface(lash
, control_interface_name
)
119 # we have deactivated the object and we need to get new connection if there are more commands
122 elif arg
== 'studios':
123 print "--- studio list"
124 for studio
in control_iface
.GetStudioList():
128 for app
in control_iface
.GetApplicationList():
131 if index
>= len(sys
.argv
):
132 print "load studio command requires studio name argument"
135 arg
= sys
.argv
[index
]
139 #open_options["option1"] = "asd"
140 #open_options["option2"] = True
142 control_iface
.LoadStudio(arg
, open_options
)
144 print "Unknown command '%s'" % arg
145 except dbus
.DBusException
, e
:
146 print "DBus exception: %s" % str(e
)
148 if __name__
== '__main__':