From fdfe5938c2e4b007970c8ef307534432bab4f95b Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Mon, 3 Mar 2014 14:52:43 +0400 Subject: [PATCH] Read only permissions for generated types --- libuavcan/dsdl_compiler/dsdlc.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libuavcan/dsdl_compiler/dsdlc.py b/libuavcan/dsdl_compiler/dsdlc.py index 99cdba1b9d..75dae5d0ac 100755 --- a/libuavcan/dsdl_compiler/dsdlc.py +++ b/libuavcan/dsdl_compiler/dsdlc.py @@ -18,6 +18,7 @@ from pyuavcan import dsdl MAX_BITLEN_FOR_ENUM = 31 CPP_HEADER_EXTENSION = 'hpp' +CPP_HEADER_PERMISSIONS = 0o444 # Read only for all TEMPLATE_FILENAME = os.path.join(os.path.dirname(__file__), 'data_type_template.hpp') # ----------------- @@ -64,8 +65,12 @@ def run_generator(types, dest_dir): text = generate_one_type(t) with open(file_path, 'w') as f: f.write(text) + try: + os.chmod(file_path, CPP_HEADER_PERMISSIONS) + except (OSError, IOError) as ex: + logging.warning('Failed to set permissions for %s: %s', file_path, ex) except Exception as ex: - logging.info('Generator error', exc_info=True) + logging.info('Generator failure', exc_info=True) die(str(ex)) def type_to_cpp_type(t):