blob: 4efa1c65f7aaaf7e3222f680e0dd4401e80adeda [file] [log] [blame]
Brad Bishop61908f82016-06-05 23:57:43 -04001#!/usr/bin/env python
2
3# Contributors Listed Below - COPYRIGHT 2016
4# [+] International Business Machines Corp.
5#
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16# implied. See the License for the specific language governing
17# permissions and limitations under the License.
18
19import sys
20import subprocess
21import dbus
22import dbus.service
23import dbus.mainloop.glib
24import gobject
25
26
27class Goto(dbus.service.Object):
28 def __init__(self, connection, path, loop, state, cmdline):
29 super(Goto, self).__init__(connection, path)
30 self.loop = loop
31 self.state = state
32 self.cmdline = cmdline
33 gobject.idle_add(self.go)
34
35 def go(self):
36 if self.cmdline:
37 subprocess.call(self.cmdline)
38
39 if self.state:
40 self.GotoSystemState(self.state)
41
42 self.loop.quit()
43
44 @dbus.service.signal('org.openbmc.Control', signature='s')
45 def GotoSystemState(self, state):
46 pass
47
48if __name__ == '__main__':
49 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
50 bus = dbus.SystemBus()
51 cmdline = None
52 state = None
53
54 if len(sys.argv) > 1:
55 state = sys.argv[1]
56 if len(sys.argv) > 2:
57 cmdline = sys.argv[2:]
58
59 loop = gobject.MainLoop()
60 o = Goto(bus, '/org/openbmc/goto', loop, state, cmdline)
61 loop.run()