From cad756ba18c1d44051b2933649009b8ada66366b Mon Sep 17 00:00:00 2001 From: Rod Persky Date: Fri, 16 May 2014 15:43:42 +1000 Subject: [PATCH 1/2] Added parameter for path to JSON_to_CPP.py set path through --path that is the root directory for the code. The default is None as this was the previous behavior, however this does not make sense. Also the path name is normalised as, depending on OS there is confusion on slash direction. --- dev/JSON_to_CPP.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/dev/JSON_to_CPP.py b/dev/JSON_to_CPP.py index 9894cc3a..2546c643 100644 --- a/dev/JSON_to_CPP.py +++ b/dev/JSON_to_CPP.py @@ -2,6 +2,7 @@ import json as pyjson from datetime import datetime import struct import os +import argparse, textwrap # 0: Input file path relative to dev folder # 1: Output file path relative to include folder @@ -18,6 +19,9 @@ def TO_CPP(root_dir): n=1 return [l[i:i+n] for i in range(0, len(l), n)] + # Normalise path name + root_dir = os.path.normpath(root_dir) + # First we package up the JSON files import package_json package_json.package_json(root_dir) @@ -49,4 +53,19 @@ def TO_CPP(root_dir): f.close() if __name__=='__main__': - TO_CPP() \ No newline at end of file + parser = argparse.ArgumentParser( + formatter_class=argparse.RawDescriptionHelpFormatter, + description=textwrap.dedent("""CoolProp + This program converts the JSON files from dev/fluid etc + to header files. It is necessary to give this program the + value for --path, this is the root directory where + dev/ can be found.""") + ) + + parser.add_argument('--path', required=False, + help='Location of the root folder', + default=None) + + args = parser.parse_args() + + TO_CPP(args.path) \ No newline at end of file From cd571e67977933036a66d52cca24cb968b508297 Mon Sep 17 00:00:00 2001 From: Rod Persky Date: Fri, 16 May 2014 16:36:44 +1000 Subject: [PATCH 2/2] Path generate_headers.py may not be called from the correct path, so get the path of generate_headers.py and determine the base path from there assuming generate_headers.py will be in dev/ --- dev/generate_headers.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dev/generate_headers.py b/dev/generate_headers.py index ab521900..3ed8dfb9 100644 --- a/dev/generate_headers.py +++ b/dev/generate_headers.py @@ -80,7 +80,11 @@ def gitrev_to_file(root_dir): pass if __name__=='__main__': - version_to_file(root_dir = '..') - gitrev_to_file(root_dir = '..') + path = os.path.abspath(__file__) + path = os.path.dirname(path) + path = os.path.dirname(path) + + version_to_file(root_dir = path) + gitrev_to_file(root_dir = path) import JSON_to_CPP - JSON_to_CPP.TO_CPP(root_dir = '..') \ No newline at end of file + JSON_to_CPP.TO_CPP(root_dir = path) \ No newline at end of file