Exemple #1
0
 def check_all():
     log_file = __file__[:-3] + '.log'
     log.print(log_file, 'STARTUP TESTS\n')
     Checks.check_os()
     Checks.check_python()
     Checks.check_default_web_browser()
     Checks.check_requirements()  # containts SystemExit
Exemple #2
0
def log_time_delta(start, log_file=None):
    msg = '\nTotal ' + get_time_delta(start)
    if log_file is None:
        print(msg)
    else:
        import log
        log.print(log_file, msg)
Exemple #3
0
def read_config(config_file):
    try:
        with open(config_file, "r") as f:
            data = yaml.load(f)
    except FileNotFoundError:
        log.print("{}: file not found".format(config_file), LogLevel.Error)
        sys.exit()

    return data
Exemple #4
0
def test_frd_reader_on_models_in(folder):
    print('FRD READER TEST\n\n')
    counter = 0
    for file_name in scan_all_files_in(folder, '.frd'):
        counter += 1
        relpath = os.path.relpath(file_name, start=folder)
        print('\n{}\n{}: {}'.format('=' * 50, counter, relpath))
        try:
            reader.FRD(file_name)
        except:
            logging.error(traceback.format_exc())
Exemple #5
0
def convert_unv_files_in(folder):
    print('CONVERTER TEST\n\n')
    counter = 0
    for file_name in scan_all_files_in(folder, '.unv'):
        counter += 1
        relpath = os.path.relpath(file_name, start=folder)
        print('\n{}\n{}: {}'.format('=' * 50, counter, relpath))
        try:
            unv2ccx.Converter(file_name).run()
        except:
            logging.error(traceback.format_exc())
Exemple #6
0
def convert_calculation_results_in(folder):
    print('CONVERTER TEST\n\n')
    counter = 0
    for file_name in scan_all_files_in(folder, '.frd'):
        counter += 1
        relpath = os.path.relpath(file_name, start=folder)
        print('\n{}\n{}: {}'.format('=' * 50, counter, relpath))
        try:
            ccx2paraview.Converter(file_name, ['vtk', 'vtu']).run()
        except:
            logging.error(traceback.format_exc())
Exemple #7
0
def convert_calculation_results_in(folder):
    print('CONVERTER TEST\n\n')
    start = time.perf_counter() # start time
    for file_name in scan_all_files_in(folder, '.frd'):
        print('\n' + '='*50)
        ccx2paraview.Converter(file_name, 'vtk').run()
        print('\n' + '='*50)
        ccx2paraview.Converter(file_name, 'vtu').run()
    print('\nTotal {:.1f} seconds'.format(time.perf_counter() - start))
Exemple #8
0
def main():
    #check to see if we are root first
    # check_root()

    try:
        # create the parser and add our options to look for
        parser = ArgumentParser()
        add_arg_options(parser)

        # parse the arguments
        options = parser.parse_args()

        # read our config file
        data = read_config(options.config_file)

        for k, v in data.items():
            if (k == 'backup'):
                # backup_files(v)
                pass

            elif (k == 'install'):
                # install_files(v)
                pass

            elif (k == 'link'):
                # link_files(v)
                pass

            elif (k == 'sublime'):
                # sub = sublime.Sublime(log, v)
                # sub.run()
                pass

            elif (k == 'git'):
                # g = git.Git(log, v)
                # g.run()
                pass

            else:
                pass

        z = zsh.ZSH(log, data)
        z.run()

    except OSError:
        log.print("FIALED SPLATESDSDEHLKJA:HFU*IH", LogLevel.Error)
Exemple #9
0
def test_binary_in(folder):
    print('CONVERTER TEST\n\n')
    counter = 0
    for file_name in scan_all_files_in(folder, '.unv'):
        counter += 1
        if os.name == 'nt':
            command = 'bin\\unv2ccx.exe'
        else:
            command = './bin/unv2ccx'
        relpath = os.path.relpath(file_name, start=folder)
        print('\n{}\n{}: {}'.format('=' * 50, counter, relpath))
        cmd = [command, file_name]
        try:
            process = subprocess.Popen(cmd,
                                       stdin=subprocess.PIPE,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.STDOUT)
            read_and_log(process.stdout)
        except:
            logging.error(traceback.format_exc())
Exemple #10
0
def test():

    # Prepare logging
    log_file = __file__[:-3] + '.log'
    log.stop_logging()
    log.add_my_handler(logging.DEBUG)
    log.print(log_file, 'MESH PARSER TEST')

    limit = 50000  # how many files to process
    # examples_dir = '../../../../examples/ccx/test'
    examples_dir = '../../../../examples'
    counter = 0

    examples = tests.scan_all_files_in(examples_dir, '.inp', limit)
    for file_name in examples:
        counter += 1
        relpath = os.path.relpath(file_name, start=os.getcwd())
        log.print(log_file, '\n{}\n{}: {}'.format('=' * 50, counter, relpath))

        # Parse mesh
        m = Mesh(ifile=file_name)
Exemple #11
0
def test():
    m = model.Model() # generate FEM model

    # Prepare logging
    log_file = __file__[:-3] + '.log'
    log.stop_logging()
    log.add_my_handler(logging.WARNING)
    log.print(log_file, 'IMPORTER (KEYWORDS PARSER) TEST')

    limit = 50000 # how many files to process
    examples_dir = '../../examples'
    # examples_dir = '../../examples/ccx/test'
    # examples_dir = '../../examples/abaqus/eif'
    # examples_dir = '../../examples/yahoo'
    examples = tests.scan_all_files_in(examples_dir, '.inp', limit)

    counter = 0
    for file_name in examples:
        counter += 1
        relpath = os.path.relpath(file_name, start=os.getcwd())
        log.print(log_file, '\n{} {}'.format(counter, relpath))

        # Build new clean/empty keyword object model
        m.KOM = model.kom.KOM(kom_xml='../config/kom.xml')

        # Parse inp_doc end enrich existing KOM
        i = Importer(None, None, m, None, None)
        inp_doc = read_lines(file_name)
        i.split_on_blocks(inp_doc) # fill keyword_blocks
        i.import_inp()

    msg = '\n{} INP files.'
    log.print(log_file, msg.format(len(examples)))
Exemple #12
0
def test_frd_parser_on_models_in(folder):
    start = time.perf_counter() # start time
    print('FRD PARSER TEST\n\n')
    counter = 1
    for file_name in scan_all_files_in(folder, '.frd'):
        relpath = os.path.relpath(file_name, start=os.getcwd())
        print('\n{}\n{}: {}'.format('='*50, counter, relpath))
        FRDParser.Parse(file_name)
        counter += 1
    print('\nTotal {:.1f} seconds'.format(time.perf_counter() - start))
Exemple #13
0
def test_binary_in(folder):
    print('CONVERTER TEST\n\n')
    start = time.perf_counter() # start time
    for file_name in scan_all_files_in(folder, '.frd'):
        if os.name == 'nt':
            command = 'bin\\ccx2paraview.exe'
        else:
            command = './bin/ccx2paraview'
        for fmt in ['vtk', 'vtu']:
            print('\n' + '='*50)
            subprocess.run('{} {} {}'.format(command, file_name, fmt), shell=True)

    print('\nTotal {:.1f} seconds'.format(time.perf_counter() - start))
Exemple #14
0
def backup_files(list):
    files = list.split(' ')
    dst = os.path.expanduser("~") + "/.backup-dotfiles"

    log.print("{} Exits? {}".format(dst, os.path.exists(dst)), LogLevel.Debug)

    # check if there is already a backup dir, if not make it
    if (not os.path.exists(dst)):
        log.print("creating directory " + dst, LogLevel.Info)
        os.makedirs(dst)

    #loop through our files, if it exits move it to the backup directory
    for f in files:
        path = os.path.expanduser("~") + "/" + f

        if (os.path.isfile(path)):  #exits
            try:
                shutil.move(path, dst)
            except Exception as e:
                log.print("Skipped file: {}".format(path), LogLevel.Warn)
            else:
                log.print("Moving {} to {}".format(path, dst), LogLevel.Info)
Exemple #15
0
def install_files(list):
    for v in list:
        if shutil.which(v) is None:  # package doesn't exist
            print("Installing: {}".format(v))

            # install the package
            try:
                ret = subprocess.run(['sudo', 'apt-get', 'install', v],
                                     check=True)
            except subprocess.CalledProcessError as err:
                log.print("Error: {}".format(err),
                          LogLevel.Error)  # an error occured
            else:
                log.print(
                    "{} installed".format(v),
                    LogLevel.Info)  # everything went well, package installed

        else:  # package is already installed
            log.print("{} is already installed".format(v), LogLevel.Info)
Exemple #16
0
def link_files(list):
    for k, v in list.items():
        if (os.path.exists(v)):  # if we have a config file for it
            dest_file = os.path.expanduser(k)

            if (not os.path.islink(dest_file)
                ):  # we don't need to link if it already is
                source_file = os.path.abspath(v)

                try:
                    os.symlink(source_file, dest_file)
                except OSError as e:
                    log.print("Failed to link file: {}".format(dest_file),
                              LogLevel.Error)
                else:
                    log.print(
                        "Linked file: {} -> {}".format(dest_file, source_file),
                        LogLevel.Info)
            else:  #
                log.print("{} already linked".format(dest_file), LogLevel.Warn)
Exemple #17
0
def check_root():
    if (os.getuid() != 0):
        log.print("must be root to run", LogLevel.Error)
        sys.exit()
Exemple #18
0
        try:
            process = subprocess.Popen(cmd,
                                       stdin=subprocess.PIPE,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.STDOUT)
            read_and_log(process.stdout)
        except:
            logging.error(traceback.format_exc())


# Run
if __name__ == '__main__':
    start = time.perf_counter()
    clean.screen()

    # Prepare logging
    logging.getLogger().addHandler(myHandler())
    logging.getLogger().setLevel(logging.DEBUG)

    folder = os.path.abspath(__file__)
    folder = os.path.dirname(folder)
    folder = os.path.join(folder, '..', 'examples')
    folder = os.path.normpath(folder)

    # Choose what we test
    convert_unv_files_in(folder)
    # test_binary_in(folder)

    print('\nTotal {:.1f} seconds'.format(time.perf_counter() - start))
    clean.cache()