예제 #1
0
    def generate_script(self):
        """
        Generate Code_Aster run script
        """

        s_path = os.path.join(self.exec_dir, "aster_by_yacs")
        s = open(s_path, 'w')

        from cs_exec_environment import write_shell_shebang
        write_shell_shebang(s)

        s.write('cd ..\n')
        s.write('export PATH=' + os.path.join(self.aster_home, 'bin') +
                ':$PATH\n')
        s.write('as_run ' + self.param + '\n')

        s.close()

        oldmode = (os.stat(s_path)).st_mode
        newmode = oldmode | (stat.S_IXUSR)
        os.chmod(s_path, newmode)
예제 #2
0
    def generate_script(self):
        """
        Generate Code_Aster run script
        """

        s_path = os.path.join(self.exec_dir, "aster_by_yacs")
        s = open(s_path, 'w')

        from cs_exec_environment import write_shell_shebang
        write_shell_shebang(s)

        aster_root = os.path.split(self.aster_home)[0]

        s.write('cd ..\n')
        s.write('export PATH=' + os.path.join(aster_root, 'bin') + ':$PATH\n')
        s.write('as_run ' + self.param + '\n')

        s.close()

        oldmode = (os.stat(s_path)).st_mode
        newmode = oldmode | (stat.S_IXUSR)
        os.chmod(s_path, newmode)
예제 #3
0
    def create_case(self, casename):
        """
        Create a case for a Code_Saturne study.
        """

        casedirname = casename

        if self.verbose > 0:
            if not self.import_only:
                sys.stdout.write("  o Creating case  '%s'...\n" % casename)
            else:
                if not casename:
                    casedirname = "."
                    casename = os.path.basename(os.getcwd())
                sys.stdout.write("  o Importing case  '%s'...\n" % casename)

        datadir = self.package.get_dir("pkgdatadir")
        data_distpath = os.path.join(datadir, 'data')

        if not self.import_only:
            try:
                os.mkdir(casedirname)
            except:
                sys.exit(1)

        os.chdir(casedirname)

        # Data directory

        data = 'DATA'

        if not self.import_only:
            os.mkdir(data)

        if self.use_ref:

            thch_distpath = os.path.join(data_distpath, 'thch')
            ref = os.path.join(data, 'REFERENCE')
            os.mkdir(ref)
            for f in [
                    'dp_C3P', 'dp_C3PSJ', 'dp_C4P', 'dp_ELE', 'dp_FCP.xml',
                    'dp_FUE', 'dp_transfo', 'meteo'
            ]:
                abs_f = os.path.join(thch_distpath, f)
                if os.path.isfile(abs_f):
                    shutil.copy(abs_f, ref)
                    unset_executable(ref)
            abs_f = os.path.join(datadir, 'cs_user_scripts.py')
            shutil.copy(abs_f, ref)
            unset_executable(ref)

        # Write a wrapper for GUI launching

        guiscript = os.path.join(data, self.package.guiname)

        fd = open(guiscript, 'w')
        cs_exec_environment.write_shell_shebang(fd)

        cs_exec_environment.write_script_comment(
            fd, 'Ensure the correct command is found:\n')
        cs_exec_environment.write_prepend_path(fd, 'PATH',
                                               self.package.get_dir("bindir"))
        fd.write('\n')
        cs_exec_environment.write_script_comment(fd, 'Run command:\n')
        # On Linux systems, add a backslash to prevent aliases
        if sys.platform.startswith('linux'): fd.write('\\')
        fd.write(self.package.name + ' gui ' +
                 cs_exec_environment.get_script_positional_args() + '\n')

        fd.close()

        set_executable(guiscript)

        # User source files directory

        if not self.import_only:
            src = 'SRC'
            os.mkdir(src)

        if self.use_ref:

            user_distpath = os.path.join(datadir, 'user')
            user_examples_distpath = os.path.join(datadir, 'user_examples')

            user = os.path.join(src, 'REFERENCE')
            user_examples = os.path.join(src, 'EXAMPLES')
            shutil.copytree(user_distpath, user)
            shutil.copytree(user_examples_distpath, user_examples)

            add_datadirs = []
            if self.package.name == 'neptune_cfd':
                add_datadirs.append(
                    os.path.join(self.package.get_dir("datadir"),
                                 self.package.name))

            for d in add_datadirs:
                user_distpath = os.path.join(d, 'user')
                user_examples_distpath = os.path.join(d, 'user_examples')

                if os.path.isdir(user_distpath):
                    s_files = os.listdir(user_distpath)
                    for f in s_files:
                        shutil.copy(os.path.join(user_distpath, f), user)

                if os.path.isdir(user_examples_distpath):
                    s_files = os.listdir(user_examples_distpath)
                    for f in s_files:
                        shutil.copy(os.path.join(user_examples_distpath, f),
                                    user_examples)

            unset_executable(user)
            unset_executable(user_examples)

        # Copy data and source files from another case

        if self.copy is not None:

            # Data files

            ref_data = os.path.join(self.copy, data)
            data_files = os.listdir(ref_data)

            for f in data_files:
                abs_f = os.path.join(ref_data, f)
                if os.path.isfile(abs_f) and \
                       f not in [self.package.guiname,
                                 'preprocessor_output']:
                    shutil.copy(os.path.join(ref_data, abs_f), data)
                    unset_executable(os.path.join(data, f))

            # Source files

            ref_src = os.path.join(self.copy, src)
            if os.path.exists(ref_src):
                src_files = os.listdir(ref_src)
            else:
                src_files = []

            c_files = fnmatch.filter(src_files, '*.c')
            cxx_files = fnmatch.filter(src_files, '*.cxx')
            cpp_files = fnmatch.filter(src_files, '*.cpp')
            h_files = fnmatch.filter(src_files, '*.h')
            hxx_files = fnmatch.filter(src_files, '*.hxx')
            hpp_files = fnmatch.filter(src_files, '*.hpp')
            f_files = fnmatch.filter(src_files, '*.[fF]90')

            for f in c_files + h_files + f_files + \
                    cxx_files + cpp_files + hxx_files + hpp_files:
                shutil.copy(os.path.join(ref_src, f), src)
                unset_executable(os.path.join(src, f))

        # Results directory (only one for all instances)

        resu = 'RESU'
        if not os.path.isdir(resu):
            os.mkdir(resu)

        # Script directory (only one for all instances)

        scripts = 'SCRIPTS'
        if not os.path.isdir(scripts):
            os.mkdir(scripts)

        self.build_batch_file(distrep=os.path.join(os.getcwd(), scripts),
                              casename=casename)
예제 #4
0
def update_case(options, pkg):

    repbase = os.getcwd()
    study_name = os.path.basename(os.getcwd())
    for case in options.case_names:
        os.chdir(repbase)

        if case == ".":
            casename = os.path.split(repbase)[-1]
        else:
            casename = case

        if options.verbose > 0:
            sys.stdout.write("  o Updating case '%s' paths...\n" % casename)

        datadir = os.path.join(pkg.get_dir("pkgdatadir"))

        os.chdir(case)

        # Write a wrapper for GUI launching
        data = 'DATA'
        if not os.path.isdir(data):
            os.mkdir(data)

        guiscript = os.path.join(data, pkg.guiname)

        fd = open(guiscript, 'w')
        cs_exec_environment.write_shell_shebang(fd)

        cs_exec_environment.write_script_comment(
            fd, 'Ensure the correct command is found:\n')
        cs_exec_environment.write_prepend_path(fd, 'PATH',
                                               pkg.get_dir("bindir"))
        fd.write('\n')
        cs_exec_environment.write_script_comment(fd, 'Run command:\n')
        # On Linux systems, add a backslash to prevent aliases
        if sys.platform.startswith('linux'): fd.write('\\')
        fd.write(pkg.name + ' gui ' +
                 cs_exec_environment.get_script_positional_args() + '\n')

        fd.close()

        set_executable(guiscript)

        # User source files directory
        src = 'SRC'
        if not os.path.isdir(src):
            os.mkdir(src)

        user_distpath = os.path.join(datadir, 'user')
        user_examples_distpath = os.path.join(datadir, 'user_examples')

        user = os.path.join(src, 'REFERENCE')
        user_examples = os.path.join(src, 'EXAMPLES')

        copy_directory(user_distpath, user)
        copy_directory(user_examples_distpath, user_examples)

        add_datadirs = []
        if pkg.name == 'neptune_cfd':
            add_datadirs.append(os.path.join(pkg.get_dir("datadir"), pkg.name))

        for d in add_datadirs:
            user_distpath = os.path.join(d, 'user')
            if os.path.isdir(user_distpath):
                copy_directory(user_distpath, user)

            user_examples_distpath = os.path.join(d, 'user_examples')
            if os.path.isdir(user_examples_distpath):
                copy_directory(user_examples_distpath, user_examples)

        unset_executable(user)
        unset_executable(user_examples)

        # Results directory (only one for all instances)

        resu = 'RESU'
        if not os.path.isdir(resu):
            os.mkdir(resu)

        # Script directory (only one for all instances)

        scripts = 'SCRIPTS'
        if not os.path.isdir(scripts):
            os.mkdir(scripts)

        batch_file = os.path.join(repbase, case, scripts, 'runcase')
        if sys.platform.startswith('win'):
            batch_file = batch_file + '.bat'

        # Add info from parent in case of copy

        runcase = cs_runcase.runcase(batch_file,
                                     package=pkg,
                                     rebuild=True,
                                     study_name=study_name,
                                     case_name=case)
        runcase.save()