Пример #1
0
def compileAPI(config_name, config_file, root_dir, exe_file):
    """
       Main function

       @param config_name Name of the telemac configuration
       @param config_file Name of the configuration file
       @param root_dir Path to the root folder of telemac
       @param exe_file Name of the file to compile
    """


    cfgs = build_config(config_name, config_file, root_dir)
# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reporting errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    xcptss = MESSAGES()

    for cfgname in cfgs:
        print '\n\n'+'\n'.join(banner(cfgname))

        # Check if we are compiling a fortran or recompiling the API
        compile_api_exe(exe_file, cfgs, cfgname, user_fortran)
    return xcptss
Пример #2
0
def main():
    """ Main function of compileTELEMAC """

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~ Reads config file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print('\n\nLoading Options and Configurations\n' + 72 * '~' + '\n')
    parser = ArgumentParser(
        formatter_class=RawDescriptionHelpFormatter,
        description=('''\n
Compile the TELEMAC system:\n
1. rescan the tree dependencies if necessary
2. check which files need re-compilation
3. create object files, libraries, executable, and other binaries
    depending on your configuration settings
Work with all active configurations.
        '''))

    parser = add_config_argument(parser)
    parser.add_argument(
        "-m", "--modules", metavar="modules",
        dest="modules", default='',
        help="specify the list modules . separated, default is taken from config file")
    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)")
    parser.add_argument(
        "--rescan", action="store_true",
        dest="rescan", default=False,
        help="will redo the scan of sources for an update of "
             "all the cmdf files")
    parser.add_argument(
        "--clean", action="store_true",
        dest="cleanup", default=False,
        help="will erase all object, executable libraries from folder "
             "on the selected configs/modules")
    parser.add_argument(
        "-j", type=int,
        dest="ncsize", default=0,
        help="set the number of core used for the parallel "
             "compilation of objects")
    parser.add_argument(
        "-v", "--verbose", action="store_true",
        dest="verbose", default=False,
        help="If given will print every command")
    options = parser.parse_args()

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

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

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Separately dealing with rescan for all configs ? ~~~~~~~~~~~~
    for cfgname in CFGS.configs:
        # Setting configuration name
        CFGS.cfgname = cfgname
        # Getting configuration
        cfg = CFGS.configs[cfgname]

        if options.cleanup:
            CFGS.clean_install(cfgname)

        print('\n\n' + '\n'.join(banner(cfgname)))
        print('Scanning the source code for:\n' + '~' * 72 + '\n')

        compute_config(options.cleanup and options.rescan,
                       options.bypass)
        CFGS.light_dump()
        # Only if we ask for a scan
        if options.rescan:
            update_cmdf(options.bypass, options.cleanup, options.verbose)

        # /!\ multiple configurations will now generate multiple rescan
        # (because of tags and adds, specific to some configurations)
        compute_config(False, options.bypass)

        # ~~ Scans all cmdf files found in all modules ~~~~~~~~~~~~~~~~~~~~~
        # Specifying what module to compile
        if options.modules == '':
            modules = []
        else:
            modules = options.modules.split(".")
        compile_cmdf(options.ncsize, modules, options.verbose)

        # Compiling api if asked for
        cfg_opt = cfg.get('options', [])
        if 'api' in cfg_opt:
            compile_api_files(silent=not options.verbose,
                              static='static' in cfg_opt,
                              hermes_only='hermes_only' in cfg_opt)

    print('\n\nMy work is done\n\n')
    sys.exit(0)
Пример #3
0
    svnrev = ''
    svnurl = ''
    try:
        key_equals = re.compile(r'(?P<key>[^:]*)(?P<after>.*)', re.I)
        tail, code = mes.runCmd('svn info ' + PWD, True)
        for line in tail.split('\n'):
            proc = re.match(key_equals, line)
            if proc:
                if proc.group('key').strip() == 'Revision':
                    svnrev = proc.group('after')[1:].strip()
                if proc.group('key').strip() == 'URL':
                    svnurl = proc.group('after')[1:].strip()
    except:
        pass
    if svnrev + svnurl == '':
        print '\n'.join(banner('unknown revision'))
    else:
        if svnurl != '': print '\n'.join(banner(svnurl.split('/')[-1]))
        if svnrev != '': print '\n'.join(banner('rev. #' + svnrev))
        version = svnurl.split('/')[-1] + '-' + svnrev

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Works for all configurations unless specified ~~~~~~~~~~~~~~~
    if not path.isfile(options.configFile):
        print '\nNot able to get to the configuration file: ' + options.configFile + '\n'
        dircfg = path.abspath(path.dirname(options.configFile))
        if path.isdir(dircfg):
            print ' ... in directory: ' + dircfg + '\n ... use instead: '
            _, _, filenames = walk(dircfg).next()
            for fle in filenames:
                head, tail = path.splitext(fle)
Пример #4
0
def main():
    """
      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_argument(\
       "-c", "--configname",dest="configName",default='',
       help="specify configuration name, default is randomly found in the configuration file" )
    parser.add_argument(\
       "-f", "--configfile",dest="configFile",default='',
       help="specify configuration file, default is systel.cfg" )
    parser.add_argument(\
       "-r", "--rootdir",dest="rootDir",default='',
       help="specify the root, default is taken from config file" )
    parser.add_argument(\
       "-s", "--sortiefile",action="store_true",dest="sortieFile",default=False,
       help="specify whether there is a sortie file, default is no" )
    options = parser.parse_args()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # path to the root
    PWD = path.dirname(path.dirname(path.dirname(sys.argv[0])))
    if options.rootDir != '': PWD = options.rootDir
    # user configuration name
    USETELCFG = ''
    if 'USETELCFG' in environ: USETELCFG = environ['USETELCFG']
    if options.configName == '': options.configName = USETELCFG
    # user configuration file
    SYSTELCFG = path.join(PWD, 'configs')
    if 'SYSTELCFG' in environ: SYSTELCFG = environ['SYSTELCFG']
    if options.configFile != '': SYSTELCFG = options.configFile
    if path.isdir(SYSTELCFG): SYSTELCFG = path.join(SYSTELCFG, 'systel.cfg')
    options.configFile = SYSTELCFG
    options.bypass = False

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ banners ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    mes = MESSAGES()  # runcode takes its version number from the CAS file
    svnrev = ''
    svnurl = ''
    svnban = 'unknown revision'
    try:
        key_equals = re.compile(r'(?P<key>[^:]*)(?P<after>.*)', re.I)
        tail, code = mes.runCmd('svn info ' + PWD, True)
        for line in tail.split('\n'):
            proc = re.match(key_equals, line)
            if proc:
                if proc.group('key').strip() == 'Revision':
                    svnrev = proc.group('after')[1:].strip()
                if proc.group('key').strip() == 'URL':
                    svnurl = proc.group('after')[1:].strip()
    except:
        pass
    if svnrev + svnurl == '':
        print '\n'.join(banner('unknown revision'))
    else:
        if svnurl != '': print '\n'.join(banner(svnurl.split('/')[-1]))
        if svnrev != '': print '\n'.join(banner('rev. #' + svnrev))

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Works for one configuration only ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if not path.isfile(options.configFile):
        print '\nNot able to get to the configuration file: ' + options.configFile + '\n'
        dircfg = path.abspath(path.dirname(options.configFile))
        if path.isdir(dircfg):
            print ' ... in directory: ' + dircfg + '\n ... use instead: '
            _, _, filenames = walk(dircfg).next()
            for fle in filenames:
                head, tail = path.splitext(fle)
                if tail == '.cfg':
                    print '    +> ', fle
        sys.exit(1)
    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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    cfgs = parseConfigFile(options.configFile, options.configName)
    cfgname = cfgs.iterkeys().next()

    xcpts = MESSAGES()

    # still in lower case
    if not cfgs[cfgname].has_key('root'): cfgs[cfgname]['root'] = PWD
    if options.rootDir != '':
        cfgs[cfgname]['root'] = path.abspath(options.rootDir)
    # parsing for proper naming
    cfg = parseConfig_RunningTELEMAC(cfgs[cfgname])

    try:
        createMascaretFiles(cfg, cas)
    except Exception as e:
        xcpts.addMessages(
            filterMessage({'name': '_____________\nruncode::main:\n'}, e,
                          options.bypass))


    mascaretExe = cfg['root'] + sep + 'builds'+ sep + cfgname + sep + 'bin' + \
                  sep + 'mascaret' + cfgs[cfgname]['sfx_exe'] + ' FichierCas.txt'
    try:
        tail, code = xcpts.runCmd(mascaretExe, options.bypass)
    except Exception as e:
        xcpts.addMessages(
            filterMessage(
                {
                    'name':
                    'processExecutable',
                    'msg':
                    'something went wrong for no reason. \
                                             Please verify your compiler installation.'
                }, e, options.bypass))

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


# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Jenkins' success message ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    else:
        print '\n\nMy work is done\n\n'
        sys.exit(0)
Пример #5
0
def main(config_name, config_file, root_dir, validation_directory, example,
         clean):
    """
       Main function

       :param: config_name Name of the telemac configuration
       :param: config_file Name of the configuration file
       :param: root_dir Path to the root folder of telemac
       :param: validation_directory name of the example repository to validate
       :param: example case to compute
       :param: clean keyword to know if or not the tmp directory are remove after validation
    """

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # path to the root
    hometel = ''
    if 'HOMETEL' in environ:
        hometel = environ['HOMETEL']
    if root_dir == '':
        root_dir = hometel
    # user configuration name
    usetelcfg = ''
    if 'USETELCFG' in environ:
        usetelcfg = environ['USETELCFG']
    if config_name == '':
        config_name = usetelcfg
    # user configuration file
    systelcfg = path.join(hometel, 'configs')
    if 'SYSTELCFG' in environ:
        systelcfg = environ['SYSTELCFG']
    if config_file != '':
        systelcfg = config_file
    if path.isdir(systelcfg):
        systelcfg = path.join(systelcfg, 'systel.cfg')
    config_file = systelcfg

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Works for all configurations unless specified ~~~~~~~~~~~~~~~
    if not path.isfile(config_file):
        print '\nNot able to get to the configuration file: '\
              + config_file + '\n'
        dircfg = path.abspath(path.dirname(config_file))
        if path.isdir(dircfg):
            print ' ... in directory: ' + dircfg + '\n ... use instead: '
            _, _, filenames = walk(dircfg).next()
            for fle in filenames:
                _, tail = path.splitext(fle)
                if tail == '.cfg':
                    print '    +> ', fle
        raise Exception('Error in configuration file')


# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reporting errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    xcptss = MESSAGES()
    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Works for all configurations unless specified ~~~~~~~~~~~~~~~
    cfgs = parseConfigFile(config_file, config_name)

    for cfgname in cfgs:
        # still in lower case
        if not cfgs[cfgname].has_key('root'):
            cfgs[cfgname]['root'] = root_dir
        # parsing for proper naming
        #cfg = parseConfig_CompileTELEMAC(cfgs[cfgname])
        print '\n\n' + '\n'.join(banner(cfgname))
    return xcptss