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
)
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"
113 bus
= dbus
.SessionBus()
119 while index
< len(sys
.argv
):
120 arg
= sys
.argv
[index
]
124 control_obj
= bus
.get_object(service_name
, control_object_path
)
125 control_iface
= dbus
.Interface(control_obj
, control_interface_name
)
131 # we have deactivated the object and we need to get new connection if there are more commands
135 print "--- studio list"
136 for studio
in control_iface
.GetStudioList():
138 mtime
= studio
[1]['Modification Time']
139 print '"%s" last modified on %s' % (name
, time
.ctime(mtime
))
142 for app
in control_iface
.GetApplicationList():
145 print "--- studio load"
146 if index
>= len(sys
.argv
):
147 print "load studio command requires studio name argument"
150 arg
= sys
.argv
[index
]
154 #open_options["option1"] = "asd"
155 #open_options["option2"] = True
157 control_iface
.LoadStudio(arg
, open_options
)
159 print "--- studio delete"
160 if index
>= len(sys
.argv
):
161 print "delete studio command requires studio name argument"
164 arg
= sys
.argv
[index
]
167 control_iface
.DeleteStudio(arg
)
169 print "--- studio new"
171 if index
< len(sys
.argv
):
172 name
= sys
.argv
[index
]
175 control_iface
.NewStudio(name
)
176 elif arg
== 'sisloaded':
177 print "--- studio is loaded"
178 if control_iface
.IsStudioLoaded():
184 studio_obj
= bus
.get_object(service_name
, studio_object_path
)
185 studio_iface
= dbus
.Interface(studio_obj
, studio_interface_name
)
188 print "--- studio get name"
189 print "\"%s\"" % studio_iface
.GetName()
191 print "--- studio save"
193 elif arg
== 'sunload':
194 print "--- studio unload"
195 studio_iface
.Unload()
198 elif arg
== 'srename':
199 print "--- studio rename"
200 if index
>= len(sys
.argv
):
201 print "rename studio command requires studio name argument"
204 arg
= sys
.argv
[index
]
207 studio_iface
.Rename(arg
)
209 print "Unknown command '%s'" % arg
210 except dbus
.DBusException
, e
:
211 print "DBus exception: %s" % str(e
)
213 if __name__
== '__main__':