Changeset 75
- Timestamp:
- Feb 11, 2010, 8:10:33 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
powerbar/npm4000.py
r74 r75 1 #!/usr/bin/env python 1 2 # NPM 4000 powerbar managment script, to be used instead of the windows 2 3 # application. 4 # 3 5 # XXX: Not all features are ported yet (like amp monitoring) 4 6 # XXX: Some dirty poking around with hex representations and numeric representations of ports 5 # 7 # XXX: Make proper classes for use 8 # XXX: Documentation 9 # 6 10 # Licence: BSD 7 11 # Version: $Id: npm4000.py 750 2009-09-27 14:34:55Z rick $ 8 12 # Rick van der Zwet <info@rickvanderzwet.nl> 13 9 14 import socket, time 10 15 import getopt, sys … … 130 135 return False 131 136 132 def getPortStatus( port):137 def getPortStatus(i): 133 138 raw_status = doCommand('status') 134 retval = getPortState(port,raw_status) 135 dprint("Port %i: %s" % (port, retval)) 139 print "Port %02i [%s]:" % (i, getPortName(i)), 140 if getPortState(i,raw_status): 141 print "1" 142 else: 143 print "0" 136 144 return(retval) 137 145 138 def getStatus ():146 def getStatusAll(): 139 147 raw_status= doCommand('status') 140 148 for i in range(1,25): … … 146 154 147 155 def togglePort(port): 148 portNumber = getPortNumber("%X" % port) 149 if getPortStatus(portNumber): 156 if getPortState(port): 150 157 doCommand('portOff',port) 151 158 else: … … 198 205 try: 199 206 opts, args = getopt.getopt(sys.argv[1:], 200 "hf:s t:o:v", ["help","verbose","host=", "port=", "password=", "addresscode=","toggle=","off=", "on=", "status"])207 "hf:s:t:o:v", ["help","verbose","host=", "port=", "password=", "addresscode=","toggle=","off=", "on=", "status="]) 201 208 except getopt.GetoptError, err: 202 209 # print help information and exit: … … 207 214 opt_port = None 208 215 opt_action = None 209 opt_status = None210 216 for o, a in opts: 211 217 if o in ("-v", "--verbose"): … … 223 229 inet_port = a 224 230 elif o in ("-s", "--status"): 225 opt_status = True 231 opt_action = "status" 232 opt_port = a 226 233 elif o in ("-t","--toggle"): 227 234 opt_action = "toggle" … … 236 243 assert False, "unhandled option" 237 244 238 if (opt_status): 239 getStatus() 240 sys.exit(0) 241 elif (opt_port == None or opt_action == None): 245 if (opt_port == None or opt_action == None): 242 246 usage() 243 247 sys.exit(2) 244 248 245 249 dprint ('action: ' + opt_action + ' port: ' + opt_port) 250 251 s.connect((inet_addr, inet_port)) 252 253 # Status needs real integers, hack 254 if opt_action == "status": 255 if opt_port == "all": 256 getStatusAll() 257 else: 258 print "XXX: Implement" 259 sys.exit(0) 246 260 247 261 # Resolve port to proper number … … 256 270 dprint('Hexcode of port: %i' % opt_port) 257 271 258 s.connect((inet_addr, inet_port))259 260 272 if opt_action == "toggle": 261 273 if opt_port == "all": … … 275 287 doCommand("portOn", opt_port) 276 288 289 277 290 if __name__ == "__main__": 278 291 main()
Note:
See TracChangeset
for help on using the changeset viewer.