def config_corrections(options, cfgname):
    """
    overwrite configuration wiht options arguments

    @param options (Value) List of argparse options
    @param cfgname (string) Name of the configuration

    @return (dict) The configuration info
    """
    CFGS.cfgname = cfgname
    cfg = CFGS.configs[cfgname]
    # still in lower case
    if options.val_root != '':
        cfg['val_root'] = options.val_root
    # parsing for proper naming
    CFGS.compute_vnv_info()
    print('    +> ' + cfgname + ': ' + ', '.join(cfg['VALIDATION'].keys()))
    if options.cleanup:
        cfg['REBUILD'] = 2

    return cfg
def main():
    """
    Main program for the compilation of the documentation of
    the telemac-mascaret system
    """
# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~ Reads config file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print('\n\nLoading Options and Configurations\n'+'~'*72+'\n')
    parser = ArgumentParser(
        formatter_class=RawDescriptionHelpFormatter,
        description=('''\n
By Default all the documentation are generated\n
use the options --validation/reference/user/release/theory to compile only one
        '''))
    parser = add_config_argument(parser)
    parser.add_argument(
        "-v", "--verbose", action="store_true",
        dest="verbose", default=False,
        help="Will display listing for all commands")
    parser.add_argument(
        "-m", "--modules",
        dest="modules", default='',
        help="specify the list modules (, separated), default is all of them")
    parser.add_argument(
        "-M", "--misc",
        dest="misc", default='',
        help="specify the list of misc documentation (, separated) to compile, "
             "default is all of them")
    parser.add_argument(
        "--validation", action="store_true",
        dest="validation", default=False,
        help="Will generate the validation documentation")
    parser.add_argument(
        "--case-list",
        dest="case_list", default='',
        help="List of cas to include in the validation documentation"
             "separated by ',' (default all of them)")
    parser.add_argument(
        "--reference", action="store_true",
        dest="reference", default=False,
        help="Will generate the reference documentation")
    parser.add_argument(
        "--user", action="store_true",
        dest="user", default=False,
        help="Will generate the user documentation")
    parser.add_argument(
        "--release", action="store_true",
        dest="release_note", default=False,
        help="Will generate the release note")
    parser.add_argument(
        "--theory", action="store_true",
        dest="theory_guide", default=False,
        help="Will generate the theory guide")
    parser.add_argument(
        "--clean", action="store_true",
        dest="cleanup", default=False,
        help="Will remove all temporary file generated by pdflatex")
    parser.add_argument(
        "--fullclean", action="store_true",
        dest="fullcleanup", default=False,
        help="Same as clean but removes the pdf as well")

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    options = parser.parse_args()
    update_config(options)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Works for all configurations unless specified ~~~~~~~~~~~~~~~
# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Compile the valiation documentation
    doall = not (options.validation or options.user or options.reference
                 or options.release_note or options.theory_guide)
    cfg = CFGS.configs[CFGS.cfgname]
    # still in lower case
    root = CFGS.get_root()
    # Get what i to be compiled
    # By default everything if something is defined compiling only that
    if options.modules != '':
        module_list = options.modules.split(',')
    else:
        # all modules
        module_list = ['artemis', 'stbtel', 'sisyphe', 'postel3d',
                       'telemac2d', 'telemac3d', 'tomawac', 'waqtel',
                       'telapy', 'mascaret', 'gaia', 'nestor', 'khione']
    if options.misc != '':
        misc_list = options.misc.split(',')
        module_list = []
    else:
        # all docs
        misc_list = ['developer_guide', 'software_quality_plan',
                     'TelemacDocTemplate', 'git_guide',
                     'doxypydocs']
        # If a module was specified or a specific documentation for modules
        # not compiling Misc documentation
        if options.modules != '' or not doall:
            misc_list = []

    CFGS.compute_vnv_info()

    # Get version in config if it exist use trunk otherwise
    version = cfg.get('version', 'trunk')

    # Initialise output message
    output_mess = '\n\n'
    # Look on all the modules for the documentation
    for code_name in module_list:
        print('\nCompilation of the documentation for ' + code_name
              + '\n'+'~'*72)
        # list of what to do for the module
        todo = []
        if options.validation or doall:
            if code_name not in ['telapy', 'mascaret']:
                # Building Validation LaTeX file
                doc_dir = path.join(root, 'documentation',
                                    code_name, 'validation')
                chdir(doc_dir)
                if options.case_list != '':
                    list_of_case = options.case_list.split(',')
                else:
                    list_of_case = list(cfg['VALIDATION'][code_name].keys())
                    list_of_case.remove('path')
                skiped_case = \
                    create_case_list_file(
                        doc_dir,
                        cfg['VALIDATION'][code_name]['path'],
                        list_of_case,
                        options.cleanup or options.fullcleanup)
                for case in skiped_case:
                    output_mess += r'   - /!\ Missing LaTeX file for ' + \
                                   case+'\n'
                todo.append('validation')
        if options.reference or doall:
            if code_name not in ['telapy', 'mascaret', 'nestor']:
                # Path to the dictionary
                dictionary = path.join(root, 'sources', code_name,
                                       code_name+'.dico')
                # Path to latex File
                latex_file = path.join(root, 'documentation',
                                       code_name, 'reference',
                                       'latex', 'Corpus.tex')
                # English only for now
                lng = '2'
                # Path to bin directory
                exe_path = path.join(\
                        root, 'builds', CFGS.cfgname,
                        'bin', 'damocles'+cfg['SYSTEM']['sfx_exe'])
                generate_ref_from_dict(\
                        exe_path, dictionary, latex_file, lng,
                        options.cleanup or options.fullcleanup,
                        options.verbose)
                todo.append('reference')
        if options.user or doall:
            if code_name not in ['mascaret']:
                # Normal Compilation of a LaTeX file
                todo.append('user')
        if options.theory_guide or doall:
            # theory guide only available for telemac3d
            if code_name in ['telemac3d', 'mascaret', 'waqtel']:
                todo.append('theory_guide')
        for doc_type in todo:
            print('\n     ~> Compilation of the {} documentation'\
                  .format(doc_type))
            doc_dir = path.join(root, 'documentation',
                                code_name, doc_type)
            chdir(doc_dir)
            # Check if the file exist
            if path.exists(path.join(doc_dir,
                                     code_name + "_" + doc_type + ".tex")):
                compile_doc(doc_dir, code_name+'_'+doc_type,
                            version,
                            options.cleanup, options.fullcleanup,
                            options.verbose)
            else:
                raise TelemacException(\
                        "   - Error for {} {}, {}.tex "
                        "not found ".format(code_name,
                                            path.basename(doc_dir),
                                            code_name+"_"+doc_type))
            if not (options.cleanup or options.fullcleanup):
                output_mess += '   - Created %s_%s_%s.pdf\n' % \
                              (code_name, doc_type, version)
    # List of the other documentation
    print('\nCompilation of the documentation for Misc'
          + '\n'+'~'*72)
    for doc in misc_list:
        print('\n     ~> Compilation of the {} documentation'.format(doc))
        doc_dir = path.join(root, 'documentation',
                            'Misc', doc)

        if doc == 'notebook':
            notebook_dir = path.join(root, 'notebooks')
            generate_notebook_pdf(doc_dir, notebook_dir)
        elif doc in ['doxydocs', 'doxypydocs']:
            generate_doxygen(doc, options.verbose)
        else:
            chdir(doc_dir)
            if path.exists(path.join(doc_dir, doc + ".tex")):
                compile_doc(doc_dir, doc,
                            version,
                            options.cleanup, options.fullcleanup,
                            options.verbose)
            else:
                raise TelemacException(\
                        "   - Error in {}, {}.tex "
                        "not found ".format(path.basename(doc_dir), doc))
        if not (options.cleanup or options.fullcleanup) or \
           doc not in ['notebooks', 'doxydocs', 'doxypydocs']:
            output_mess += '   - Created %s_%s.pdf\n' % \
                          (doc, version)

    print(output_mess)
    print('\n\n'+'~'*72)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Jenkins' success message ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print('\n\nMy work is done\n\n')

    sys.exit(0)
Beispiel #3
0
def main():
    """
       Main program for the execution of damocles
    """
    #   ~~ Reads config file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print('\n\nLoading Options and Configurations\n' + '~' * 72 + '\n')
    parser = ArgumentParser()
    parser = add_config_argument(parser)
    parser.add_argument(\
                  "-m", "--modules",
                  dest="modules",
                  default='',
                  help="specify the list modules, default is "\
                      "taken from config file")
    parser.add_argument(\
                  "--dump",
                  action="store_true",
                  dest="dump",
                  default=False,
                  help="Will dump a reordered dictionary by rubrique")
    parser.add_argument(\
                  "--dump2",
                  action="store_true",
                  dest="dump2",
                  default=False,
                  help="Will dump a reordered dictionary by index")
    parser.add_argument(\
                  "--eficas",
                  action="store_true",
                  dest="eficas",
                  default=False,
                  help="Will generate the eficas Catalogue from the dictionary")
    parser.add_argument(\
                  "--latex",
                  action="store_true",
                  dest="latex",
                  default=False,
                  help="Will generate the LaTeX file for the reference manual")

    #   ~~~~ Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    args = parser.parse_args()
    # path to the root

    #   ~~~~ Works for all configurations unless specified ~~~~~~~~~~~~~~~
    update_config(args)
    cfg = CFGS.configs[CFGS.cfgname]
    #   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # Defining which modules to use
    if args.modules is '':
        module_list = [
            'artemis', 'postel3d', 'stbtel', 'sisyphe', 'telemac2d',
            'telemac3d', 'tomawac', 'waqtel', 'gaia', 'khione'
        ]
    else:
        module_list = args.modules.split(';')
    # Identify Root value
    CFGS.compute_vnv_info()
    root = CFGS.get_root()
    exe_path = path.join(root, 'builds', CFGS.cfgname,\
                         'bin', 'damocles'+\
                         cfg['SYSTEM']['sfx_exe'])
    # Looping on all modules
    for module in module_list:
        module_path = path.join(root, 'sources', module)
        if args.dump:
            input_dict = path.join(module_path, module + ".dico")
            output_dict = path.join(module_path, module + "2.dico")
            gen_dump(exe_path, input_dict, output_dict)

        if args.dump2:
            input_dict = path.join(module_path, module + ".dico")
            output_dict = path.join(module_path, module + "2.dico")
            gen_dump2(exe_path, input_dict, output_dict)

        if args.eficas:

            # Creating eficas folder and __init__ if it does not exists
            eficas_path = path.join(root, 'scripts', 'python3', 'eficas')
            if not path.exists(eficas_path):
                mkdir(eficas_path)
                with open(path.join(eficas_path, '__init__.py'), 'w') as fobj:
                    fobj.write("#! /usr/bin/env python")
                    fobj.write("# -*- coding: utf-8 -*")

            input_dict = path.join(module_path, module + ".dico")
            input_dep = path.join(module_path, module + ".dico.dep")
            fancy_module = module
            cata_name = path.join(eficas_path, fancy_module + "_cata_auto.py")
            enum_name = path.join(eficas_path, fancy_module + "_enum_auto.py")
            ts_path = eficas_path
            gen_cata(module.upper(), exe_path, input_dict, input_dep,
                     cata_name, enum_name, ts_path + path.sep)

        if args.latex:
            input_dict = path.join(module_path, module + ".dico")
            latex_name = path.join(root, 'documentation', module, 'reference',\
                                  'latex', 'Corpus.tex')
            # English only
            lng = '2'
            gen_latex(exe_path, input_dict, latex_name, lng)


#   ~~~~ Compile the valiation documentation

    print('\n\n' + '~' * 72)

    #   ~~~~ Jenkins' success message ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print('\n\nMy work is done\n\n')

    sys.exit(0)