This repository was archived by the owner on May 7, 2020. It is now read-only.
forked from OpenZWave/python-openzwave
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathpyozw_shell.py
More file actions
executable file
·96 lines (77 loc) · 2.75 KB
/
Copy pathpyozw_shell.py
File metadata and controls
executable file
·96 lines (77 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
.. module:: pyozw_shell
This file is part of **python-openzwave** project https://github.com/OpenZWave/python-openzwave.
:platform: Unix, Windows, MacOS X
:sinopsis: openzwave API
.. moduleauthor: bibi21000 aka Sébastien GALLET <bibi21000@gmail.com>
License : GPL(v3)
**python-openzwave** is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
**python-openzwave** is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with python-openzwave. If not, see http://www.gnu.org/licenses.
"""
__author__ = 'bibi21000'
import sys, os, optparse, re, shutil, datetime
import logging
import urwid
from pyozwman.ozwsh_main import MainWindow
from libopenzwave import configPath
import signal
def signal_term_handler(signal, frame):
print('got SIGTERM')
raise urwid.ExitMainLoop()
signal.signal(signal.SIGTERM, signal_term_handler)
signal.signal(signal.SIGINT, signal_term_handler)
def main():
parser = optparse.OptionParser(
usage="pyozw_shell [--device=/dev/ttyUSB0] [--log=Debug] ...")
parser.add_option(
'-d', '--device',
dest='device',
type="str",
default="/dev/ttyUSB0",
help="The path to your ZWave device")
parser.add_option(
'-l', '--log',
dest='log',
default="Debug",
type="choice",
choices=['Debug', 'Info'],
help="The log level (Debug|Info)")
def callback_config(option, opt_str, value, parser):
if value is None :
value = configPath()
if value is None :
raise optparse.OptionValueError("Can't determine the config path automatically.")
setattr(parser.values, option.dest, value)
parser.add_option(
'-c', '--config',
dest='config',
action="callback",
default=None,
callback=callback_config,
type="str",
help="The config path")
parser.add_option(
'-u', '--user',
dest='user',
default=".",
type="str",
help="The user path")
options, args = parser.parse_args()
window = None
window = MainWindow(device=options.device, loglevel=options.log, user_path=options.user, config_path=options.config)
window.start()
window.loop.run()
window.stop()
window.log.info("="*15 + " exit " + "="*15)
if __name__ == '__main__':
main()