Commit cb9b5d5f4ca5eb0c39159dab6d39bdf388b12da2
1 parent
d8ef96d6
Exists in
master
update imports
Showing
5 changed files
with
91 additions
and
78 deletions
Show diff stats
src/guitastro_device_ascomcam/__init__.py
... | ... | @@ -8,8 +8,61 @@ guitastro_device_ascomcam.device_ascomcam |
8 | 8 | from __future__ import (absolute_import, division, print_function, |
9 | 9 | unicode_literals) |
10 | 10 | |
11 | -import glob | |
12 | -import os | |
11 | +__version__ = "20240702" | |
13 | 12 | |
14 | -from .device_ascomcam import Device_Ascomcam | |
13 | +import os, sys, pathlib | |
14 | + | |
15 | +# --- Get the module name | |
16 | +# __file__ = 'C:\\d\\python\\gestion_packages\\mymodule\\src\\mymodule\\__init__.py' | |
17 | +modulename = pathlib.Path(__file__).parts[-2] | |
18 | + | |
19 | +# --- Special for Sphinx in mymodule/docs | |
20 | +path = os.path.abspath(os.path.join(__file__, "..", "..", modulename)) | |
21 | +sys.path.append(path) if path not in sys.path else None | |
15 | 22 | |
23 | +# --- Switch on True to update the list of imports | |
24 | +if False: | |
25 | + import glob, os | |
26 | + import importlib | |
27 | + pyfiles = glob.glob(os.path.abspath(os.path.join(__file__, "..", "*.py"))) | |
28 | + files = [] | |
29 | + imps = [] | |
30 | + for pyfile in pyfiles: | |
31 | + if os.path.basename(pyfile)[0] != "_" and os.path.isfile(pyfile): | |
32 | + file = os.path.splitext(os.path.basename(pyfile))[0] | |
33 | + #print(f"{file=}") | |
34 | + with open(pyfile, "rt") as fid: | |
35 | + lines = fid.readlines() | |
36 | + for line in lines: | |
37 | + # 0123456789 | |
38 | + # class O( | |
39 | + if len(line) < 8: | |
40 | + continue | |
41 | + if line[0:6] == "class ": | |
42 | + k = line.find("(") | |
43 | + if k > 6: | |
44 | + obj = line[6:k].strip() | |
45 | + imp = f"from .{file} import {obj}" | |
46 | + imps.append(imp) | |
47 | + files.append(file) | |
48 | + #importlib.__import__(modulename, fromlist=files) | |
49 | + print("="*40) | |
50 | + for file in files: | |
51 | + print(f"import {file}") | |
52 | + print() | |
53 | + for imp in imps: | |
54 | + print(f"{imp}") | |
55 | + print("="*40) | |
56 | + del pyfiles, pyfile, file, files, os, glob, importlib, fid, lines, line, k, obj, imp, imps | |
57 | + | |
58 | +# --- All imports generated by the switch = True | |
59 | +import component_detector_shutter_ascomcam | |
60 | +import component_detector_timer_ascomcam | |
61 | +import component_sensor_detector_ascomcam | |
62 | +import device_ascomcam | |
63 | + | |
64 | +from .component_detector_shutter_ascomcam import ComponentDetectorShutterAscomcam | |
65 | +from .component_detector_timer_ascomcam import ComponentDetectorTimerAscomcam | |
66 | +from .component_sensor_detector_ascomcam import ComponentSensorDetectorAscomcamDoAcq | |
67 | +from .component_sensor_detector_ascomcam import ComponentSensorDetectorAscomcam | |
68 | +from .device_ascomcam import Device_Ascomcam | ... | ... |
src/guitastro_device_ascomcam/component_detector_shutter_ascomcam.py
... | ... | @@ -2,20 +2,10 @@ |
2 | 2 | import os |
3 | 3 | import sys |
4 | 4 | |
5 | -try: | |
6 | - # guitastro is installed with setup.py | |
7 | - from guitastro import ComponentDetectorShutter, ComponentException | |
8 | -except: | |
9 | - # guitastro is installed with only requirements.in | |
10 | - # guitastro_camera_* folders must be copied at the same root folder than guitastro | |
11 | - pwd = os.getcwd() | |
12 | - short_paths = ['../../../guitastro/src'] | |
13 | - for short_path in short_paths: | |
14 | - path = os.path.abspath(os.path.join(pwd, short_path)) | |
15 | - if path not in sys.path: | |
16 | - sys.path.insert(0, path) | |
17 | - from guitastro.component import ComponentException | |
18 | - from guitastro.component_detector_shutter import ComponentDetectorShutter | |
5 | +# --- import guitastro | |
6 | +path = os.path.abspath(os.path.join(__file__, "..", "..", "..", "..", "guitastro", "src")) | |
7 | +sys.path.append(path) if path not in sys.path else None | |
8 | +from guitastro import * | |
19 | 9 | |
20 | 10 | # ##################################################################### |
21 | 11 | # ##################################################################### | ... | ... |
src/guitastro_device_ascomcam/component_detector_timer_ascomcam.py
... | ... | @@ -2,20 +2,10 @@ import time |
2 | 2 | import os |
3 | 3 | import sys |
4 | 4 | |
5 | -try: | |
6 | - # guitastro is installed with setup.py | |
7 | - from guitastro import ComponentDetectorTimer, ComponentException | |
8 | -except: | |
9 | - # guitastro is installed with only requirements.in | |
10 | - # guitastro_camera_* folders must be copied at the same root folder than guitastro | |
11 | - pwd = os.getcwd() | |
12 | - short_paths = ['../../../guitastro/src'] | |
13 | - for short_path in short_paths: | |
14 | - path = os.path.abspath(os.path.join(pwd, short_path)) | |
15 | - if path not in sys.path: | |
16 | - sys.path.insert(0, path) | |
17 | - from guitastro.component import ComponentException | |
18 | - from guitastro.component_detector_timer import ComponentDetectorTimer | |
5 | +# --- import guitastro | |
6 | +path = os.path.abspath(os.path.join(__file__, "..", "..", "..", "..", "guitastro", "src")) | |
7 | +sys.path.append(path) if path not in sys.path else None | |
8 | +from guitastro import * | |
19 | 9 | |
20 | 10 | # ##################################################################### |
21 | 11 | # ##################################################################### | ... | ... |
src/guitastro_device_ascomcam/component_sensor_detector_ascomcam.py
... | ... | @@ -5,23 +5,11 @@ from threading import Thread, Event |
5 | 5 | import traceback |
6 | 6 | import time |
7 | 7 | import datetime |
8 | -#import shlex | |
9 | 8 | |
10 | -try: | |
11 | - # guitastro is installed with setup.py | |
12 | - #from guitastro import ComponentSensorDetector, ComponentException | |
13 | - from guitastro import ComponentSensorDetector, ComponentSensorDetectorException | |
14 | -except: | |
15 | - # guitastro is installed with only requirements.in | |
16 | - # guitastro_objcom_* folders must be copied at the same root folder than guitastro | |
17 | - pwd = os.getcwd() | |
18 | - short_paths = ['../../../guitastro/src'] | |
19 | - for short_path in short_paths: | |
20 | - path = os.path.abspath(os.path.join(pwd, short_path)) | |
21 | - if path not in sys.path: | |
22 | - sys.path.insert(0, path) | |
23 | - #from guitastro.component import ComponentException | |
24 | - from guitastro.component_sensor_detector import ComponentSensorDetector, ComponentSensorDetectorException | |
9 | +# --- import guitastro | |
10 | +path = os.path.abspath(os.path.join(__file__, "..", "..", "..", "..", "guitastro", "src")) | |
11 | +sys.path.append(path) if path not in sys.path else None | |
12 | +from guitastro import * | |
25 | 13 | |
26 | 14 | isascom = True |
27 | 15 | try: |
... | ... | @@ -51,12 +39,14 @@ class ComponentSensorDetectorAscomcamDoAcq(Thread): |
51 | 39 | self._binning = args[2] |
52 | 40 | self._queue = self._upself._queue |
53 | 41 | self._stopevent = Event() |
42 | + self._timer = -1 | |
54 | 43 | |
55 | 44 | def run(self): |
56 | 45 | """Code to execute during the Thread life |
57 | 46 | """ |
58 | 47 | operation = "thread.acq.run" |
59 | 48 | upself = self._upself |
49 | + self._timer = 0 | |
60 | 50 | try: |
61 | 51 | # --- stop current acq |
62 | 52 | # --- start current acq |
... | ... | @@ -69,6 +59,7 @@ class ComponentSensorDetectorAscomcamDoAcq(Thread): |
69 | 59 | while True: |
70 | 60 | # --- Timeout |
71 | 61 | dt = time.time() - t0 |
62 | + self._timer = int(dt) | |
72 | 63 | if dt >= timeout: |
73 | 64 | upself._is_timeout = True |
74 | 65 | break |
... | ... | @@ -95,6 +86,8 @@ class ComponentSensorDetectorAscomcamDoAcq(Thread): |
95 | 86 | traceback.print_exc(file=sys.stdout) |
96 | 87 | # --- |
97 | 88 | # The thread termined properly |
89 | + self._timer = -1 | |
90 | + upself.database.query("status", upself.SENSOR_STATE_IDLE) | |
98 | 91 | |
99 | 92 | def stop(self): |
100 | 93 | # --- stop any motion |
... | ... | @@ -103,6 +96,9 @@ class ComponentSensorDetectorAscomcamDoAcq(Thread): |
103 | 96 | upself._stop_acq(operation) |
104 | 97 | self._stopevent.set() |
105 | 98 | |
99 | + def timer(self): | |
100 | + return self._timer | |
101 | + | |
106 | 102 | def __del__(self): |
107 | 103 | self.stop() |
108 | 104 | ... | ... |
src/guitastro_device_ascomcam/device_ascomcam.py
1 | 1 | # -*- coding: utf-8 -*- |
2 | +# source d'inspiration | |
3 | +# https://stackoverflow.com/questions/46163001/python-script-for-controlling-ascom-ccd-camera | |
4 | +# https://rk.edu.pl/en/ascom-end-user-application-developers/ | |
5 | +# https://mountwizzard4.readthedocs.io/en/latest/overview.html | |
6 | + | |
7 | +# https://ascom-standards.org/Help/Developer/html/T_ASCOM_deviceAccess_Camera.htm | |
8 | + | |
2 | 9 | import os |
3 | 10 | import sys |
4 | 11 | #import ast |
5 | 12 | import time |
6 | 13 | |
7 | -try: | |
8 | - from .component_sensor_detector_ascomcam import ComponentSensorDetectorAscomcam | |
9 | -except: | |
10 | - from component_sensor_detector_ascomcam import ComponentSensorDetectorAscomcam | |
11 | - | |
12 | -""" | |
13 | -try: | |
14 | - from .component_detector_shutter_ascomcam import ComponentDetectorShutterAscomcam | |
15 | -except: | |
16 | - from component_detector_shutter_ascomcam import ComponentDetectorShutterAscomcam | |
14 | +# --- import guitastro | |
15 | +path = os.path.abspath(os.path.join(__file__, "..", "..", "..", "..", "guitastro", "src")) | |
16 | +sys.path.append(path) if path not in sys.path else None | |
17 | +from guitastro import * | |
17 | 18 | |
18 | -try: | |
19 | - from .component_detector_timer_ascomcam import ComponentDetectorTimerAscomcam | |
20 | -except: | |
21 | - from component_detector_timer_ascomcam import ComponentDetectorTimerAscomcam | |
22 | -""" | |
19 | +# --- import guitastro_device_ascomcam | |
20 | +path = os.path.abspath(os.path.join(__file__, "..", "..")) | |
21 | +sys.path.append(path) if path not in sys.path else None | |
22 | +from guitastro_device_ascomcam import * | |
23 | 23 | |
24 | 24 | isascom = True |
25 | 25 | try: |
... | ... | @@ -27,22 +27,6 @@ try: |
27 | 27 | except: |
28 | 28 | isascom = False |
29 | 29 | |
30 | -try: | |
31 | - # guitastro is installed with setup.py | |
32 | - # from guitastro import Ephemeris, Device | |
33 | - from guitastro import Device | |
34 | -except: | |
35 | - # guitastro is installed with only requirements.in | |
36 | - # guitastro_objcom_* folders must be copied at the same root folder than guitastro | |
37 | - pwd = os.getcwd() | |
38 | - short_paths = ['../../../guitastro/src', '..'] | |
39 | - for short_path in short_paths: | |
40 | - path = os.path.abspath(os.path.join(pwd, short_path)) | |
41 | - if path not in sys.path: | |
42 | - sys.path.insert(0, path) | |
43 | - from guitastro.device import Device | |
44 | - #from guitastro.ephemeris import Ephemeris | |
45 | - | |
46 | 30 | # ##################################################################### |
47 | 31 | # ##################################################################### |
48 | 32 | # ##################################################################### | ... | ... |