From 13a6132a0a29da3a8d8af5d25ad4876fbcbac0a9 Mon Sep 17 00:00:00 2001 From: imirzov Date: Mon, 11 May 2020 21:22:57 +0200 Subject: [PATCH] Release v1.1 --- INPWriter.py | 16 +++------- UNVParser.py | 26 +++++++-------- clean.py | 17 ++++------ make_release.py | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ tests.py | 15 ++++----- unv2ccx.py | 17 ++++------ 6 files changed, 121 insertions(+), 54 deletions(-) create mode 100644 make_release.py diff --git a/INPWriter.py b/INPWriter.py index 183653f..4f7e4d5 100644 --- a/INPWriter.py +++ b/INPWriter.py @@ -1,19 +1,16 @@ # -*- coding: utf-8 -*- - -""" - © Joël Cugnoni, September 2006 - original code, www.caelinux.com - © Ihor Mirzov, August 2019 - refactoring - Distributed under GNU General Public License v3.0 - - Writes FEM nodes, elements and groups (node and element sets) into INP file. """ +© Joël Cugnoni, September 2006 - original code, www.caelinux.com +© Ihor Mirzov, August 2019 - refactoring +Distributed under GNU General Public License v3.0 +Writes FEM nodes, elements and groups +(node and element sets) into INP file. """ import os, logging, re PADDING = ' '*4 # four spaces - # Main function def write(FEM, filename): @@ -62,7 +59,6 @@ def write(FEM, filename): f.write('*ELSET, ELSET=' + group.name) writeGroup(f, group) - # Write node or element set def writeGroup(f, group): for i in range(group.nitems): @@ -71,7 +67,6 @@ def writeGroup(f, group): f.write('{:d}, '.format(group.items[i])) f.write('\n') - # Convert UNV element type to CalculiX def convert_element(unv_element_type): @@ -169,7 +164,6 @@ def convert_element(unv_element_type): else: return None - # Map of the nodes between Universal and Calculix elements def element_connectivity(ccx_element_type): diff --git a/UNVParser.py b/UNVParser.py index 21edbab..6f2bdec 100644 --- a/UNVParser.py +++ b/UNVParser.py @@ -1,25 +1,23 @@ # -*- coding: utf-8 -*- - """ - © Joël Cugnoni, September 2006 - original code, www.caelinux.com - © Ihor Mirzov, August 2019 - refactoring - Distributed under GNU General Public License v3.0 +© Joël Cugnoni, September 2006 - original code, www.caelinux.com +© Ihor Mirzov, August 2019 - refactoring +Distributed under GNU General Public License v3.0 - This is a set of objects & functions to read a Universal File - into a simple FEM object structure in order to simplify the - conversion of Mesh definitions from UNV to any other format. +This is a set of objects & functions to read a Universal File +into a simple FEM object structure in order to simplify the +conversion of Mesh definitions from UNV to any other format. - This code is based on two main objects: - 1) FEM object structure to store nodes, elements and groups. - 2) UNVParser which provides a simple & modular solution to read - some datasets from UNV file and store them in a FEM object structure. +This code is based on two main objects: +1) FEM object structure to store nodes, elements and groups. +2) UNVParser which provides a simple & modular solution to read +some datasets from UNV file and store them in a FEM object structure. - UNV format documentation: - http://sdrl.uc.edu/sdrl/referenceinfo/universalfileformats/file-format-storehouse/universal-file-datasets-summary +UNV format documentation: +http://sdrl.uc.edu/sdrl/referenceinfo/universalfileformats/file-format-storehouse/universal-file-datasets-summary """ - import logging, FEM FLAG = ' -1' diff --git a/clean.py b/clean.py index bdb13b3..69e7307 100644 --- a/clean.py +++ b/clean.py @@ -1,29 +1,24 @@ # -*- coding: utf-8 -*- +""" © Ihor Mirzov, August 2019 +Distributed under GNU General Public License v3.0 -""" - © Ihor Mirzov, August 2019 - Distributed under GNU General Public License v3.0 - - Routine methods for cleaning up temporary/unused files/folders. -""" - - -import os, sys, shutil +Routine methods for cleaning up temporary/unused files/folders. """ +import os +import sys +import shutil # Clean screen def screen(): os.system('cls' if os.name=='nt' else 'clear') - # Delete cached files def cache(): # os.system('py3clean .') if os.path.isdir('__pycache__'): shutil.rmtree('__pycache__') # works in Linux as in Windows - # Cleaup trash files in startFolder and all subfolders def files(startFolder): extensions = ( '.12d', '.cvg', '.dat', '.vwf', '.out', '.nam', '.inp1', '.inp2', diff --git a/make_release.py b/make_release.py new file mode 100644 index 0000000..d0db8d1 --- /dev/null +++ b/make_release.py @@ -0,0 +1,84 @@ +# -*- coding: utf-8 -*- + +""" © Ihor Mirzov, September 2019 +Distributed under GNU General Public License v3.0 + +Prepare binaries for publishing: +- python3 make_release.py +or 'Ctrl+F5' from VSCode """ + +import clean +import os +import shutil +import datetime +import PyInstaller.__main__ + +def copy(src, dst, skip): + for f in os.listdir(src): + if f!='dist' and not f.endswith(skip): + src_path = os.path.join(src, f) + dst_path = os.path.join('dist', src, f) + + if os.path.isdir(src_path): + if not os.path.isdir(dst_path): + os.mkdir(dst_path) + copy(src_path, dst_path, skip) + + if os.path.isfile(src_path): + shutil.copy2(src_path, dst_path) + +if __name__ == '__main__': + if os.name=='nt': + op_sys = '_windows' + extension = '.exe' # binary extension in OS + TEMP = 'C:\\Windows\\Temp\\' + else: + op_sys = '_linux' + extension = '' # binary extension in OS + TEMP = '/tmp/' + + skip = (op_sys, ) + PROJECT_NAME = os.path.split(os.getcwd())[-1] # name of project's folder + DATE = '_' + datetime.datetime.now().strftime('%Y%m%d') + ARCH = os.path.join('./releases', PROJECT_NAME + DATE + op_sys) + + # Remove prev. trash + if os.path.isdir('./dist'): + shutil.rmtree('./dist') + + # Run pyinstaller to create binaries + args = [ + './unv2ccx.py', + '--workpath=' + TEMP, # temp dir + '-w', # no console during app run + '--onefile', + ] + PyInstaller.__main__.run(args) + + # Delete cached files + clean.cache() + + # Delete .spec file + if os.path.isfile('unv2ccx.spec'): + os.remove('unv2ccx.spec') + + # Prepare skip list + with open('.gitignore', 'r') as f: + lines = f.readlines() + for i in range(len(lines)): + skip += (lines[i].rstrip().lstrip('*'), ) + skip += ('.git', '.gitignore', '.py', 'dist') + + # Copy files and folders from sources to 'dist' + copy('.', 'dist', skip) + + # Make archive + if os.path.isfile(ARCH + '.zip'): + os.remove(ARCH + '.zip') # delete old + + # Complress whole directory + shutil.make_archive(ARCH, 'zip', 'dist') + + # Remove unneeded files and folders + shutil.rmtree(TEMP + 'unv2ccx') + shutil.rmtree(os.path.abspath('dist')) diff --git a/tests.py b/tests.py index 2e1ef6c..985d99c 100644 --- a/tests.py +++ b/tests.py @@ -1,12 +1,11 @@ # -*- coding: utf-8 -*- -""" - © Ihor Mirzov, April 2019 - Distributed under GNU General Public License v3.0 +""" © Ihor Mirzov, May 2020 +Distributed under GNU General Public License v3.0 - Usage: - python3 tests.py -""" +Usage: +- python3 tests.py +or 'Ctrl+F5' from VSCode """ import subprocess, os, clean @@ -30,7 +29,9 @@ def listAllFiles(startFolder, ext): # Convert calculation results for filename in listAllFiles('./tests', '.unv'): - subprocess.run('python3 unv2ccx.py ' + filename, shell=True) + # subprocess.run('python3 unv2ccx.py ' + filename, shell=True) + cmd = 'unv2ccx{} {}'.format(extension, filename) + subprocess.run(cmd, shell=True) # break # one file only clean.cache() diff --git a/unv2ccx.py b/unv2ccx.py index e46ce20..230b153 100644 --- a/unv2ccx.py +++ b/unv2ccx.py @@ -1,22 +1,17 @@ # -*- coding: utf-8 -*- +""" © Ihor Mirzov, August 2019 +Distributed under GNU General Public License v3.0 -""" - © Ihor Mirzov, August 2019 - Distributed under GNU General Public License v3.0 - - Converts UNV file from Salome to CalculiX INP mesh: reads UNV_file, - creates an internal FEM object, then writes the INP_file. - - Usage: - python3 unv2ccx.py ./tests-elements/116.unv -""" +Converts UNV file from Salome to CalculiX INP mesh: reads UNV_file, +creates an internal FEM object, then writes the INP_file. +Usage: +python3 unv2ccx.py ./tests-elements/116.unv """ import os, argparse, logging, shutil, INPWriter from UNVParser import * - if __name__ == '__main__': # Clean cached files