4 # Copyright (C) 2008 Nedko Arnaudov <nedko@arnaudov.name>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 control_interface_name
= 'org.ladish.Control'
21 service_name
= 'org.ladish'
26 from traceback
import print_exc
30 def bool_convert(str_value
):
31 if str_value
.lower() == "false":
34 if str_value
.lower() == "off":
37 if str_value
.lower() == "no":
43 if str_value
.lower() == "(null)":
46 return bool(str_value
)
48 def dbus_type_to_python_type(dbus_value
):
49 if type(dbus_value
) == dbus
.Boolean
:
50 return bool(dbus_value
)
51 if type(dbus_value
) == dbus
.Int32
or type(dbus_value
) == dbus
.UInt32
:
52 return int(dbus_value
)
55 def dbus_type_to_type_string(dbus_value
):
56 if type(dbus_value
) == dbus
.Boolean
:
58 if type(dbus_value
) == dbus
.Int32
:
60 if type(dbus_value
) == dbus
.UInt32
:
62 if type(dbus_value
) == dbus
.Byte
:
64 if type(dbus_value
) == dbus
.String
:
67 return None # throw exception here?
69 def dbus_typesig_to_type_string(type_char
):
70 type_char
= str(type_char
)
83 return None # throw exception here?
86 if len(sys
.argv
) == 1:
87 print "Usage: %s [command] [command] ..." % os
.path
.basename(sys
.argv
[0])
89 print " exit - exit lash dbus service"
90 print " list - list projects"
91 print " open <projectname> - open project"
92 print " save - save all open projects"
93 print " close - close all open projects"
96 bus
= dbus
.SessionBus()
101 while index
< len(sys
.argv
):
102 arg
= sys
.argv
[index
]
106 lash
= bus
.get_object(service_name
, "/")
107 control_iface
= dbus
.Interface(lash
, control_interface_name
)
113 # we have deactivated the object and we need to get new connection if there are more commands
117 print "--- projects list"
118 projects
= control_iface
.ProjectsGetAvailable()
119 for project
in projects
:
122 if index
>= len(sys
.argv
):
123 print "project open command requires project name argument"
126 arg
= sys
.argv
[index
]
130 #open_options["option1"] = "asd"
131 #open_options["option2"] = True
133 control_iface
.ProjectOpen(arg
, open_options
)
135 control_iface
.ProjectsSaveAll()
137 control_iface
.ProjectsCloseAll()
139 print "Unknown command '%s'" % arg
140 except dbus
.DBusException
, e
:
141 print "DBus exception: %s" % str(e
)
143 if __name__
== '__main__':