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 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")
115 bus
= dbus
.SessionBus()
121 while index
< len(sys
.argv
):
122 arg
= sys
.argv
[index
]
126 control_obj
= bus
.get_object(service_name
, control_object_path
)
127 control_iface
= dbus
.Interface(control_obj
, control_interface_name
)
133 # we have deactivated the object and we need to get new connection if there are more commands
137 print("--- studio list")
138 for studio
in control_iface
.GetStudioList():
140 mtime
= studio
[1]['Modification Time']
141 print('"%s" last modified on %s' % (name
, time
.ctime(mtime
)))
143 print("--- app list")
144 for app
in control_iface
.GetApplicationList():
147 print("--- studio load")
148 if index
>= len(sys
.argv
):
149 print("load studio command requires studio name argument")
152 arg
= sys
.argv
[index
]
156 #open_options["option1"] = "asd"
157 #open_options["option2"] = True
159 control_iface
.LoadStudio(arg
, open_options
)
161 print("--- studio delete")
162 if index
>= len(sys
.argv
):
163 print("delete studio command requires studio name argument")
166 arg
= sys
.argv
[index
]
169 control_iface
.DeleteStudio(arg
)
171 print("--- studio new")
173 if index
< len(sys
.argv
):
174 name
= sys
.argv
[index
]
177 control_iface
.NewStudio(name
)
178 elif arg
== 'sisloaded':
179 print("--- studio is loaded")
180 if control_iface
.IsStudioLoaded():
186 studio_obj
= bus
.get_object(service_name
, studio_object_path
)
187 studio_iface
= dbus
.Interface(studio_obj
, studio_interface_name
)
190 print("--- studio get name")
191 print("\"%s\"" % studio_iface
.GetName())
193 print("--- studio save")
195 elif arg
== 'sunload':
196 print("--- studio unload")
197 studio_iface
.Unload()
200 elif arg
== 'srename':
201 print("--- studio rename")
202 if index
>= len(sys
.argv
):
203 print("rename studio command requires studio name argument")
206 arg
= sys
.argv
[index
]
209 studio_iface
.Rename(arg
)
210 elif arg
== 'sstart':
211 print("--- studio start")
214 print("--- studio stop")
217 print("Unknown command '%s'" % arg
)
218 except dbus
.DBusException
, e
:
219 print("DBus exception: %s" % str(e
))
221 if __name__
== '__main__':