3 # LADI Session Handler (ladish)
5 # Copyright (C) 2008, 2009, 2010 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 service_name
= 'org.ladish'
28 control_object_path
= "/org/ladish/Control"
29 studio_object_path
= "/org/ladish/Studio"
31 control_interface_name
= 'org.ladish.Control'
32 studio_interface_name
= 'org.ladish.Studio'
37 from traceback
import print_exc
41 def bool_convert(str_value
):
42 if str_value
.lower() == "false":
45 if str_value
.lower() == "off":
48 if str_value
.lower() == "no":
54 if str_value
.lower() == "(null)":
57 return bool(str_value
)
59 def dbus_type_to_python_type(dbus_value
):
60 if type(dbus_value
) == dbus
.Boolean
:
61 return bool(dbus_value
)
62 if type(dbus_value
) == dbus
.Int32
or type(dbus_value
) == dbus
.UInt32
:
63 return int(dbus_value
)
66 def dbus_type_to_type_string(dbus_value
):
67 if type(dbus_value
) == dbus
.Boolean
:
69 if type(dbus_value
) == dbus
.Int32
:
71 if type(dbus_value
) == dbus
.UInt32
:
73 if type(dbus_value
) == dbus
.Byte
:
75 if type(dbus_value
) == dbus
.String
:
78 return None # throw exception here?
80 def dbus_typesig_to_type_string(type_char
):
81 type_char
= str(type_char
)
93 print('unknown dbus typesig')
94 return None # throw exception here?
97 if len(sys
.argv
) == 1:
98 print("Usage: %s [command] [command] ..." % os
.path
.basename(sys
.argv
[0]))
100 print(" exit - exit ladish dbus service")
101 print(" slist - list studios")
102 print(" alist - list apps")
103 print(" sload <studioname> - load studio")
104 print(" sdel <studioname> - delete studio")
105 print(" snew [studioname] - new studio")
106 print(" sisloaded - is studio loaded?")
107 print(" sname - get studio name")
108 print(" ssave - save studio")
109 print(" sunload - unload studio")
110 print(" srename <studioname> - rename studio")
111 print(" sstart - start studio")
112 print(" sstop - stop studio")
113 print(" rtlist - list room templates")
114 print(" rtdel <roomtemplatename> - delete room template")
115 print(" rtnew <roomtemplatename> - create new room template")
116 print(" snewroom <rname> <rtname> - create new studio room")
117 print(" srlist - list studio rooms")
118 print(" sdelroom <rname> - delete studio room")
121 bus
= dbus
.SessionBus()
127 while index
< len(sys
.argv
):
128 arg
= sys
.argv
[index
]
132 control_obj
= bus
.get_object(service_name
, control_object_path
)
133 control_iface
= dbus
.Interface(control_obj
, control_interface_name
)
139 # we have deactivated the object and we need to get new connection if there are more commands
143 print("--- studio list")
144 for studio
in control_iface
.GetStudioList():
146 mtime
= studio
[1]['Modification Time']
147 print('"%s" last modified on %s' % (name
, time
.ctime(mtime
)))
149 print("--- app list")
150 for app
in control_iface
.GetApplicationList():
153 print("--- studio load")
154 if index
>= len(sys
.argv
):
155 print("load studio command requires studio name argument")
158 arg
= sys
.argv
[index
]
162 #open_options["option1"] = "asd"
163 #open_options["option2"] = True
165 control_iface
.LoadStudio(arg
, open_options
)
167 print("--- studio delete")
168 if index
>= len(sys
.argv
):
169 print("delete studio command requires studio name argument")
172 arg
= sys
.argv
[index
]
175 control_iface
.DeleteStudio(arg
)
177 print("--- studio new")
179 if index
< len(sys
.argv
):
180 name
= sys
.argv
[index
]
183 control_iface
.NewStudio(name
)
184 elif arg
== 'sisloaded':
185 print("--- studio is loaded")
186 if control_iface
.IsStudioLoaded():
190 elif arg
== 'rtlist':
191 print("--- list room templates")
192 for studio
in control_iface
.GetRoomTemplateList():
196 print("--- create new room template")
197 if index
>= len(sys
.argv
):
198 print("create new room template command requires room template name argument")
201 arg
= sys
.argv
[index
]
204 control_iface
.CreateRoomTemplate(arg
)
206 print("--- delete room template")
207 if index
>= len(sys
.argv
):
208 print("delete room template command requires room template name argument")
211 arg
= sys
.argv
[index
]
214 control_iface
.DeleteRoomTemplate(arg
)
217 studio_obj
= bus
.get_object(service_name
, studio_object_path
)
218 studio_iface
= dbus
.Interface(studio_obj
, studio_interface_name
)
221 print("--- studio get name")
222 print("\"%s\"" % studio_iface
.GetName())
224 print("--- studio save")
226 elif arg
== 'sunload':
227 print("--- studio unload")
228 studio_iface
.Unload()
231 elif arg
== 'srename':
232 print("--- studio rename")
233 if index
>= len(sys
.argv
):
234 print("rename studio command requires studio name argument")
237 arg
= sys
.argv
[index
]
240 studio_iface
.Rename(arg
)
241 elif arg
== 'sstart':
242 print("--- studio start")
245 print("--- studio stop")
247 elif arg
== 'snewroom':
248 print("--- create new studio room")
249 if index
+ 1 >= len(sys
.argv
):
250 print("creation of studio room requires room name and room template name arguments")
253 room_name
= sys
.argv
[index
]
255 room_template_name
= sys
.argv
[index
]
258 studio_iface
.CreateRoom(room_name
, room_template_name
)
259 elif arg
== 'srlist':
260 print("--- list studio rooms")
261 for room
in studio_iface
.GetRoomList():
264 name
= room
[1]["name"]
265 if room
[1].has_key("template"):
266 template
= str(room
[1]["template"])
271 print('"%s" from template "%s" (%s)' % (name
, template
, opath
))
273 print('"%s" (%s)' % (name
, opath
))
274 elif arg
== 'sdelroom':
275 print("--- delete studio room")
276 if index
>= len(sys
.argv
):
277 print("delete studio room command requires room name argument")
280 arg
= sys
.argv
[index
]
283 studio_iface
.DeleteRoom(arg
)
285 print("Unknown command '%s'" % arg
)
286 except dbus
.DBusException
, e
:
287 print("DBus exception: %s" % str(e
))
289 if __name__
== '__main__':