Skip to content

Instantly share code, notes, and snippets.

@rmehta
Created January 21, 2013 08:49
Show Gist options
  • Save rmehta/4584676 to your computer and use it in GitHub Desktop.
Save rmehta/4584676 to your computer and use it in GitHub Desktop.
Script to read txt doctypes and update report permissions to 1
# 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