import re with open('addons/education_lms/security/security.xml', 'r') as f: text = f.read() # Replace all student rules to explicitly have perm_read="True" # We will do this by finding \n # and adding perm_read="True" after it. def replace_perms(match): return match.group(0) + '\n \n \n \n ' # First, remove existing perms to avoid duplicates text = re.sub(r' *\n', '', text) # Now add default perms back to Faculty text = re.sub( r'()', r'\1\n \n \n \n ', text ) # And Admin text = re.sub( r'()', r'\1\n \n \n \n ', text ) # And Student (Read Only except for submission) text = re.sub( r'(.*?)', r'\1\n \n \n \n ', text, flags=re.DOTALL ) # Exception for Student Submission Sandbox (needs write, create, unlink maybe?) # Actually Submission Sandbox might need create/write text = re.sub( r'(.*?)\n \n ', r'\1\n \n ', text, flags=re.DOTALL ) with open('addons/education_lms/security/security.xml', 'w') as f: f.write(text)