def __init__(self,
                 name: str,
                 wkflow_dir: Path,
                 cpacs_in: Path = None,
                 cpacs_out: Path = None) -> None:

        # Check module name validity
        accepted_names = get_submodule_list() + OPTIM_METHOD
        if name not in accepted_names:
            raise ValueError(f"Module '{name}' did not exit!")

        # Check workflow directory exist
        if not wkflow_dir.exists():
            raise FileNotFoundError(f"{str(wkflow_dir)} did not exist!")

        # Main attributes
        self.name = name
        self.wkflow_dir = wkflow_dir
        self.cpacs_in = cpacs_in
        self.cpacs_out = cpacs_out

        # Set module path
        self.module_dir = Path.joinpath(LIB_DIR, self.name)

        # Set other default values
        self.is_settinggui = False
        self.gui_related_modules = []
        self.is_optim_module = False
        self.optim_method = None
        self.optim_related_modules = []
Esempio n. 2
0
def test_get_submodule_list():
    """
    Test 'get_submodule_list()' function
    """

    submodule_list = m.get_submodule_list()
    for submod_name in submodule_list:
        assert len(submod_name.split('.')) == 1
Esempio n. 3
0
def get_results_directory(module_name: str) -> Path:
    """Create (if not exists) and return the results directory for a module"""

    if module_name not in get_submodule_list():
        raise ValueError(f"Module '{module_name}' did not exit!")

    specs = importlib.import_module(f"ceasiompy.{module_name}.__specs__")
    results_dir = Path(Path.cwd(), specs.RESULTS_DIR)

    if not results_dir.is_dir():
        results_dir.mkdir(parents=True)

    return results_dir
Esempio n. 4
0
    def __init__(self, master, name, **kwargs):

        tk.Frame.__init__(self, master, **kwargs)

        self.name = name

        # Get list of available modules
        self.modules_list = mi.get_submodule_list()
        self.modules_list.sort()

        self.modules_list.remove('SettingsGUI')
        self.modules_list.insert(0, 'SettingsGUI')

        self.modules_list.remove('CPACSUpdater')
        self.modules_list.remove('WorkflowCreator')
        self.modules_list.remove('utils')
        try:
            self.modules_list.remove('WKDIR')
        except:
            log.info('No WKDIR yet.')

        self.selected_list = []

        row_pos = 0

        if name == 'Optim':

            label_optim = tk.Label(self, text='Optimisation method')
            label_optim.grid(column=0, row=0, columnspan=1, pady=10)

            # The Combobox is directly use as the varaible
            optim_choice = ['None', 'DoE', 'Optim']
            self.optim_choice_CB = ttk.Combobox(self,
                                                values=optim_choice,
                                                width=15)
            self.optim_choice_CB.grid(column=4, row=row_pos)
            row_pos += 1

        # ListBox with all available modules
        tk.Label(self, text='Available modules').grid(column=0,
                                                      row=row_pos,
                                                      pady=5)
        self.LB_modules = tk.Listbox(self,
                                     selectmode=tk.SINGLE,
                                     width=25,
                                     height=len(self.modules_list))
        item_count = len(self.modules_list)
        self.LB_modules.grid(column=0,
                             row=row_pos + 1,
                             columnspan=3,
                             rowspan=15,
                             padx=10,
                             pady=3)
        for item in self.modules_list:
            self.LB_modules.insert(tk.END, item)

        # Button
        addButton = tk.Button(self, text='   Add >   ', command=self._add)
        addButton.grid(column=4, row=row_pos + 1)
        removeButton = tk.Button(self, text='< Remove', command=self._remove)
        removeButton.grid(column=4, row=row_pos + 2)
        upButton = tk.Button(self, text='    Up  ^   ', command=self._up)
        upButton.grid(column=4, row=row_pos + 3)
        downButton = tk.Button(self, text='  Down v  ', command=self._down)
        downButton.grid(column=4, row=row_pos + 4)

        # ListBox with all selected modules
        tk.Label(self, text='Selected modules').grid(column=5, row=row_pos)
        self.LB_selected = tk.Listbox(self,
                                      selectmode=tk.SINGLE,
                                      width=25,
                                      height=len(self.modules_list))
        self.LB_selected.grid(column=5,
                              row=row_pos + 1,
                              columnspan=3,
                              rowspan=15,
                              padx=10,
                              pady=3)
        for item in self.selected_list:
            self.LB_selected.insert(tk.END, item)
            row_pos += (item_count + 1)
def run_subworkflow(module_to_run, cpacs_path_in='', cpacs_path_out=''):
    """Function to run a list of module in order.

    Function 'run_subworkflow' will exectute in order all the module contained
    in 'module_to_run' list. Every time the resuts of one module (generaly CPACS
    file) will be copied as input for the next module.

    Args:
        module_to_run (list): List of mododule to run (in order)
        cpacs_path_in (str): Path of the CPACS file use, if not already in the
                             ToolInput folder of the first submodule
        cpacs_path_out (str): Path of the output CPACS file use, if not already
                              in the ToolInput folder of the first submodule

    """

    if not module_to_run:
        log.info('No module to run')
        return 0

    # Check non existing module
    submodule_list = mi.get_submodule_list()
    for module in module_to_run:
        if module not in submodule_list:
            raise ValueError('No module named "' + module + '"!')

    # Copy the cpacs file in the first module
    if cpacs_path_in:
        shutil.copy(cpacs_path_in,
                    mi.get_toolinput_file_path(module_to_run[0]))

    log.info('The following modules will be executed: ')
    for module in module_to_run:
        log.info(module)

    for m, module in enumerate(module_to_run):

        log.info(
            '######################################################################################'
        )
        log.info('Run module: ' + module)
        log.info(
            '######################################################################################'
        )

        # Go to the module directory
        module_path = os.path.join(LIB_DIR, module)
        log.info('Going to ' + module_path)
        os.chdir(module_path)

        # Copy CPACS file from previous module to this one
        if m > 0:
            copy_module_to_module(module_to_run[m - 1], 'out', module, 'in')

        if module == 'SettingsGUI':
            cpacs_path = mi.get_toolinput_file_path(module)
            cpacs_out_path = mi.get_tooloutput_file_path(module)

            # Check if there is at least one other 'SettingsGUI' after this one
            if 'SettingsGUI' in module_to_run[m + 1:] and m + 1 != len(
                    module_to_run):
                idx = module_to_run.index('SettingsGUI', m + 1)
                create_settings_gui(cpacs_path, cpacs_out_path,
                                    module_to_run[m:idx])
            else:
                create_settings_gui(cpacs_path, cpacs_out_path,
                                    module_to_run[m:])
        else:
            # Find the python file to run
            for file in os.listdir(module_path):
                if file.endswith('.py'):
                    if not file.startswith('__'):
                        main_python = file

            # Run the module
            error = subprocess.call(['python', main_python])

            if error:
                raise ValueError('An error ocured in the module ' + module)

    # Copy the cpacs file in the first module
    if cpacs_path_out:
        shutil.copy(mi.get_tooloutput_file_path(module_to_run[-1]),
                    cpacs_path_out)
Esempio n. 6
0
    root = tk.Tk()
    root.title('CEASIOMpy Settings GUI')
    root.geometry('600x900+400+50')
    my_setting_gui = SettingGUI(root, cpacs_path, cpacs_out_path, submodule_list)
    my_setting_gui.mainloop()
    root.iconify()
    root.destroy()


#==============================================================================
#    MAIN
#==============================================================================

if __name__ == '__main__':

    log.info('----- Start of ' + os.path.basename(__file__) + ' -----')

    cpacs_path = os.path.join(MODULE_DIR,'ToolInput','ToolInput.xml')
    cpacs_out_path = os.path.join(MODULE_DIR,'ToolOutput','ToolOutput.xml')

    # Call the function which check if imputs are well define
    mif.check_cpacs_input_requirements(cpacs_path)

    # Get the complete submodule
    submodule_list = mif.get_submodule_list()

    create_settings_gui(cpacs_path, cpacs_out_path, submodule_list)

    log.info('----- End of ' + os.path.basename(__file__) + ' -----')
    def __init__(self, master, name, **kwargs):

        tk.Frame.__init__(self, master, **kwargs)

        self.name = name

        # Get list of available modules
        self.modules_list = mi.get_submodule_list()
        self.modules_list.sort()

        self.modules_list.remove("SettingsGUI")
        self.modules_list.insert(0, "SettingsGUI")

        self.modules_list.remove("CPACSUpdater")
        self.modules_list.remove("WorkflowCreator")
        self.modules_list.remove("utils")

        # TODO: remove that when WKDIR is completly out of /ceasiompy/
        try:
            self.modules_list.remove("WKDIR")
        except:
            log.info("No WKDIR yet.")

        self.selected_list = []

        row_pos = 0

        if name == "Optimisation":

            label_optim = tk.Label(self, text="Optimisation method")
            label_optim.grid(column=0, row=0, columnspan=1, pady=10)

            # The Combobox is directly use as the varaible
            optim_choice = ["None", "DOE", "OPTIM"]
            self.optim_choice_CB = ttk.Combobox(self,
                                                values=optim_choice,
                                                width=15)
            self.optim_choice_CB.grid(column=4, row=row_pos)
            row_pos += 1

        # ListBox with all available modules
        tk.Label(self, text="Available modules").grid(column=0,
                                                      row=row_pos,
                                                      pady=5)
        self.LB_modules = tk.Listbox(self,
                                     selectmode=tk.SINGLE,
                                     width=25,
                                     height=len(self.modules_list))
        item_count = len(self.modules_list)
        self.LB_modules.grid(column=0,
                             row=row_pos + 1,
                             columnspan=3,
                             rowspan=15,
                             padx=10,
                             pady=3)
        for item in self.modules_list:
            self.LB_modules.insert(tk.END, item)

        # Button
        addButton = tk.Button(self, text="   Add >   ", command=self._add)
        addButton.grid(column=4, row=row_pos + 1)
        removeButton = tk.Button(self, text="< Remove", command=self._remove)
        removeButton.grid(column=4, row=row_pos + 2)
        upButton = tk.Button(self, text="    Up  ^   ", command=self._up)
        upButton.grid(column=4, row=row_pos + 3)
        downButton = tk.Button(self, text="  Down v  ", command=self._down)
        downButton.grid(column=4, row=row_pos + 4)

        # ListBox with all selected modules
        tk.Label(self, text="Selected modules").grid(column=5, row=row_pos)
        self.LB_selected = tk.Listbox(self,
                                      selectmode=tk.SINGLE,
                                      width=25,
                                      height=len(self.modules_list))
        self.LB_selected.grid(column=5,
                              row=row_pos + 1,
                              columnspan=3,
                              rowspan=15,
                              padx=10,
                              pady=3)
        for item in self.selected_list:
            self.LB_selected.insert(tk.END, item)
            row_pos += item_count + 1