Skip to content

Instantly share code, notes, and snippets.

@mitchute
Last active September 19, 2016 15:34
Show Gist options
  • Save mitchute/ac8ba614f07e29fc44fcc81464af2c43 to your computer and use it in GitHub Desktop.
Save mitchute/ac8ba614f07e29fc44fcc81464af2c43 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# Attempt to automatically change the version number of all idf and imf files in a repo
# Two arguments: old version number and new version number
import sys
import shutil
import fnmatch
import os
import subprocess
import time
import re
# provide a nice usage function
def usage():
print("""Call this script with three command line arguments:
$ transition_run_check.py <path to idfs> <path to eplus build> <path to output dir>
$ transition_run_check.py /repos/eplus /repos/eplus/build/products /tests/transitions""")
# check the command line argument status
if not len(sys.argv) == 4:
print(len(sys.argv))
print("Invalid command line arguments")
usage()
sys.exit(1)
transition_exe_name = "Transition-V8-5-0-to-V8-6-0.exe"
# store the command line arguments since they appear valid so far
path_to_test_files = os.path.abspath(sys.argv[1])
path_to_build = os.path.abspath(sys.argv[2])
path_to_output = os.path.abspath(sys.argv[3])
path_to_build_exe = os.path.join(path_to_build, transition_exe_name)
# walk across
for ext in ['*.idf']:
for root, dirnames, filenames in os.walk(path_to_test_files):
for file in fnmatch.filter(filenames, ext):
try:
# copy to transition
src_file_path = os.path.abspath(os.path.join(root,file))
shutil.copy(src_file_path, path_to_build)
# run transition
test_file_path = os.path.abspath(os.path.join(path_to_build, file))
transition_run = subprocess.Popen(["" + transition_exe_name, os.path.basename(test_file_path)], shell=True, cwd=path_to_build, stderr=subprocess.STDOUT)
transition_run.communicate()
# copy files to test file dir
base_test_file_name = file.split(".")[0]
test_file_dir = os.path.join(path_to_output, base_test_file_name)
os.makedirs(test_file_dir)
print(test_file_dir)
print(path_to_build)
for _,_, files_ in os.walk(path_to_build):
for copyfile in fnmatch.filter(files_, base_test_file_name):
print(copyfile)
shutil.move(os.path.join(path_to_build, copyfile), test_file_dir)
except:
print('')
break
break
@Myoldmopar
Copy link

https://gist.github.com/mitchute/ac8ba614f07e29fc44fcc81464af2c43#file-trany-py-L46

transition_run = subprocess.Popen([path_to_transition_exe, file], stderr=subprocess.STDOUT)
transition_run = subprocess.Popen([path_to_transition_exe, file], cwd=path_to_transition, stderr=subprocess.STDOUT)

@mitchute
Copy link
Author

/home/mitchute/EnergyPlusBuild/Products/AdultEducationCenter.idf: 1: /home/mitchute/EnergyPlusBuild/Products/AdultEducationCenter.idf: ../EnergyPlusBuild/Products/Transition-V8-5-0-to-V8-6-0: not found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment