[PATCH] libosmocore[master]: build: conv_gen.py: ensure parent dirs of written files exist

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Mon Mar 13 13:35:46 UTC 2017


Review at  https://gerrit.osmocom.org/2042

build: conv_gen.py: ensure parent dirs of written files exist

Previously, this would fail when generating to $builddir if that subtree did
not exist yet in $builddir.

Change-Id: Ia4fba96dcf74a25cf3e515eb3e4f970e0c3cdd54
---
M utils/conv_gen.py
1 file changed, 9 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/42/2042/1

diff --git a/utils/conv_gen.py b/utils/conv_gen.py
index 1ffeb3f..0cdba75 100644
--- a/utils/conv_gen.py
+++ b/utils/conv_gen.py
@@ -306,9 +306,15 @@
 		code = ConvolutionalCode(0, polys, name = name)
 		code.print_state_and_output(fi)
 
+def open_for_writing(parent_dir, base_name):
+	path = os.path.join(parent_dir, base_name)
+	if not os.path.isdir(parent_dir):
+		os.makedirs(parent_dir)
+	return open(path, 'w')
+
 def generate_codes(codes, path, prefix, name):
 	# Open a new file for writing
-	f = open(os.path.join(path, name), 'w')
+	f = open_for_writing(path, name)
 	f.write(mod_license + "\n")
 	f.write("#include <stdint.h>\n")
 	f.write("#include <osmocom/core/conv.h>\n\n")
@@ -335,7 +341,7 @@
 
 def generate_vectors(codes, path, prefix, name, inc = None):
 	# Open a new file for writing
-	f = open(os.path.join(path, name), 'w')
+	f = open_for_writing(path, name)
 	f.write(mod_license + "\n")
 
 	# Print includes
@@ -363,7 +369,7 @@
 
 def generate_header(codes, path, prefix, name, description = None):
 	# Open a new file for writing
-	f = open(os.path.join(path, name), 'w')
+	f = open_for_writing(path, name)
 
 	# Print license and includes
 	f.write(mod_license + "\n")

-- 
To view, visit https://gerrit.osmocom.org/2042
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia4fba96dcf74a25cf3e515eb3e4f970e0c3cdd54
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list