Created
January 21, 2013 08:49
-
-
Save rmehta/4584676 to your computer and use it in GitHub Desktop.
Script to read txt doctypes and update report permissions to 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add report permission | |
from webnotes.modules.utils import peval_doclist, pprint_doclist | |
import os | |
def do(): | |
for path, folders, files in os.walk('app/'): | |
if (os.path.basename(os.path.dirname(path)) in "doctype"): | |
for f in files: | |
if f.endswith(".txt"): | |
doc_name = f.split(".txt")[0] | |
if doc_name == os.path.basename(path): | |
module_name = path.split(os.sep)[-3] | |
doctype = path.split(os.sep)[-2] | |
name = path.split(os.sep)[-1] | |
if doctype == 'doctype': | |
with open(os.path.join(path, f), 'r') as txtfile: | |
doclist = peval_doclist(txtfile.read()) | |
changed = False | |
if doclist[0].get("issingle",0)==0: | |
for d in doclist: | |
if d["doctype"]=="DocPerm" and d.get("permlevel",0)==0\ | |
and d.get("read",0)==1 and d.get("report",0)==0: | |
d["report"] = 1 | |
changed = True | |
if changed: | |
with open(os.path.join(path, f), 'w') as txtfile: | |
txtfile.write(pprint_doclist(doclist)) | |
print os.path.join(path, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment