unify source copyright headers in gladish
[ladish.git] / ladish_control
blob6fb4a0cd73d022c14a77dac3e7987d41141d6de1
1 #!/usr/bin/env python
2 # LASH
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'
23 import sys
24 import os
25 import time
26 from traceback import print_exc
28 import dbus
30 def bool_convert(str_value):
31 if str_value.lower() == "false":
32 return False
34 if str_value.lower() == "off":
35 return False
37 if str_value.lower() == "no":
38 return False
40 if str_value == "0":
41 return False
43 if str_value.lower() == "(null)":
44 return False
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)
53 return dbus_value
55 def dbus_type_to_type_string(dbus_value):
56 if type(dbus_value) == dbus.Boolean:
57 return "bool"
58 if type(dbus_value) == dbus.Int32:
59 return "sint"
60 if type(dbus_value) == dbus.UInt32:
61 return "uint"
62 if type(dbus_value) == dbus.Byte:
63 return "char"
64 if type(dbus_value) == dbus.String:
65 return "str"
67 return None # throw exception here?
69 def dbus_typesig_to_type_string(type_char):
70 type_char = str(type_char)
71 if type_char == 'i':
72 return "sint"
73 if type_char == 'u':
74 return "uint"
75 if type_char == 'y':
76 return "char"
77 if type_char == 's':
78 return "str"
79 if type_char == 'b':
80 return "bool"
82 print 'shit'
83 return None # throw exception here?
85 def main():
86 if len(sys.argv) == 1:
87 print "Usage: %s [command] [command] ..." % os.path.basename(sys.argv[0])
88 print "Commands:"
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"
94 sys.exit(0)
96 bus = dbus.SessionBus()
97 lash = None
99 # check arguments
100 index = 1
101 while index < len(sys.argv):
102 arg = sys.argv[index]
103 index += 1
104 try:
105 if not lash:
106 lash = bus.get_object(service_name, "/")
107 control_iface = dbus.Interface(lash, control_interface_name)
109 if arg == "exit":
110 print "--- exit"
111 control_iface.Exit()
112 time.sleep(1)
113 # we have deactivated the object and we need to get new connection if there are more commands
114 lash = None
115 control_iface = None
116 elif arg == 'list':
117 print "--- projects list"
118 projects = control_iface.ProjectsGetAvailable()
119 for project in projects:
120 print project
121 elif arg == 'open':
122 if index >= len(sys.argv):
123 print "project open command requires project name argument"
124 sys.exit()
126 arg = sys.argv[index]
127 index += 1
129 open_options = {}
130 #open_options["option1"] = "asd"
131 #open_options["option2"] = True
133 control_iface.ProjectOpen(arg, open_options)
134 elif arg == 'save':
135 control_iface.ProjectsSaveAll()
136 elif arg == 'close':
137 control_iface.ProjectsCloseAll()
138 else:
139 print "Unknown command '%s'" % arg
140 except dbus.DBusException, e:
141 print "DBus exception: %s" % str(e)
143 if __name__ == '__main__':
144 main()