Commit e36f962e4520a432a7b67079ff63aabd136c52d5
1 parent
bac5d5e7
Exists in
dev
option "-d" (DEBUG) pour le script pyros.py (+ petit bugfix logpyros)
=> permet de lancer un agent en mode debug Il faut maintenant faire passer correctement cette option dans toutes les classes..
Showing
6 changed files
with
55 additions
and
32 deletions
Show diff stats
pyros.py
... | ... | @@ -224,21 +224,25 @@ GLOBAL_OPTIONS = {} |
224 | 224 | def verbose_mode(): return GLOBAL_OPTIONS["verbose"] |
225 | 225 | def test_mode(): return GLOBAL_OPTIONS["test"] |
226 | 226 | def sim_mode(): return GLOBAL_OPTIONS["sim"] |
227 | +def debug_mode(): return GLOBAL_OPTIONS["debug"] | |
227 | 228 | |
228 | 229 | @click.group() |
229 | -@click.option('--test', '-t', is_flag=True, help="don't do it for real, just show what it would do") | |
230 | +@click.option('--debug', '-d', is_flag=True, help='DEBUG mode') | |
230 | 231 | @click.option('--sim', '-s', is_flag=True, help="only for an AgentDevice, asking it to start its simulator and work with it (instead of real device)") |
232 | +@click.option('--test', '-t', is_flag=True, help="don't do it for real, just show what it would do") | |
231 | 233 | @click.option('--verbose', '-v', is_flag=True, help='Verbose output') |
232 | 234 | #@click.option('--verbose', '-v', 'verbosity', flag_value=2, default=1, help='Verbose output'), |
233 | 235 | #@click.option('--quiet', '-q', 'verbosity', flag_value=0, help='Minimal output'), |
234 | 236 | #@click.option('--fail-fast', '--failfast', '-f', 'fail_fast', is_flag=True, default=False, help='Stop on failure'), |
235 | -def pyros_launcher(test, sim, verbose): | |
237 | +def pyros_launcher(debug, sim, test, verbose): | |
236 | 238 | #pass |
239 | + if debug: click.echo('DEBUG mode') | |
240 | + if sim: click.echo('Starting and connecting to simulator instead of real device') | |
237 | 241 | if test: click.echo('Test mode') |
238 | - if test: click.echo('Starting and connecting to simulator instead of real device') | |
239 | 242 | if verbose: click.echo('Verbose mode') |
240 | - GLOBAL_OPTIONS["test"] = test | |
243 | + GLOBAL_OPTIONS["debug"] = debug | |
241 | 244 | GLOBAL_OPTIONS["sim"] = sim |
245 | + GLOBAL_OPTIONS["test"] = test | |
242 | 246 | GLOBAL_OPTIONS["verbose"] = verbose |
243 | 247 | |
244 | 248 | |
... | ... | @@ -474,8 +478,10 @@ def start(agent:str, configfile:str): |
474 | 478 | #cmd = "-m AgentX" |
475 | 479 | #cmd = f" Agent{agent_name[5:]}.py {configfile}" |
476 | 480 | cmd = f"Agent{agent_name[5:]}.py" |
477 | - if test_mode(): cmd += " -t" | |
481 | + if debug_mode(): cmd += " -d" | |
478 | 482 | if sim_mode(): cmd += " -s" |
483 | + if test_mode(): cmd += " -t" | |
484 | + if verbose_mode(): cmd += " -v" | |
479 | 485 | if configfile: cmd += " {configfile}" |
480 | 486 | |
481 | 487 | #if not test_mode(): current_processes.append( [execProcessFromVenvAsync(cmd), agent_name, -1] ) | ... | ... |
src/core/pyros_django/agent/Agent.py
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | |
3 | 3 | VERSION = "0.5" |
4 | 4 | |
5 | -DEBUG=True | |
5 | +#DEBUG=True | |
6 | 6 | #DEBUG=False |
7 | 7 | |
8 | 8 | """TODO: |
... | ... | @@ -219,6 +219,11 @@ class Agent: |
219 | 219 | # --- - INSTANCE attributes are accessible via agent.__dict__ |
220 | 220 | # --- |
221 | 221 | |
222 | + # Default modes | |
223 | + DEBUG_MODE = False | |
224 | + WITH_SIMULATOR = False | |
225 | + TEST_MODE = False | |
226 | + | |
222 | 227 | # To be overriden by subclasses (empty by default, no agent specific command) |
223 | 228 | AGENT_SPECIFIC_COMMANDS = [ |
224 | 229 | #"do_eval", |
... | ... | @@ -384,11 +389,13 @@ class Agent: |
384 | 389 | _log = None |
385 | 390 | |
386 | 391 | #def __init__(self, name:str="Agent", config_filename:str=None, RUN_IN_THREAD=True): |
387 | - def __init__(self, config_filename:str=None, RUN_IN_THREAD=True): | |
392 | + def __init__(self, config_filename:str=None, RUN_IN_THREAD=True, DEBUG_MODE=False): | |
388 | 393 | #self.name = name |
389 | 394 | self.name = self.__class__.__name__ |
390 | - self._log = LogPyros(self.name,AgentLogs) | |
391 | - self._log.debug_level = DEBUG | |
395 | + self.DEBUG_MODE = DEBUG_MODE | |
396 | + self._log = LogPyros(self.name, AgentLogs) | |
397 | + self._log.debug_level = DEBUG_MODE | |
398 | + self.printd("LOG DEBUG LEVEL IS:", self._log.debug_level) | |
392 | 399 | |
393 | 400 | # New way with PathLib |
394 | 401 | my_parent_abs_dir = Path(__file__).resolve().parent |
... | ... | @@ -414,7 +421,7 @@ class Agent: |
414 | 421 | config_filename = config_filename.replace(os.sep+"monitoring"+os.sep, os.sep) |
415 | 422 | config_filename = os.path.normpath(config_filename) |
416 | 423 | ''' |
417 | - self.printd(f"Config file used is={config_filename}") | |
424 | + self.printd(f"*** Config file used is={config_filename}") | |
418 | 425 | self.config = ConfigPyros(config_filename) |
419 | 426 | if self.config.get_last_errno() != self.config.NO_ERROR: |
420 | 427 | raise Exception(f"Bad config file name '{config_filename}', error {str(self.config.get_last_errno())}: {str(self.config.get_last_errmsg())}") |
... | ... | @@ -523,7 +530,7 @@ class Agent: |
523 | 530 | # TEST MODE ONLY |
524 | 531 | # IF in test mode but with REAL devices (no SIMULATOR), delete all dangerous commands from the test commands list scenario: |
525 | 532 | if self.TEST_MODE: |
526 | - print("\n!!! In TEST mode !!! => preparing to run a scenario of test commands") | |
533 | + self.printd("\n!!! In TEST mode !!! => preparing to run a scenario of test commands") | |
527 | 534 | print("- Current test commands list scenario is:\n", self.TEST_COMMANDS_LIST) |
528 | 535 | if not self.WITH_SIMULATOR: |
529 | 536 | print("\n!!! In TEST but no SIMULATOR mode (using REAL device) !!! => removing dangerous commands for real devices... :") |
... | ... | @@ -1272,11 +1279,12 @@ class Agent: |
1272 | 1279 | ================================================================= |
1273 | 1280 | """ |
1274 | 1281 | |
1275 | - #def setSimulatorMode(self, mode): | |
1276 | - def _set_test_mode(self, mode:bool): | |
1277 | - self.TEST_MODE=mode | |
1282 | + def _set_debug_mode(self, mode:bool): | |
1283 | + self.DEBUG_MODE=mode | |
1278 | 1284 | def _set_with_simulator(self, mode:bool): |
1279 | 1285 | self.WITH_SIMULATOR=mode |
1286 | + def _set_test_mode(self, mode:bool): | |
1287 | + self.TEST_MODE=mode | |
1280 | 1288 | |
1281 | 1289 | def _TEST_get_next_command_to_send(self)->Command: |
1282 | 1290 | cmd_full_name = next(self.TEST_COMMANDS, None) |
... | ... | @@ -1437,7 +1445,7 @@ class Agent: |
1437 | 1445 | for cmd_get in commands_after: |
1438 | 1446 | if cmd_get.name.startswith('get_') and cmd_get.name[4:]==cmd_set.name[4:] and cmd_get.device_type==cmd_set.device_type: |
1439 | 1447 | print("cmd_get.result == cmd_set.args ?", cmd_get.result, cmd_set.args) |
1440 | - assert cmd_get.get_result() == ','.join(cmd_set.args) | |
1448 | + assert cmd_get.get_result() == ','.join(cmd_set.args), "A get_xx command did not gave the expected result as set by a previous set_xx command" | |
1441 | 1449 | break |
1442 | 1450 | |
1443 | 1451 | # Specific (detailed) test (to be overriden by subclass) |
... | ... | @@ -1515,13 +1523,17 @@ def extract_parameters(): |
1515 | 1523 | """ Usage: Agent.py [-t] [configfile] """ |
1516 | 1524 | # arg 1 : -t |
1517 | 1525 | # arg 2 : configfile |
1526 | + DEBUG_MODE = False | |
1518 | 1527 | TEST_MODE = False |
1519 | 1528 | WITH_SIM = False |
1529 | + VERBOSE_MODE = False | |
1520 | 1530 | configfile = None |
1521 | 1531 | print("args:", sys.argv) |
1522 | 1532 | for arg in sys.argv[1:] : |
1523 | 1533 | if arg == "-t": TEST_MODE = True |
1524 | 1534 | elif arg == "-s": WITH_SIM = True |
1535 | + elif arg == "-d": DEBUG_MODE = True | |
1536 | + elif arg == "-v": VERBOSE_MODE = True | |
1525 | 1537 | else: configfile = arg |
1526 | 1538 | ''' |
1527 | 1539 | if len(sys.argv) > 1: |
... | ... | @@ -1532,17 +1544,17 @@ def extract_parameters(): |
1532 | 1544 | else: |
1533 | 1545 | configfile = sys.argv[1] |
1534 | 1546 | ''' |
1535 | - return TEST_MODE, WITH_SIM, configfile | |
1547 | + return DEBUG_MODE, WITH_SIM, TEST_MODE, VERBOSE_MODE, configfile | |
1536 | 1548 | |
1537 | 1549 | #def build_agent(Agent_type:Agent, name="GenericAgent", RUN_IN_THREAD=True): |
1538 | 1550 | def build_agent(Agent_type:Agent, RUN_IN_THREAD=True): |
1539 | - TEST_MODE, WITH_SIM, configfile = extract_parameters() | |
1551 | + DEBUG_MODE, WITH_SIM, TEST_MODE, VERBOSE_MODE, configfile = extract_parameters() | |
1540 | 1552 | #agent = Agent("GenericAgent", configfile, RUN_IN_THREAD=True) |
1541 | - agent = Agent_type(configfile, RUN_IN_THREAD) | |
1553 | + agent = Agent_type(configfile, RUN_IN_THREAD, DEBUG_MODE=DEBUG_MODE) | |
1542 | 1554 | #agent = Agent_type(name, configfile, RUN_IN_THREAD) |
1543 | - #agent.setSimulatorMode(TEST_MODE) | |
1544 | - agent._set_test_mode(TEST_MODE) | |
1545 | 1555 | agent._set_with_simulator(WITH_SIM) |
1556 | + agent._set_test_mode(TEST_MODE) | |
1557 | + #agent._set_debug_mode(DEBUG_MODE) | |
1546 | 1558 | return agent |
1547 | 1559 | |
1548 | 1560 | ... | ... |
src/core/pyros_django/agent/AgentDevice.py
... | ... | @@ -89,10 +89,10 @@ class AgentDevice(Agent): |
89 | 89 | #def __init__(self, name:str=None, config_filename=None, RUN_IN_THREAD=True, device_controller, host, port): |
90 | 90 | #def __init__(self, name:str, config_filename, RUN_IN_THREAD, device_controller, host, port, device_simulator): |
91 | 91 | ##def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceController, host, port, device_simulator): |
92 | - def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceController, host, port): | |
92 | + def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceController, host, port, DEBUG_MODE=False): | |
93 | 93 | ##if name is None: name = self.__class__.__name__ |
94 | 94 | #super().__init__(name, config_filename, RUN_IN_THREAD) |
95 | - super().__init__(config_filename, RUN_IN_THREAD) | |
95 | + super().__init__(config_filename, RUN_IN_THREAD, DEBUG_MODE) | |
96 | 96 | self.HOST, self.PORT = host, port |
97 | 97 | self._device_ctrl = device_controller |
98 | 98 | ##self._device_sim = device_simulator |
... | ... | @@ -139,7 +139,7 @@ class AgentDevice(Agent): |
139 | 139 | |
140 | 140 | # Create instance of device controller (device client) |
141 | 141 | # Ex: this can be the Gemini or the SBIG (...) DC |
142 | - self._device_ctrl = self._device_ctrl(self.HOST, self.PORT, True) | |
142 | + self._device_ctrl = self._device_ctrl(self.HOST, self.PORT, DEBUG=True) | |
143 | 143 | |
144 | 144 | # Device socket init |
145 | 145 | # (optional) Only useful for TCP (does nothing for UDP) | ... | ... |
src/core/pyros_django/agent/AgentDeviceGemini.py
... | ... | @@ -64,7 +64,7 @@ class AgentDeviceGemini(AgentDevice): |
64 | 64 | """ |
65 | 65 | |
66 | 66 | # @override |
67 | - def __init__(self, config_filename=None, RUN_IN_THREAD=True): | |
67 | + def __init__(self, config_filename=None, RUN_IN_THREAD=True, DEBUG_MODE=False): | |
68 | 68 | ''' |
69 | 69 | if self.is_in_simulator_mode() and not self.WITH_SIMULATOR: |
70 | 70 | # START device SIMULATOR (in a thread) so that we can connect to it in place of the real device |
... | ... | @@ -77,7 +77,8 @@ class AgentDeviceGemini(AgentDevice): |
77 | 77 | config_filename, |
78 | 78 | RUN_IN_THREAD, |
79 | 79 | device_controller=DC_Gemini, |
80 | - host=self.HOST, port=self.PORT) | |
80 | + host=self.HOST, port=self.PORT, | |
81 | + DEBUG_MODE=DEBUG_MODE) | |
81 | 82 | ###device_simulator=DeviceSimulatorTelescopeGemini) |
82 | 83 | |
83 | 84 | # Initialize the device table status | ... | ... |
src/core/pyros_django/agent/logpyros.py
... | ... | @@ -130,16 +130,16 @@ class LogPyros: |
130 | 130 | # ===================================================================== |
131 | 131 | |
132 | 132 | def _set_debug_level(self, level:str): |
133 | - if type(level)=="bool": | |
133 | + if type(level).__name__=="bool": | |
134 | 134 | if level==True: |
135 | 135 | level = 1 |
136 | 136 | else: |
137 | 137 | level = 0 |
138 | 138 | self._debug_level = level |
139 | - | |
139 | + | |
140 | 140 | def _get_debug_level(self): |
141 | 141 | return self._debug_level |
142 | - | |
142 | + | |
143 | 143 | def _set_agent_alias(self, agent_alias:str): |
144 | 144 | if agent_alias=="": |
145 | 145 | self._last_errno = self.ERR_ALIAS_NAME_NOT_DEFINED |
... | ... | @@ -227,7 +227,7 @@ class LogPyros: |
227 | 227 | # Methods for users |
228 | 228 | # ===================================================================== |
229 | 229 | # ===================================================================== |
230 | - | |
230 | + | |
231 | 231 | def print(self, *args, **kwargs): |
232 | 232 | """ |
233 | 233 | This is the method to print in the console display and in a log file. |
... | ... | @@ -254,9 +254,9 @@ class LogPyros: |
254 | 254 | """ |
255 | 255 | Same as print method but only if debug level is > threashold |
256 | 256 | """ |
257 | - if self.debug_level > 0: | |
257 | + if self._debug_level > 0: | |
258 | 258 | self.print(*args, **kwargs) |
259 | - | |
259 | + | |
260 | 260 | def file(self, *args, **kwargs): |
261 | 261 | """ |
262 | 262 | This is the method to print in a log file. | ... | ... |
src/device_controller/concrete_component/gemini/gemini_controller.py
... | ... | @@ -303,7 +303,8 @@ class DC_Gemini(DeviceController): |
303 | 303 | |
304 | 304 | # Gemini is using UDP |
305 | 305 | #def __init__(self, device_host:str="localhost", device_port:int=11110, channel=socket, DEBUG=False): |
306 | - def __init__(self, device_host:str="localhost", device_port:int=11110, DEBUG=False): | |
306 | + #def __init__(self, device_host:str="localhost", device_port:int=11110, DEBUG=False): | |
307 | + def __init__(self, device_host:str="localhost", device_port:int=11110, dcc_list=[], DEBUG=False): | |
307 | 308 | ##super().__init__(device_host, device_port, "SOCKET-UDP", 1024, DEBUG) |
308 | 309 | super().__init__(device_host, device_port, "SOCKET-UDP", MY_DEVICE_CHANNEL_BUFFER_SIZE, protoc=self.Protocol, gen2nat_cmds=self.GEN2NAT_CMDS, device_sim=DS_Gemini, DEBUG=DEBUG) |
309 | 310 | |
... | ... | @@ -316,6 +317,9 @@ class DC_Gemini(DeviceController): |
316 | 317 | - NO SIMULATOR (because my dccs will use the same as me and I have already launched it), |
317 | 318 | - DEBUG |
318 | 319 | ''' |
320 | + # TODO: utiliser dcc_list | |
321 | + # Default list of DCCs (if not given) | |
322 | + if not dcc_list: dcc_list = [DC_Mount, DC_MountBis] | |
319 | 323 | # @override superclass empty list of dc components |
320 | 324 | self.set_dc_components( |
321 | 325 | [ | ... | ... |