Newer
Older
from shell.ais_shell import GetListInformation, AISGetLibraryVersionStr, AisShellpGetProgramVersion, AISRestart, \
AISDestroy, AISOpen, AISClose, AISUpdateAndGetCount, wr_status, sys_get_timezone_info, AISGetTime, AISSetTime, \
log_get, whitelist_read, blacklist_read, get_io_state, lock_open, relay_toogle, AISGetVersion, ee_lock, ee_unlock
def GetDLLVersion():
return "AIS_GetDLLVersion() >> %s\n" % AISGetLibraryVersionStr()
def GetProgramVersion():
return '{0}\n{1}\n'.format(AisHttpGetProgramVersion(), AisShellpGetProgramVersion())
def GetExitApp():
if sys.platform.startswith('linux'):
os.system('pkill -9 python')
os.kill(os.getpid(), signal.SIGINT)
elif sys.platform.startswith('win'):
os._exit(0)
return '\nServer stopped !\nClose program !\n'
res, count = AISUpdateAndGetCount()
return ' COUNT >> {0} {1}'.format(count, wr_status('', res))
except WindowsError:
pass
def GetAISSetTime():
return '{0}\n{1}'.format(sys_get_timezone_info(), AISSetTime(dev))
def GetInformation():
return '{0}\n{1}\n{2}'.format(AISGetTime(dev)[0], sys_get_timezone_info(), AISGetVersion(dev))
action = {'q': GetListInformation,
'v': GetDLLVersion,
'V': GetProgramVersion,
'X': GetExitApp,
'R': functools.partial(AISRestart, dev),
'D': functools.partial(AISDestroy, dev),
'o': functools.partial(AISOpen, dev),
'c': functools.partial(AISClose, dev),
'd': GetAISUpdateAndGetCount,
't': GetAISGetTime,
'T': GetAISSetTime,
'l': functools.partial(log_get, dev),
'w': functools.partial(whitelist_read, dev),
'b': functools.partial(blacklist_read, dev),
'g': functools.partial(get_io_state, dev),
'G': functools.partial(lock_open, dev),
'y': functools.partial(relay_toogle, dev),
'f': functools.partial(AISGetVersion, dev),
'E': functools.partial(ee_lock, dev),
'e': functools.partial(ee_unlock, dev),
'i': GetInformation
}
def command(getfunction, ldev, **pq):
global dev
dev = ldev
try:
return action[getfunction].__call__()
except KeyError:
return 'WRONG COMMAND !!! \nYou must enter the correct command'