diff --git a/src/guitastro_device_ascomcam/__init__.py b/src/guitastro_device_ascomcam/__init__.py index e4c7d78..570ab7b 100644 --- a/src/guitastro_device_ascomcam/__init__.py +++ b/src/guitastro_device_ascomcam/__init__.py @@ -8,8 +8,61 @@ guitastro_device_ascomcam.device_ascomcam from __future__ import (absolute_import, division, print_function, unicode_literals) -import glob -import os +__version__ = "20240702" -from .device_ascomcam import Device_Ascomcam +import os, sys, pathlib + +# --- Get the module name +# __file__ = 'C:\\d\\python\\gestion_packages\\mymodule\\src\\mymodule\\__init__.py' +modulename = pathlib.Path(__file__).parts[-2] + +# --- Special for Sphinx in mymodule/docs +path = os.path.abspath(os.path.join(__file__, "..", "..", modulename)) +sys.path.append(path) if path not in sys.path else None +# --- Switch on True to update the list of imports +if False: + import glob, os + import importlib + pyfiles = glob.glob(os.path.abspath(os.path.join(__file__, "..", "*.py"))) + files = [] + imps = [] + for pyfile in pyfiles: + if os.path.basename(pyfile)[0] != "_" and os.path.isfile(pyfile): + file = os.path.splitext(os.path.basename(pyfile))[0] + #print(f"{file=}") + with open(pyfile, "rt") as fid: + lines = fid.readlines() + for line in lines: + # 0123456789 + # class O( + if len(line) < 8: + continue + if line[0:6] == "class ": + k = line.find("(") + if k > 6: + obj = line[6:k].strip() + imp = f"from .{file} import {obj}" + imps.append(imp) + files.append(file) + #importlib.__import__(modulename, fromlist=files) + print("="*40) + for file in files: + print(f"import {file}") + print() + for imp in imps: + print(f"{imp}") + print("="*40) + del pyfiles, pyfile, file, files, os, glob, importlib, fid, lines, line, k, obj, imp, imps + +# --- All imports generated by the switch = True +import component_detector_shutter_ascomcam +import component_detector_timer_ascomcam +import component_sensor_detector_ascomcam +import device_ascomcam + +from .component_detector_shutter_ascomcam import ComponentDetectorShutterAscomcam +from .component_detector_timer_ascomcam import ComponentDetectorTimerAscomcam +from .component_sensor_detector_ascomcam import ComponentSensorDetectorAscomcamDoAcq +from .component_sensor_detector_ascomcam import ComponentSensorDetectorAscomcam +from .device_ascomcam import Device_Ascomcam diff --git a/src/guitastro_device_ascomcam/component_detector_shutter_ascomcam.py b/src/guitastro_device_ascomcam/component_detector_shutter_ascomcam.py index 933d008..ad115b9 100644 --- a/src/guitastro_device_ascomcam/component_detector_shutter_ascomcam.py +++ b/src/guitastro_device_ascomcam/component_detector_shutter_ascomcam.py @@ -2,20 +2,10 @@ import os import sys -try: - # guitastro is installed with setup.py - from guitastro import ComponentDetectorShutter, ComponentException -except: - # guitastro is installed with only requirements.in - # guitastro_camera_* folders must be copied at the same root folder than guitastro - pwd = os.getcwd() - short_paths = ['../../../guitastro/src'] - for short_path in short_paths: - path = os.path.abspath(os.path.join(pwd, short_path)) - if path not in sys.path: - sys.path.insert(0, path) - from guitastro.component import ComponentException - from guitastro.component_detector_shutter import ComponentDetectorShutter +# --- import guitastro +path = os.path.abspath(os.path.join(__file__, "..", "..", "..", "..", "guitastro", "src")) +sys.path.append(path) if path not in sys.path else None +from guitastro import * # ##################################################################### # ##################################################################### diff --git a/src/guitastro_device_ascomcam/component_detector_timer_ascomcam.py b/src/guitastro_device_ascomcam/component_detector_timer_ascomcam.py index bb05908..17f23f9 100644 --- a/src/guitastro_device_ascomcam/component_detector_timer_ascomcam.py +++ b/src/guitastro_device_ascomcam/component_detector_timer_ascomcam.py @@ -2,20 +2,10 @@ import time import os import sys -try: - # guitastro is installed with setup.py - from guitastro import ComponentDetectorTimer, ComponentException -except: - # guitastro is installed with only requirements.in - # guitastro_camera_* folders must be copied at the same root folder than guitastro - pwd = os.getcwd() - short_paths = ['../../../guitastro/src'] - for short_path in short_paths: - path = os.path.abspath(os.path.join(pwd, short_path)) - if path not in sys.path: - sys.path.insert(0, path) - from guitastro.component import ComponentException - from guitastro.component_detector_timer import ComponentDetectorTimer +# --- import guitastro +path = os.path.abspath(os.path.join(__file__, "..", "..", "..", "..", "guitastro", "src")) +sys.path.append(path) if path not in sys.path else None +from guitastro import * # ##################################################################### # ##################################################################### diff --git a/src/guitastro_device_ascomcam/component_sensor_detector_ascomcam.py b/src/guitastro_device_ascomcam/component_sensor_detector_ascomcam.py index 6a23a3e..2e75323 100644 --- a/src/guitastro_device_ascomcam/component_sensor_detector_ascomcam.py +++ b/src/guitastro_device_ascomcam/component_sensor_detector_ascomcam.py @@ -5,23 +5,11 @@ from threading import Thread, Event import traceback import time import datetime -#import shlex -try: - # guitastro is installed with setup.py - #from guitastro import ComponentSensorDetector, ComponentException - from guitastro import ComponentSensorDetector, ComponentSensorDetectorException -except: - # guitastro is installed with only requirements.in - # guitastro_objcom_* folders must be copied at the same root folder than guitastro - pwd = os.getcwd() - short_paths = ['../../../guitastro/src'] - for short_path in short_paths: - path = os.path.abspath(os.path.join(pwd, short_path)) - if path not in sys.path: - sys.path.insert(0, path) - #from guitastro.component import ComponentException - from guitastro.component_sensor_detector import ComponentSensorDetector, ComponentSensorDetectorException +# --- import guitastro +path = os.path.abspath(os.path.join(__file__, "..", "..", "..", "..", "guitastro", "src")) +sys.path.append(path) if path not in sys.path else None +from guitastro import * isascom = True try: @@ -51,12 +39,14 @@ class ComponentSensorDetectorAscomcamDoAcq(Thread): self._binning = args[2] self._queue = self._upself._queue self._stopevent = Event() + self._timer = -1 def run(self): """Code to execute during the Thread life """ operation = "thread.acq.run" upself = self._upself + self._timer = 0 try: # --- stop current acq # --- start current acq @@ -69,6 +59,7 @@ class ComponentSensorDetectorAscomcamDoAcq(Thread): while True: # --- Timeout dt = time.time() - t0 + self._timer = int(dt) if dt >= timeout: upself._is_timeout = True break @@ -95,6 +86,8 @@ class ComponentSensorDetectorAscomcamDoAcq(Thread): traceback.print_exc(file=sys.stdout) # --- # The thread termined properly + self._timer = -1 + upself.database.query("status", upself.SENSOR_STATE_IDLE) def stop(self): # --- stop any motion @@ -103,6 +96,9 @@ class ComponentSensorDetectorAscomcamDoAcq(Thread): upself._stop_acq(operation) self._stopevent.set() + def timer(self): + return self._timer + def __del__(self): self.stop() diff --git a/src/guitastro_device_ascomcam/device_ascomcam.py b/src/guitastro_device_ascomcam/device_ascomcam.py index 6aaaa08..89aed27 100644 --- a/src/guitastro_device_ascomcam/device_ascomcam.py +++ b/src/guitastro_device_ascomcam/device_ascomcam.py @@ -1,25 +1,25 @@ # -*- coding: utf-8 -*- +# source d'inspiration +# https://stackoverflow.com/questions/46163001/python-script-for-controlling-ascom-ccd-camera +# https://rk.edu.pl/en/ascom-end-user-application-developers/ +# https://mountwizzard4.readthedocs.io/en/latest/overview.html + +# https://ascom-standards.org/Help/Developer/html/T_ASCOM_deviceAccess_Camera.htm + import os import sys #import ast import time -try: - from .component_sensor_detector_ascomcam import ComponentSensorDetectorAscomcam -except: - from component_sensor_detector_ascomcam import ComponentSensorDetectorAscomcam - -""" -try: - from .component_detector_shutter_ascomcam import ComponentDetectorShutterAscomcam -except: - from component_detector_shutter_ascomcam import ComponentDetectorShutterAscomcam +# --- import guitastro +path = os.path.abspath(os.path.join(__file__, "..", "..", "..", "..", "guitastro", "src")) +sys.path.append(path) if path not in sys.path else None +from guitastro import * -try: - from .component_detector_timer_ascomcam import ComponentDetectorTimerAscomcam -except: - from component_detector_timer_ascomcam import ComponentDetectorTimerAscomcam -""" +# --- import guitastro_device_ascomcam +path = os.path.abspath(os.path.join(__file__, "..", "..")) +sys.path.append(path) if path not in sys.path else None +from guitastro_device_ascomcam import * isascom = True try: @@ -27,22 +27,6 @@ try: except: isascom = False -try: - # guitastro is installed with setup.py - # from guitastro import Ephemeris, Device - from guitastro import Device -except: - # guitastro is installed with only requirements.in - # guitastro_objcom_* folders must be copied at the same root folder than guitastro - pwd = os.getcwd() - short_paths = ['../../../guitastro/src', '..'] - for short_path in short_paths: - path = os.path.abspath(os.path.join(pwd, short_path)) - if path not in sys.path: - sys.path.insert(0, path) - from guitastro.device import Device - #from guitastro.ephemeris import Ephemeris - # ##################################################################### # ##################################################################### # ##################################################################### -- libgit2 0.21.2