indipyconsole 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ import sys
2
+
3
+ from .consoleclient import ConsoleClient
4
+
5
+ __all__ = ["ConsoleClient"]
6
+
7
+ version = "0.0.1"
8
+
9
+ if sys.version_info < (3, 10):
10
+ raise ImportError('indipyconsole requires Python >= 3.10')
@@ -0,0 +1,126 @@
1
+
2
+ """Creates a terminal client
3
+
4
+ Try
5
+
6
+ python3 -m indipyconsole --help
7
+
8
+ For a description of options
9
+ """
10
+
11
+
12
+ import sys, argparse, asyncio, pathlib, logging
13
+
14
+ from . import version
15
+
16
+ from . import ConsoleClient
17
+
18
+ logger = logging.getLogger()
19
+
20
+ # logger is the root logger, with level and handler set here
21
+ # by the arguments given. If no logging option is given, it
22
+ # has a NullHandler() added
23
+
24
+
25
+ def setlogging(client, level, logfile):
26
+ """Sets the logging level and logfile, returns the level on success, None on failure.
27
+ level should be an integer, one of 1, 2, 3 or 4."""
28
+
29
+ # loglevel:1 Information and error messages only
30
+ # loglevel:2 log vector tags without members or contents
31
+ # loglevel:3 log vectors and members - but not BLOB contents
32
+ # loglevel:4 log vectors and all contents
33
+
34
+ try:
35
+ if level not in (1, 2, 3, 4):
36
+ return
37
+ logfile = pathlib.Path(logfile).expanduser().resolve()
38
+
39
+ if level == 4:
40
+ logger.setLevel(logging.DEBUG)
41
+ client.debug_verbosity(3)
42
+ elif level == 3:
43
+ logger.setLevel(logging.DEBUG)
44
+ client.debug_verbosity(2)
45
+ elif level == 2:
46
+ logger.setLevel(logging.DEBUG)
47
+ client.debug_verbosity(1)
48
+ elif level == 1:
49
+ logger.setLevel(logging.INFO)
50
+ client.debug_verbosity(0)
51
+ # If logging debug not enabled, reduce traceback info
52
+ sys.tracebacklimit = 0
53
+
54
+ fh = logging.FileHandler(logfile)
55
+ logger.addHandler(fh)
56
+ except Exception:
57
+ return
58
+ return level
59
+
60
+
61
+ def main():
62
+ """The commandline entry point to run the terminal client."""
63
+
64
+ parser = argparse.ArgumentParser(usage="indipyconsole [options]",
65
+ formatter_class=argparse.RawDescriptionHelpFormatter,
66
+ description="Console client to communicate to an INDI service.",
67
+ epilog="""The BLOB's folder can also be set from within the session.
68
+ Setting loglevel and logfile should only be used for brief
69
+ diagnostic purposes, the logfile could grow very big.
70
+ loglevel:1 Information and error messages only, no exception trace.
71
+ The following levels enable exception traces in the logs
72
+ loglevel:2 As 1 plus xml vector tags without members or contents,
73
+ loglevel:3 As 1 plus xml vectors and members - but not BLOB contents,
74
+ loglevel:4 As 1 plus xml vectors and all contents
75
+ """)
76
+ parser.add_argument("-p", "--port", type=int, default=7624, help="Port of the INDI server (default 7624).")
77
+ parser.add_argument("--host", default="localhost", help="Hostname/IP of the INDI server (default localhost).")
78
+ parser.add_argument("-b", "--blobs", help="Optional folder where BLOB's will be saved.")
79
+ parser.add_argument("--loglevel", help="Enables logging, value 1, 2, 3 or 4.")
80
+ parser.add_argument("--logfile", help="File where logs will be saved")
81
+
82
+ parser.add_argument("--version", action="version", version=version)
83
+ args = parser.parse_args()
84
+
85
+ if args.blobs:
86
+ try:
87
+ blobfolder = pathlib.Path(args.blobs).expanduser().resolve()
88
+ except Exception:
89
+ print("Error: If given, the BLOB's folder should be an existing directory")
90
+ return 1
91
+ else:
92
+ if not blobfolder.is_dir():
93
+ print("Error: If given, the BLOB's folder should be an existing directory")
94
+ return 1
95
+ else:
96
+ blobfolder = None
97
+
98
+ if args.loglevel:
99
+ if args.loglevel not in ("1", "2", "3", "4"):
100
+ print("Error: If given, the loglevel should be 1, 2, 3 or 4")
101
+ return 1
102
+
103
+
104
+ client = ConsoleClient(indihost=args.host, indiport=args.port, blobfolder=blobfolder)
105
+
106
+ if args.loglevel and args.logfile:
107
+ loglevel = int(args.loglevel)
108
+ level = setlogging(client, loglevel, args.logfile)
109
+ if level != loglevel:
110
+ print("Error: Failed to set logging")
111
+ return 1
112
+ else:
113
+ logger.addHandler(logging.NullHandler())
114
+
115
+ try:
116
+ # Starts the client, creates the console screens
117
+ asyncio.run(client.asyncrun())
118
+ finally:
119
+ # clear curses setup
120
+ client.console_reset()
121
+
122
+ return 0
123
+
124
+
125
+ if __name__ == "__main__":
126
+ sys.exit(main())