mirror of https://gitlab.com/pamhyr/pamhyr2
Script: Add pamhyr2 script with exemple hello.
parent
75066fa61a
commit
d4568ddbb5
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# -*- 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)
|
||||||
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# -*- 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
|
||||||
|
|
@ -34,10 +34,25 @@ from tools import (
|
||||||
from View.MainWindow import ApplicationWindow
|
from View.MainWindow import ApplicationWindow
|
||||||
from Model.Study import Study
|
from Model.Study import Study
|
||||||
|
|
||||||
|
from Scripts.Hello import ScriptHello
|
||||||
|
|
||||||
from init import license, setup_lang
|
from init import license, setup_lang
|
||||||
|
|
||||||
logger = logging.getLogger()
|
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]} <script> <args...>")
|
||||||
|
logger.info(f"")
|
||||||
|
logger.info(f"Valid scripts:")
|
||||||
|
for s in scripts:
|
||||||
|
logger.info(f"\t{s}\t\t{scripts[s].name}: {scripts[s].description}")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
conf = Config.load()
|
conf = Config.load()
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|
@ -47,10 +62,24 @@ def main():
|
||||||
|
|
||||||
license()
|
license()
|
||||||
|
|
||||||
application = ApplicationWindow(conf=conf)
|
if len(sys.argv) > 1:
|
||||||
application.show()
|
# Run a script
|
||||||
|
script = sys.argv[1]
|
||||||
|
|
||||||
|
if script not in scripts:
|
||||||
|
usage(sys.argv)
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
|
application = scripts[script](sys.argv)
|
||||||
|
ret = application.run()
|
||||||
|
if not ret:
|
||||||
|
application.usage()
|
||||||
|
else:
|
||||||
|
# No args, run Pamhyr2 interface
|
||||||
|
application = ApplicationWindow(conf=conf)
|
||||||
|
application.show()
|
||||||
|
ret = app.exec_()
|
||||||
|
|
||||||
ret = app.exec_()
|
|
||||||
display_timers()
|
display_timers()
|
||||||
sys.exit(ret)
|
sys.exit(ret)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue