diff --git a/src/Scripts/AScript.py b/src/Scripts/AScript.py new file mode 100644 index 00000000..ab8bf735 --- /dev/null +++ b/src/Scripts/AScript.py @@ -0,0 +1,34 @@ +# AScript.py -- Pamhyr abstract script class +# Copyright (C) 2023 INRAE +# +# This program 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. +# +# This program 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 this program. If not, see . + +# -*- coding: utf-8 -*- + +from Model.Except import NotImplementedMethodeError + +class AScript(object): + name = "" + description = "" + + def __init__(self, args): + super(AScript, self).__init__() + + self._args = args.copy() + + def usage(self): + raise NotImplementedMethodeError(self, self.usage) + + def run(self): + raise NotImplementedMethodeError(self, self.run) diff --git a/src/Scripts/Hello.py b/src/Scripts/Hello.py new file mode 100644 index 00000000..dd20e431 --- /dev/null +++ b/src/Scripts/Hello.py @@ -0,0 +1,34 @@ +# help.py -- Pamhyr +# Copyright (C) 2023 INRAE +# +# This program 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. +# +# This program 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 this program. If not, see . + +# -*- coding: utf-8 -*- + +import logging +from Scripts.AScript import AScript + +logger = logging.getLogger() + + +class ScriptHello(AScript): + name = "Hello" + description = "Display hello" + + def usage(self): + logger.info(f"Usage : {self._args[0]} hello") + + def run(self): + logger.info("Hello from Pamhyr2 script !") + return True diff --git a/src/pamhyr.py b/src/pamhyr.py index c2a7d938..61424fe8 100755 --- a/src/pamhyr.py +++ b/src/pamhyr.py @@ -34,10 +34,25 @@ from tools import ( from View.MainWindow import ApplicationWindow from Model.Study import Study +from Scripts.Hello import ScriptHello + from init import license, setup_lang logger = logging.getLogger() +scripts = { + "hello": ScriptHello, +} + +def usage(argv): + logger.error(f"{logger_color_red()}Invalid script name '{argv[1]}'{logger_color_reset()}") + logger.info(f"Usage: {argv[0]}