Example #1
0
def run_damocles(exe_path, parame_file, log_file=''):
    """
       Running the damocles executable

       @param exe_path Path the damocles executable
       @param parame_file Path to the input aprameters file
       @param log_file Redirecting ouput to that file if present
    """
    if not path.exists(exe_path):
        raise TelemacException("You need to compile damocles to use it...")
    # Run Fortran program
    mes = Messages(size=10)
    try:
        if log_file == '':
            print("%s < %s " % (exe_path, parame_file))
            _, code = mes.run_cmd("%s < %s" % (exe_path, parame_file), False)
        else:
            print("%s < %s > %s" % (exe_path, parame_file, log_file))
            _, code = mes.run_cmd(
                "%s < %s > %s" % (exe_path, parame_file, log_file), False)
    except OSError as exc:
        raise TelemacException(exc.strerror)
    if code != 0:
        raise TelemacException([\
              {'name':'damocles',
               'msg':'Could not execute damocles'\
                     +'\n\nHere is the log:\n'
                     +'\n'.join(get_file_content(log_file))
              }])
def generate_notebook_pdf(doc_dir, notebook_dir):
    """
    Generate an html layout of the notebooks using ipython nbconvert
    Than coying back the file into doc_dir

    @param doc_dir (string) Path to the folder that will contain the html
                            version of the docuemntation
    @param notebook_dir (string) Path to the notebooks
    """
    # Creating doc folder if necessary
    if not path.exists(doc_dir):
        mkdir(doc_dir)

    # Running convertion in notebook folder
    # Gathering all html files
    for root, _, files in walk(notebook_dir):
        for ffile in files:
            if ffile.endswith("ipynb"):
                # Skipping notebook tmp folders
                if ".ipynb_checkpoint" in root:
                    continue
                notebook = path.join(root, ffile)
                cmd = "jupyter nbconvert --to pdf --output-dir={} {}"\
                       .format(doc_dir, notebook)
                print("   ~> Converting "+ffile)
                # Running convertion
                mes = Messages(size=10)
                tail, code = mes.run_cmd(cmd, bypass=False)

                if code != 0:
                    raise TelemacException('nbconvert failed\n {}'.format(tail))
Example #3
0
def run_gredel(gredel, gredel_file, geom, gredel_type, ncsize, bypass):
    """
    @brief Runs GREDEL, the functions that merge Delwaq results

    @param gredel (string): the path of gredel
    @param gredel_file (string): the name of the GREDEL file
    @param geom (string): the name of the geometry file
    @param gredel_type (string): XXX
    @param ncsize (int): the number of processors
    @param bypass (boolean): continue execution after exception was
        raised if True, kill the execution otherwise

    @return None
    """

    # ~~ Change GRETEL into GREDEL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    path_gredel = path.dirname(gredel)
    _, ext_gredel = path.splitext(path.basename(gredel))
    gredel = path.join(path_gredel,
                       'gredel' + gredel_type.lower() + '_autop' + ext_gredel)
    # ~~ Run GREDEL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    gredel_par = 'gretel_' + gredel_file + '.par'
    gredel_log = 'gretel_' + gredel_file + '.log'
    put_file_content(gredel_par, [geom, gredel_file, str(ncsize)])
    mes = Messages(size=10)
    cmd = '{} < {} >> {}'.format(gredel, gredel_par, gredel_log)

    tail, code = mes.run_cmd(cmd, bypass)
    if code != 0:
        raise TelemacException('Could not split your file (runcode=' +
                               str(code) + ').\n      ' + gredel_file +
                               '\n        ' + tail)
Example #4
0
def generate_ref_from_dict(exe_path, dictionary, latex_file, lng, cleanup,
                           verbose):
    """
    @brief Generate the Latex file for the
            reference manual from the dictionary

    @param exe_path (string) Path to homere_damocles executable
    @param dictionary (string) Path to the dictionary to read
    @param latex_file (string) Name of the outpu latex file that will
                         contain the reference manual
    @param lng (int) Language for the reference manual
                 1: French
                 2: English
    @param cleanup (boolean) If True removing genrated files
    @param verbose (boolean) If True display command
    """
    # Building input parameter file
    latex_dir = path.dirname(latex_file)
    if not path.exists(latex_dir):
        mkdir(latex_dir)
    param_file = path.join(latex_dir, 'gen_ref.par')
    log_file = path.join(latex_dir, 'gen_ref.log')
    # Cleanup
    if cleanup:
        if path.exists(param_file):
            remove(param_file)
        if path.exists(log_file):
            remove(log_file)
        if path.exists(latex_file):
            remove(latex_file)
    else:
        # Creating parameter file for damocles
        with open(param_file, 'w') as f:
            f.write('LATEX' + '\n')
            f.write(dictionary + '\n')
            f.write(latex_file + '\n')
            f.write(lng + '\n')
        # Removing LaTeX file if already there
        if path.exists(latex_file):
            remove(latex_file)
        # Run Fortran program
        mes = Messages(size=10)
        if verbose:
            cmd = "{} < {}".format(exe_path, param_file)
        else:
            cmd = "{} < {} >{} 2>&1".format(exe_path, param_file, log_file)
        if verbose:
            print(cmd)
        _, code = mes.run_cmd(cmd, False)
        if code != 0:
            if verbose:
                log = ''
            else:
                log = '\n\nHere is the log:\n'\
                      + '\n'.join(get_file_content(log_file))
            raise TelemacException(\
                    'Could not generated data from dictionary '
                    + '{}'.format(log))
Example #5
0
def run_partel(partel, par_file, file_format, conlim, ncsize, bypass,
               section_name, zone_name, weir_name, geom, fmtgeom, i_part,
               concat):
    """
    @brief Runs PARTEL

    @param partel (string): the path of partel
    @param par_file (string): the name of the PARTEL file
    @param file_format (string): the format of the filee to partition
    @param conlim (string): the name of the *.cli file
    @param ncsize (int): the number of processors
    @param bypass (boolean): continue execution after exception was
        raised if True, kill the execution otherwise
    @param section_name (string): path to the section ascii input file. This
        file has to be split by partel at the same time as the geometry file.
        To do so, partel needs to know its name, which is why it is returned
        by process_lit.
    @param zone_name (string): path to the zone ascii input file. This file
        has the same treatment as the one above.
    @param weir_name (string): path to the weir ascii input file. This file
        has the same treatment as the one above.
    @param fmtgeom (string): format of the geometry file (serafin, serafind,
        med)
    @param i_part (int): type of partitionner, 1:metis; 2: scotch
    @param concat (boolean): If output is concatenate

    @return void
    """
    partel_input = 'partel_' + par_file + '.par'
    partel_log = 'partel_' + par_file + '.log'
    put_file_content(partel_input, [
        par_file, file_format, conlim,
        str(ncsize),
        str(i_part), section_name, zone_name, weir_name, geom, fmtgeom, concat,
        ''
    ])
    par_cmd = partel.replace('<partel.log>', partel_log)\
                    .replace('<partel.par>', partel_input).split(';')

    mes = Messages(size=10)
    for par in par_cmd:
        print('     +> ' + par)
        tail, code = mes.run_cmd(par, bypass)
        if code != 0:
            if path.exists(partel_log):
                log = "Here is the log:\n"+ \
                      '\n'.join(get_file_content(partel_log))
            else:
                log = "No log available check command:\n" + par_cmd
            raise TelemacException(\
                     'Could not split your file '+par_file\
                     +' with the error as follows:'\
                     +'\n        '+tail\
                     +'\n\n'+log)
Example #6
0
def run_gretel(gretel,
               gre_file,
               file_format,
               geom,
               geo_format,
               bnd,
               ncsize,
               nplan,
               method=1,
               bypass=False):
    """
    @brief Runs GRETEL, the functions that merges results

    @param gretel (string): the path of gredel
    @param gre_file (string): the name of the GRETEL file
    @param file_format (string): format of the GRETEL file
    @param geom (string): name of the geometry file
    @param geo_format (string): format of the geometry file
    @param bnd (string): name of the boundary file
    @param ncsize (int): number of processors
    @param nplan (int): number of vertical layers
    @param method (int): method for data merging
    @param bypass (boolean): continue execution after exception was
        raised if True, kill the execution otherwise

    @return None
    """

    # ~~ Run GRETEL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    gretel_par = 'gretel_' + gre_file + '.par'
    gretel_log = 'gretel_' + gre_file + '.log'
    put_file_content(gretel_par, [
        geom, geo_format, bnd, gre_file, file_format,
        str(ncsize),
        str(nplan),
        str(method)
    ])
    mes = Messages(size=10)
    cmd = '{} < {} >> {}'.format(gretel, gretel_par, gretel_log)
    print('     +> ' + cmd)
    tail, code = mes.run_cmd(cmd, bypass)
    if code != 0:
        if path.exists(gretel_log):
            log = "Here is the log:\n" + \
                  '\n'.join(get_file_content(gretel_log))
        else:
            log = "No log available check command:\n" + cmd
        raise TelemacException('Could not split your file ' + gre_file +
                               ' (runcode=' + str(code) +
                               ') with the error as follows:' + '\n        ' +
                               tail + '\n\n' + log)
 def __init__(self, user_id, name, email, pwd, phone_number) -> None:
     self.__user_id = user_id
     self.__name = name
     self.__email = email
     self.__pwd = pwd
     self.__phone_number = phone_number
     self.messages = Messages(name)
 def __init__(self, cf, model):
     self.cf = cf
     self.model = model
     self.logger_stats = Logger(cf.log_file_stats)
     self.stats = Statistics()
     self.msg = Messages()
     self.validator = self.validation(self.logger_stats, self.model, cf, self.stats, self.msg)
     self.trainer = self.train(self.logger_stats, self.model, cf, self.validator, self.stats, self.msg)
     self.predictor = self.predict(self.logger_stats, self.model, cf)
def compile_doxygen(doxy_file, verbose):
    """
    Compile a doxygen documentation

    @param doxy_file name of the doxygen file to use
    @param verbose If True display doxygen listing
    """

    doxy_dir = path.dirname(doxy_file)

    chdir(doxy_dir)
    if verbose:
        cmd = "doxygen {}".format(doxy_file)
    else:
        cmd = "doxygen {} >Doxygen_run.log 2>&1 ".format(doxy_file)

    print("   ~> Generating doxygen documentation for " + doxy_file)
    # Running convertion
    mes = Messages(size=10)
    tail, code = mes.run_cmd(cmd, bypass=False)

    if code != 0:
        if verbose:
            log = ''
        else:
            log = '\noutput:\n{}'.format(\
                    '\n'.join(get_file_content('Doxygen_run.log')[-20:]))
        raise TelemacException(\
            'Doxygen failed\n{}\n{}'\
            .format(tail, log))

    html_file = path.join(doxy_dir, 'html', 'index.html')

    print("   To see documentation run (replace firefox by your "\
          "internet browser):\n   firefox {}".format(html_file))

    doxy_warning_log = path.join(doxy_dir, 'Doxygen_warning.log')

    if stat(doxy_warning_log).st_size != 0:
        print('There seems to be some doxygen warnings see:\n{}'\
              .format(doxy_warning_log))
def process_executable(working_dir, pbin, plib, pobj, system, trace,
                       code_name):
    """
    @brief Process the excecutable including:
        - checking the presence and the validity of the current executable
        - if necessary, copying the FORTRAN files in the temporary directory
        - if necessary, compiling the FORTRAN into the executable
        The background of this function sits where the CAS file is

    @param cas (string):  Everything that touches the CAS file.
    @param pbin (string): Location of the default executables
    @param plib (string): location of the associated libs (and cmdx files)
    @param pobj (string): location of the associated objs (and cmdo files)
    @param trace:
    @param code_name (string): Name of the module

    @return exe_fort: name of the executable whether copied or compiled and a

    @note even in case of coupling, the principal executable remains
    @note possible fortran files may or may not be associated with the
        principal code and may be files or directories
    @note If the executable exist, and that the user fortran files have not
        changed and that the system has not been recompiled, then the executable
        remains valid
    @note The name of the executable is taken to be based on the name defined
        by the user, i.e. the name of the PRINCI whether it is a file or a
        directory.
    @note
        - exe_file: The name of the default executable as well as the system
          preference for that file extension
        - ori_file: The user define name of the executable, based on the name of
          the FORTRAN FILE whether a file or a directory.
        - use_name,obj_name,f90_name,obj_cmd,exe_cmd
    """
    # ~~ exception error, if any
    mes = Messages(size=10)
    # ~~ saving current location
    curdir = getcwd()
    # ~~ default executable (no user defined fortran file(s)
    exe_file = path.join(pbin, code_name + system['sfx_exe'])
    if not path.exists(exe_file):
        raise TelemacException(\
              '\nNot able to find your default executable: ' + \
              exe_file + '\n' + \
              '\n ... you have to compile this module at least: '+\
              code_name)

    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # ~~> All user fortran have been copied in user_fortran
    #
    ori_fort = []
    tmp_fortran_dir = path.join(working_dir, "user_fortran")
    if path.exists(tmp_fortran_dir):
        # Sort them to force order of compilation
        for f in sorted(listdir(tmp_fortran_dir)):
            # If we found a compiled file removing it
            if f.endswith(system['sfx_obj']):
                remove(path.join(tmp_fortran_dir, f))
            else:
                ori_fort.append(path.join(tmp_fortran_dir, f))

    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # ~~> Getting name of executable in working dir
    #
    # ~~ case of user fortran
    if ori_fort != []:
        # wir_fort working sub-directory, locally contain all user fortran files
        use_file = 'out_user_fortran' + system['sfx_exe']
    #
    # ~~ without user fortran
    else:
        # ~~ default executable
        use_file = 'out_' + code_name + system['sfx_exe']
    exe_fort = path.join(working_dir, use_file)

    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # copy the default executable
    if ori_fort == []:
        shutil.copy2(exe_file, exe_fort)

    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    else:
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # ~~> Compiling fortran file(s)
        # ~~ default command line for compilation of obects
        cmdo_file = path.join(pobj, code_name + '.cmdo')
        if not path.exists(cmdo_file):
            raise TelemacException(\
                  '\nNot able to find your OBJECT command line: ' + \
                  cmdo_file + '\n' + \
                  '\n ... you have to compile this module at least: '+\
                  code_name)
        obj_cmd = get_file_content(cmdo_file)[0]
        # ~~ make the keys portable (no full path)
        for k in trace:
            obj_cmd = obj_cmd.replace('[' + k + ']', path.normpath(trace[k]))
        # ~~ into local compilation
        chdir(tmp_fortran_dir)
        print('  > compiling objs')
        # ~~ compilation one file at a time
        objs = []
        # Reordonning user fortran to compile module first
        # Are considered modules files beginning the letter m
        user_files = []
        tmp = []
        for f90 in ori_fort:
            # /!\ TODO avoid using hard-coded explicit assumptions
            #             use get_principal_wrap_names(f90)[0], or better,
            # scan the local user tree
            if f90.lower()[0] == "m":
                user_files.append(f90)
            else:
                tmp.append(f90)
        user_files.extend(tmp)
        # Looping on ordered fortran files
        for f90 in user_files:
            print('         compiling: ' + path.basename(f90), end='')
            tail, code = mes.run_cmd(obj_cmd.replace('<f95name>', f90), False)
            if code != 0:
                raise TelemacException(\
                    'Could not compile your FORTRAN (runcode='+\
                     str(code)+').\n        '+tail)
            print(' ... completed')
            objs.append(path.splitext(f90)[0] + system['sfx_obj'])
        # ~~ default command line for linkage into an executable
        cmdx_file = path.join(plib, code_name + '.cmdx')
        if not path.exists(cmdx_file):
            raise TelemacException(\
                 '\nNot able to find your EXECUTE command line: '\
                 + cmdx_file + '\n'\
                 + '\n ... you have to compile this module '\
                 'at least: ' + code_name)
        exe_cmd = get_file_content(cmdx_file)[0]
        # ~~ make the keys portable (no full path)
        for k in trace:
            exe_cmd = exe_cmd.replace('[' + k + ']', path.normpath(trace[k]))
        exe_cmd = exe_cmd.replace('<objs>', ' '.join(objs))\
                            .replace('<exename>', '"'+exe_fort+'"')
        tail, code = mes.run_cmd(exe_cmd, False)
        if code != 0:
            raise TelemacException(\
                 'Could not link your executable (runcode='+\
                 str(code)+').\n        '+tail)
        print('         created: ' + path.basename(exe_fort))

        # ~~ out of local compilation
        chdir(curdir)

    return exe_fort
def compiletex(texfile, version, verbose):
    """
    @brief Full procedure for compiling a LaTeX file
             .i.e pdflatex,bibtex,pdflatex,pdflatex
    @param texfile Name of the main LaTex file
    @param version Version of the code/documentation
    @param verbose If yes display pdflatex listing
    """

    if verbose:
        tex_cmd = "pdflatex --jobname={tex}_{version} {tex}.tex"\
                  .format(tex=texfile, version=version)
        bib_cmd = "bibtex {}_{}.aux".format(texfile, version)
    else:
        tex_cmd = \
           "pdflatex --jobname={tex}_{version} {tex}.tex >latex_run.log 2>&1"\
                  .format(tex=texfile, version=version)
        bib_cmd = "bibtex {}_{}.aux >bib_run.log 2>&1".format(texfile, version)


    # First compilation
    mes = Messages(size=10)
    tail, code = mes.run_cmd(tex_cmd, False)

    if code != 0:
        if verbose:
            log = ''
        else:
            log = '\noutput:\n{}'.format(\
                    '\n'.join(get_file_content('latex_run.log')[-20:]))
        raise TelemacException(\
            'Latex compilation failed\n{}\n{}'\
            .format(tail, log))

    # Bibtex compilation
    tail, code = mes.run_cmd(bib_cmd, False)

    # Forcing bibtex to pass
    code = 0

    if code != 0:
        if verbose:
            log = ''
        else:
            log = '\noutput:\n{}'.format(\
                    '\n'.join(get_file_content('latex_run.log')[-20:]))
        raise TelemacException(\
            'Latex compilation failed\n{}\n{}'\
            .format(tail, log))

    # Second compilation
    tail, code = mes.run_cmd(tex_cmd, False)

    if code != 0:
        if verbose:
            log = ''
        else:
            log = '\noutput:\n{}'.format(\
                    '\n'.join(get_file_content('bib_run.log')[-20:]))
        raise TelemacException(\
            'Latex compilation failed\n{}\n{}'\
            .format(tail, log))

    # Third compilation
    tail, code = mes.run_cmd(tex_cmd, False)

    if code != 0:
        if verbose:
            log = ''
        else:
            log = '\noutput:\n{}'.format(\
                    '\n'.join(get_file_content('latex_run.log')[-20:]))
        raise TelemacException(\
            'Latex compilation failed\n{}\n{}'\
            .format(tail, log))
Example #12
0
def run_mascaret():
    """
    Main function that runs the mascaret executable in the current folder
    """

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reads config file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print('\n\nLoading Options and Configurations\n'+72*'~'+'\n')
    parser = ArgumentParser(
        formatter_class=RawDescriptionHelpFormatter,
        description=('''\n\
Run the mascaret executable in the current folder, given a CAS file.
        '''))
    parser.add_argument("args", nargs='*')
    # ~~> Environment
    parser = add_config_argument(parser)
    parser.add_argument(
        "-s", "--sortiefile", action="store_true", dest="sortie_file",
        default=False,
        help="specify whether there is a sortie file, default is no")
    parser.add_argument(
        "-b", "--bypass", action="store_true",
        dest="bypass", default=False,
        help="will bypass execution failures and try to carry on "
             "(final report at the end)")
    options = parser.parse_args()

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    update_config(options)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ banners ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    svn_banner(CFGS.get_root())

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Works for one configuration only ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if len(options.args) < 1:
        print('\nThe name of the CAS file is required\n')
        parser.print_help()
        sys.exit(1)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reads command line arguments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    cas = options.args[0]
# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Works for only one configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    xcpts = Messages()

    # still in lower case
    # parsing for proper naming
    CFGS.compute_execution_info()
    cfg = CFGS.configs[CFGS.cfgname]

    create_mascaret_files(cfg, cas)

    mascaret_exe = path.join(cfg['root'], 'builds', CFGS.cfgname, 'bin',
                             'mascaret' + cfg['sfx_exe'])
    _, code = xcpts.run_cmd(mascaret_exe, options.bypass)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reporting errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if xcpts.not_empty() or code != 0:
        print('\n\nHummm ... I could not complete my work.\n'+'~'*72
              + xcpts.except_messages())
        sys.exit(1)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Jenkins' success message ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    else:
        print('\n\nMy work is done\n\n')
        sys.exit(0)
def main(module=None):
    """
    @brief Main function of the runcode.py module

    @param module (string): the name of the module to run (
      available modules are: telemac2d, telemac3d, artemis, tomawac,
      sisyphe, artemis, postel3d, ...)

    @return None
    """

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Reads config file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print('\n\nLoading Options and Configurations\n' + 72 * '~' + '\n')
    if module is None:
        parser = ArgumentParser(
            formatter_class=RawDescriptionHelpFormatter,
            description=('''\n
runcode is the execution launcher for all TELEMAC modules.\n
where module can be:\n
    mascaret     the 1D hydrodyanmic / tracer / water quality solver
    telemac2d    the 2D hydrodyanmic / tracer / water quality solver
    telemac3d    the 3D hydrodynamic / tracer / water quality solver
    artemis      the phase resolving wave solver
    tomawac      the 3rd generation wave transformation solver
    sisyphe      the sediment transport and geomorphogical solver
    stbtel       a pre-processor for the modules
    postel3d     a post-processor for telemac3d
            '''),
            usage=' (--help for help)\n---------\n        =>  '
            '%(prog)s module [options] casfile(s)\n---------',
            epilog=('''\nexamples:\n---------
1:     => runcode.py telemac2d -s t2d.cas
---------'''))
        parser.add_argument("module",
                            default=None,
                            choices=[
                                'telemac2d', 'telemac3d', 'artemis', 'tomawac',
                                'stbtel', 'postel3d', 'sisyphe', 'partel',
                                'estel3d', 'mascaret'
                            ])
    else:
        parser = ArgumentParser(formatter_class=RawDescriptionHelpFormatter,
                                description=('''\n
%(prog)s is one of the execution launcher for the TELEMAC system.
            '''),
                                epilog=('''\nexamples:\n---------
1:     => %(prog)s -s t2d.cas
---------'''))
        parser.set_defaults(module=module)

    parser = add_runcode_argument(parser, module=module)
    # Arguments
    parser.add_argument("args", metavar='cas file(s)', nargs="+")

    options = parser.parse_args()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    update_config(options)

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ banners ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    svn_banner(CFGS.get_root())

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Works for one configuration only ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # Checking if symlink is available
    if options.use_link and not check_sym_link(options.use_link):
        raise TelemacException(\
                '\nThe symlink option is only '
                'available on Linux systems. '
                'Remove the option and try again')

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reads command line arguments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    code_name = options.module
    cas_files = options.args

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Works for only one configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # bypass errors and carries on
    options.bypass = False
    if options.split or options.merge or options.run:
        if options.w_dir == '':
            raise TelemacException(\
                    '\nPlease use option -w (--workdirectory)'
                    ' with either of the options '
                    '--split, --run or --merge\n')
    # parsing for proper naming
    CFGS.compute_execution_info()
    cfg = CFGS.configs[CFGS.cfgname]

    print('\n\nRunning your CAS file(s) for:\n' + '~' * 72 + '\n')
    CFGS.light_dump()
    if options.w_dir != '':
        print('     +> directory        ' + options.w_dir)
        options.tmpdirectory = False
    print('\n\n' + '~' * 72 + '\n')

    # >>> Check wether the config has been compiled for the runcode
    if options.compileonly:
        cfg['REBUILD'] = 1
    if code_name not in cfg['MODULES']:
        raise TelemacException(\
                '\nThe code requested is not installed '
                'on this system : {}\n'.format(code_name))

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reporting errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    xcpts = Messages()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Run the Code from the CAS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    for cas_file in cas_files:
        run_study(cas_file, code_name, options)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reporting errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if xcpts.not_empty():
        raise TelemacException(\
                '\n\nHummm ... I could not complete '
                'my work.\n{}{}'.format('~'*72, xcpts.except_messages()))


# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Jenkins' success message ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print('\n\nMy work is done\n\n')
    sys.exit(0)
def main():
    """
     @brief Main function of validateTELEMAC.
    """
    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~ Handles input arguments
    options = set_parser()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    update_config(options)
    version = CFGS.configs[CFGS.cfgname].get('version', 'trunk')

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ banners ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    svn_banner(CFGS.get_root(), version)

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Works for all configurations unless specified ~~~~~~~~~~~~~~~
    # Checking if symlink is available
    if options.use_link and not check_sym_link(options.use_link):
        raise TelemacException(\
                '\nThe symlink option is only available on Linux systems. '
                'Remove the option and try again')

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Forces not to use any Xwindows backend for Jenkins ~~~~~~~~~~
    if options.vnv_post:
        import matplotlib.pyplot as plt

        plt.switch_backend('agg')

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Reporting errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    xcpts = Messages()

    # ~~~~ Reporting summary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if options.notebook:
        type_valid = 'notebooks'
    else:
        type_valid = 'examples'

    report = Report(options.report_name, type_valid)

    # ~~~ Running validation
    cfg = config_corrections(options, CFGS.cfgname)

    if options.notebook:
        run_validation_notebooks(options, report, xcpts)
    else:
        if options.vnv_mode == 'slurm':
            run_validation_python_slurm(cfg, options, report, xcpts)
        else:
            run_validation_python_mpi(cfg, options, report, xcpts)

    # Writting report
    if options.report_name != '':
        report.write()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Reporting errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if xcpts.not_empty():
        print('\n\nHummm ... I could not complete my work.\n'
              '{}\n{}'.format('~' * 72, xcpts.except_messages()))
        sys.exit(1)

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Jenkins' success message ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    else:
        print('\n\nMy work is done\n\n')
        sys.exit(0)
Example #15
0
def generate_notebook_html(doc_dir, notebook_dir, verbose):
    """
    Generate an html layout of the notebooks using ipython nbconvert
    Than coying back the file into doc_dir

    @param doc_dir (string) Path to the folder that will contain the html
                            version of the documentation
    @param notebook_dir (string) Path to the notebooks
    @param verbose (bool) If True more verbose
    """
    # Creating doc folder if necessary
    if not path.exists(doc_dir):
        mkdir(doc_dir)

    # Running convertion in notebook folder
    # Gathering all html files
    for root, subdirs, files in walk(notebook_dir):
        # Creating subfolders in advance
        for subdir in subdirs:
            if ".ipynb_checkpoint" in root:
                continue
            out_dir = path.join(doc_dir + root.replace(notebook_dir, ''),
                                subdir)
            if not path.exists(out_dir):
                mkdir(out_dir)
        for ffile in files:
            if ffile.endswith("ipynb"):
                # Skipping notebook tmp folders
                if ".ipynb_checkpoint" in root:
                    continue
                notebook = path.join(root, ffile)
                out_dir = doc_dir + root.replace(notebook_dir, '')
                if verbose:
                    log_lvl = 'DEBUG'
                else:
                    log_lvl = 'ERROR'
                cmd = "jupyter nbconvert --to html --log-level={log_lvl} "\
                      "--output-dir={out_dir} --output={output} {nb}"\
                       .format(log_lvl=log_lvl, out_dir=out_dir,
                               output="tmp.html", nb=notebook)
                print("   ~> Converting "+\
                        path.join(root.replace(notebook_dir, '')[1:], ffile))
                if verbose:
                    print(cmd)
                # Running convertion
                mes = Messages(size=10)
                tail, code = mes.run_cmd(cmd, bypass=False)

                if code != 0:
                    raise TelemacException(
                        'nbconvert failed\n {}'.format(tail))

                tmp_file = path.join(out_dir, 'tmp.html')
                out_file = path.join(out_dir, ffile[:-5] + "html")

                # Replacing .ipynb in content of file by .html
                with open(tmp_file, 'r') as f:
                    content = f.read()

                remove(tmp_file)
                with open(out_file, 'w') as f:
                    f.write(content.replace(".ipynb", ".html"))
Example #16
0
from tmx.tmxfile import TmxFile as TmxFile
import pygame
import sys
from pygame.locals import *
from animation.animatedsprite import AnimatedSprite as AnimatedSprite
from animation.animatedpath import AnimatedPath as AnimatedPath
from ai.aimap import AiMap as AiMap
from utils.messages import Messages as Messages

tmxFile = TmxFile()
tmxMap = tmxFile.loadTmx("./media/maps/home.tmx")
del tmxFile

pygame.init()

gameMessages = Messages()
gameMessages.addMessage("test message")

# set up the window
currentSize = tmxMap.getMapImageRect()
# it should be 512*640, so it will be displayed in 1024*768
#surface = pygame.display.set_mode((currentSize.width, currentSize.height),
surface = pygame.display.set_mode((1024, 768),
    0, 32)
#os.environ['SDL_VIDEODRIVER'] = 'directfb'
#surface = pygame.display.set_mode((1920, 1080),
#    pygame.FULLSCREEN | pygame.HWSURFACE)
pygame.display.set_caption('TmxMap - Display')
clock = pygame.time.Clock()