def reset_doc(doctype): ''' doctype = name of the DocType that you want to reset ''' # fetch module name module = frappe.db.get_value('DocType', doctype, 'module') app = utils.get_module_app(module) # get path for doctype's json and its equivalent git url doc_path = os.path.join(get_module_path(module), 'doctype', scrub(doctype), scrub(doctype)+'.json') try: git_link = '/'.join(['https://raw.githubusercontent.com/frappe',\ app, branch, doc_path.split('apps/'+app)[1]]) original_file = urlopen(git_link).read() except: print('Did not find {0} in {1}'.format(doctype, app)) return # load local and original json objects local_doc = json.loads(open(doc_path, 'r').read()) original_doc = json.loads(original_file) remove_duplicate_fields(doctype) set_property_setter(doctype, local_doc, original_doc) make_custom_fields(doctype, local_doc, original_doc) with open(doc_path, 'w+') as f: f.write(original_file) f.close() setup_perms_for(doctype) frappe.db.commit()
def get_script(report_name): report = get_report_doc(report_name) module = report.module or frappe.db.get_value("DocType", report.ref_doctype, "module") module_path = get_module_path(module) report_folder = os.path.join(module_path, "report", scrub(report.name)) script_path = os.path.join(report_folder, scrub(report.name) + ".js") print_path = os.path.join(report_folder, scrub(report.name) + ".html") script = None if os.path.exists(script_path): with open(script_path, "r") as f: script = f.read() html_format = get_html_format(print_path) if not script and report.javascript: script = report.javascript if not script: script = "frappe.query_reports['%s']={}" % report_name # load translations if frappe.lang != "en": send_translations(frappe.get_lang_dict("report", report_name)) return { "script": script, "html_format": html_format }
def get_file_path(module, dt, dn): dt, dn = scrub_dt_dn(dt, dn) path = os.path.join(get_module_path(module), os.path.join(dt, dn, dn + ".json")) return path
def load_assets(self): from frappe.modules import get_module_path, scrub import os path = os.path.join(get_module_path(self.module), "page", scrub(self.name)) # script fpath = os.path.join(path, scrub(self.name) + ".js") if os.path.exists(fpath): with open(fpath, "r") as f: self.script = unicode(f.read(), "utf-8") # css fpath = os.path.join(path, scrub(self.name) + ".css") if os.path.exists(fpath): with open(fpath, "r") as f: self.style = unicode(f.read(), "utf-8") # html fpath = os.path.join(path, scrub(self.name) + ".html") if os.path.exists(fpath): with open(fpath, "r") as f: self.content = unicode(f.read(), "utf-8") if frappe.lang != "en": from frappe.translate import get_lang_js self.script += get_lang_js("page", self.name)
def on_update(self): """ Writes the .txt for this page and if write_content is checked, it will write out a .html file """ from frappe.core.doctype.doctype.doctype import make_module_and_roles make_module_and_roles(self, "roles") if not frappe.flags.in_import and getattr( conf, 'developer_mode', 0) and self.standard == 'Yes': from frappe.modules.export_file import export_to_files from frappe.modules import get_module_path, scrub import os export_to_files(record_list=[['Page', self.name]]) # write files path = os.path.join(get_module_path(self.module), 'page', scrub(self.name), scrub(self.name)) # js if not os.path.exists(path + '.js'): with open(path + '.js', 'w') as f: f.write( """frappe.pages['%s'].on_page_load = function(wrapper) { var page = frappe.ui.make_app_page({ parent: wrapper, title: '%s', single_column: true }); }""" % (self.name, self.title))
def export_customizations(module, doctype, sync_on_migrate=0): """Export Custom Field and Property Setter for the current document to the app folder. This will be synced with bench migrate""" if not frappe.get_conf().developer_mode: raise 'Not developer mode' custom = { 'custom_fields': [], 'property_setters': [], 'doctype': doctype, 'sync_on_migrate': 1 } def add(_doctype): custom['custom_fields'] += frappe.get_all('Custom Field', fields='*', filters={'dt': _doctype}) custom['property_setters'] += frappe.get_all( 'Property Setter', fields='*', filters={'doc_type': _doctype}) add(doctype) # add custom fields and property setters for all child tables for d in frappe.get_meta(doctype).get_table_fields(): add(d.options) folder_path = os.path.join(get_module_path(module), 'custom') if not os.path.exists(folder_path): os.makedirs(folder_path) path = os.path.join(folder_path, scrub(doctype) + '.json') with open(path, 'w') as f: f.write(frappe.as_json(custom)) frappe.msgprint('Customizations exported to {0}'.format(path))
def get_config(name): doc = frappe.get_doc('Dashboard Chart Source', name) with open( os.path.join(get_module_path(doc.module), 'dashboard_chart_source', scrub(doc.name), scrub(doc.name) + '.js'), 'r') as f: return f.read()
def get_script(report_name): report = get_report_doc(report_name) module = frappe.db.get_value("DocType", report.ref_doctype, "module") module_path = get_module_path(module) report_folder = os.path.join(module_path, "report", scrub(report.name)) script_path = os.path.join(report_folder, scrub(report.name) + ".js") script = None if os.path.exists(script_path): with open(script_path, "r") as script: script = script.read() if not script and report.javascript: script = report.javascript if not script: script = "frappe.query_reports['%s']={}" % report_name # load translations if frappe.lang != "en": frappe.response["__messages"] = frappe.get_lang_dict( "report", report_name) return script
def export_customizations(module, doctype, sync_on_migrate=0): """Export Custom Field and Property Setter for the current document to the app folder. This will be synced with bench migrate""" if not frappe.get_conf().developer_mode: raise 'Not developer mode' custom = {'custom_fields': [], 'property_setters': [], 'doctype': doctype, 'sync_on_migrate': 1} def add(_doctype): custom['custom_fields'] += frappe.get_all('Custom Field', fields='*', filters={'dt': _doctype}) custom['property_setters'] += frappe.get_all('Property Setter', fields='*', filters={'doc_type': _doctype}) add(doctype) # add custom fields and property setters for all child tables for d in frappe.get_meta(doctype).get_table_fields(): add(d.options) folder_path = os.path.join(get_module_path(module), 'custom') if not os.path.exists(folder_path): os.makedirs(folder_path) path = os.path.join(folder_path, scrub(doctype)+ '.json') with open(path, 'w') as f: f.write(frappe.as_json(custom)) frappe.msgprint('Customizations exported to {0}'.format(path))
def load_assets(self): import os from frappe.modules import get_module_path, scrub self.script = "" page_name = scrub(self.name) path = os.path.join(get_module_path(self.module), "page", page_name) # script fpath = os.path.join(path, page_name + ".js") if os.path.exists(fpath): with open(fpath, "r") as f: self.script = render_include(f.read()) self.script += f"\n\n//# sourceURL={page_name}.js" # css fpath = os.path.join(path, page_name + ".css") if os.path.exists(fpath): with open(fpath, "r") as f: self.style = safe_decode(f.read()) # html as js template for fname in os.listdir(path): if fname.endswith(".html"): with open(os.path.join(path, fname), "r") as f: template = f.read() if "<!-- jinja -->" in template: context = frappe._dict({}) try: out = frappe.get_attr( "{app}.{module}.page.{page}.{page}.get_context" .format(app=frappe.local.module_app[scrub( self.module)], module=scrub(self.module), page=page_name))(context) if out: context = out except (AttributeError, ImportError): pass template = frappe.render_template(template, context) self.script = html_to_js_template(fname, template) + self.script # flag for not caching this page self._dynamic_page = True if frappe.lang != "en": from frappe.translate import get_lang_js self.script += get_lang_js("page", self.name) for path in get_code_files_via_hooks("page_js", self.name): js = get_js(path) if js: self.script += "\n\n" + js
def add_code(self): if self.custom: return path = os.path.join(get_module_path(self.module), 'doctype', scrub(self.name)) def _get_path(fname): return os.path.join(path, scrub(fname)) system_country = frappe.get_system_settings("country") self._add_code(_get_path(self.name + '.js'), '__js') if system_country: self._add_code(_get_path(os.path.join('regional', system_country + '.js')), '__js') self._add_code(_get_path(self.name + '.css'), "__css") self._add_code(_get_path(self.name + '_list.js'), '__list_js') if system_country: self._add_code(_get_path(os.path.join('regional', system_country + '_list.js')), '__list_js') self._add_code(_get_path(self.name + '_calendar.js'), '__calendar_js') self._add_code(_get_path(self.name + '_tree.js'), '__tree_js') listview_template = _get_path(self.name + '_list.html') if os.path.exists(listview_template): self.set("__listview_template", get_html_format(listview_template)) self.add_code_via_hook("doctype_js", "__js") self.add_code_via_hook("doctype_list_js", "__list_js") self.add_code_via_hook("doctype_tree_js", "__tree_js") self.add_code_via_hook("doctype_calendar_js", "__calendar_js") self.add_html_templates(path)
def add_code(self): path = os.path.join(get_module_path(self.module), 'doctype', scrub(self.name)) def _get_path(fname): return os.path.join(path, scrub(fname)) system_country = frappe.get_system_settings("country") self._add_code(_get_path(self.name + '.js'), '__js') if system_country: self._add_code(_get_path(os.path.join('regional', system_country + '.js')), '__js') self._add_code(_get_path(self.name + '.css'), "__css") self._add_code(_get_path(self.name + '_list.js'), '__list_js') self._add_code(_get_path(self.name + '_calendar.js'), '__calendar_js') self._add_code(_get_path(self.name + '_tree.js'), '__tree_js') listview_template = _get_path(self.name + '_list.html') if os.path.exists(listview_template): self.set("__listview_template", get_html_format(listview_template)) self.add_code_via_hook("doctype_js", "__js") self.add_code_via_hook("doctype_list_js", "__list_js") self.add_code_via_hook("doctype_tree_js", "__tree_js") self.add_code_via_hook("doctype_calendar_js", "__calendar_js") self.add_custom_script() self.add_html_templates(path)
def load_assets(self): from frappe.modules import get_module_path, scrub import os path = os.path.join(get_module_path(self.module), 'page', scrub(self.name)) # script fpath = os.path.join(path, scrub(self.name) + '.js') if os.path.exists(fpath): with open(fpath, 'r') as f: self.script = f.read() # css fpath = os.path.join(path, scrub(self.name) + '.css') if os.path.exists(fpath): with open(fpath, 'r') as f: self.style = f.read() # html fpath = os.path.join(path, scrub(self.name) + '.html') if os.path.exists(fpath): with open(fpath, 'r') as f: self.content = f.read() if frappe.lang != 'en': from frappe.translate import get_lang_js self.script += get_lang_js("page", self.name)
def on_update(self): """ Writes the .txt for this page and if write_content is checked, it will write out a .html file """ from frappe import conf from frappe.core.doctype.doctype.doctype import make_module_and_roles make_module_and_roles(self, "roles") if not frappe.flags.in_import and getattr(conf,'developer_mode', 0) and self.standard=='Yes': from frappe.modules.export_file import export_to_files from frappe.modules import get_module_path, scrub import os export_to_files(record_list=[['Page', self.name]]) # write files path = os.path.join(get_module_path(self.module), 'page', scrub(self.name), scrub(self.name)) # js if not os.path.exists(path + '.js'): with open(path + '.js', 'w') as f: f.write("""frappe.pages['%s'].on_page_load = function(wrapper) { var page = frappe.ui.make_app_page({ parent: wrapper, title: '%s', single_column: true }); }""" % (self.name, self.title))
def load_assets(self): from frappe.modules import get_module_path, scrub import os path = os.path.join(get_module_path(self.module), 'page', scrub(self.name)) # script fpath = os.path.join(path, scrub(self.name) + '.js') if os.path.exists(fpath): with open(fpath, 'r') as f: self.script = unicode(f.read(), "utf-8") # css fpath = os.path.join(path, scrub(self.name) + '.css') if os.path.exists(fpath): with open(fpath, 'r') as f: self.style = unicode(f.read(), "utf-8") # html as js template for fname in os.listdir(path): if fname.endswith(".html"): with open(os.path.join(path, fname), 'r') as f: template = unicode(f.read(), "utf-8") self.script = html_to_js_template(fname, template) + self.script if frappe.lang != 'en': from frappe.translate import get_lang_js self.script += get_lang_js("page", self.name)
def on_update(self): """ Writes the .txt for this page and if write_content is checked, it will write out a .html file """ if not frappe.flags.in_import and getattr(frappe.get_conf(),'developer_mode', 0) and self.is_standard: from frappe.modules.export_file import export_to_files from frappe.modules import get_module_path, scrub import os # json export_to_files(record_list=[['Web Form', self.name]]) # write files path = os.path.join(get_module_path(self.module), 'web_form', scrub(self.name), scrub(self.name)) # js if not os.path.exists(path + '.js'): with open(path + '.js', 'w') as f: f.write("""frappe.ready(function() { // bind events here })""") # py if not os.path.exists(path + '.py'): with open(path + '.py', 'w') as f: f.write("""from __future__ import unicode_literals import frappe def get_context(context): # do your magic here pass """)
def get_test_records(doctype): from frappe.modules import get_doctype_module, get_module_path path = os.path.join(get_module_path(get_doctype_module(doctype)), "doctype", scrub(doctype), "test_records.json") if os.path.exists(path): with open(path, "r") as f: return json.loads(f.read()) else: return []
def get_config(name): doc = frappe.get_doc("Dashboard Chart Source", name) with open( os.path.join(get_module_path(doc.module), "dashboard_chart_source", scrub(doc.name), scrub(doc.name) + ".js"), "r", ) as f: return f.read()
def get_test_records(doctype): """Returns list of objects from `test_records.json` in the given doctype's folder.""" from frappe.modules import get_doctype_module, get_module_path path = os.path.join(get_module_path(get_doctype_module(doctype)), "doctype", scrub(doctype), "test_records.json") if os.path.exists(path): with open(path, "r") as f: return json.loads(f.read()) else: return []
def switch_module(dt, dn, to, frm=None, export=None): """ Change the module of the given doctype, if export is true, then also export txt and copy code files from src """ frappe.db.sql("update `tab"+dt+"` set module=%s where name=%s", (to, dn)) if export: export_doc(dt, dn) # copy code files if dt in ('DocType', 'Page', 'Report'): from_path = os.path.join(get_module_path(frm), scrub(dt), scrub(dn), scrub(dn)) to_path = os.path.join(get_module_path(to), scrub(dt), scrub(dn), scrub(dn)) # make dire if exists os.system('mkdir -p %s' % os.path.join(get_module_path(to), scrub(dt), scrub(dn))) for ext in ('py','js','html','css'): os.system('cp %s %s')
def load_assets(self): from frappe.modules import get_module_path, scrub import os self.script = '' page_name = scrub(self.name) path = os.path.join(get_module_path(self.module), 'page', page_name) # script fpath = os.path.join(path, page_name + '.js') if os.path.exists(fpath): with open(fpath, 'r') as f: self.script = render_include(f.read()) # css fpath = os.path.join(path, page_name + '.css') if os.path.exists(fpath): with open(fpath, 'r') as f: self.style = safe_decode(f.read()) # html as js template for fname in os.listdir(path): if fname.endswith(".html"): with open(os.path.join(path, fname), 'r') as f: template = f.read() if "<!-- jinja -->" in template: context = frappe._dict({}) try: out = frappe.get_attr("{app}.{module}.page.{page}.{page}.get_context".format( app = frappe.local.module_app[scrub(self.module)], module = scrub(self.module), page = page_name ))(context) if out: context = out except (AttributeError, ImportError): pass template = frappe.render_template(template, context) self.script = html_to_js_template(fname, template) + self.script # flag for not caching this page self._dynamic_page = True if frappe.lang != 'en': from frappe.translate import get_lang_js self.script += get_lang_js("page", self.name) for path in get_code_files_via_hooks("page_js", self.name): js = get_js(path) if js: self.script += "\n\n" + js
def load_assets(self): from frappe.modules import get_module_path, scrub import os page_name = scrub(self.name) path = os.path.join(get_module_path(self.module), 'page', page_name) # script fpath = os.path.join(path, page_name + '.js') if os.path.exists(fpath): with open(fpath, 'r') as f: self.script = unicode(f.read(), "utf-8") # css fpath = os.path.join(path, page_name + '.css') if os.path.exists(fpath): with open(fpath, 'r') as f: self.style = unicode(f.read(), "utf-8") # html as js template for fname in os.listdir(path): if fname.endswith(".html"): with open(os.path.join(path, fname), 'r') as f: template = unicode(f.read(), "utf-8") if "<!-- jinja -->" in template: context = frappe._dict({}) try: out = frappe.get_attr( "{app}.{module}.page.{page}.{page}.get_context" .format(app=frappe.local.module_app[scrub( self.module)], module=scrub(self.module), page=page_name))(context) if out: context = out except (AttributeError, ImportError): pass template = frappe.render_template(template, context) self.script = html_to_js_template(fname, template) + self.script if frappe.lang != 'en': from frappe.translate import get_lang_js self.script += get_lang_js("page", self.name) for path in get_code_files_via_hooks("page_js", self.name): js = get_js(path) if js: self.script += "\n\n" + js
def add_code(self): path = os.path.join(get_module_path(self.module), 'doctype', scrub(self.name)) def _get_path(fname): return os.path.join(path, scrub(fname)) self._add_code(_get_path(self.name + '.js'), '__js') self._add_code(_get_path(self.name + '.css'), "__css") self._add_code(_get_path(self.name + '_list.js'), '__list_js') self._add_code(_get_path(self.name + '_calendar.js'), '__calendar_js') self._add_code(_get_path(self.name + '_map.js'), '__map_js') self.add_custom_script() self.add_code_via_hook("doctype_js", "__js")
def make_controller_template(self): from frappe.modules import get_doc_path, get_module_path, scrub pypath = os.path.join( get_doc_path(self.doc.module, self.doc.doctype, self.doc.name), scrub(self.doc.name) + '.py') if not os.path.exists(pypath): with open(pypath, 'w') as pyfile: with open( os.path.join(get_module_path("core"), "doctype", "doctype", "doctype_template.py"), 'r') as srcfile: pyfile.write(srcfile.read())
def _make_boilerplate(template): template_name = template.replace("controller", scrub(self.name)) target_file_path = os.path.join(target_path, template_name) if not os.path.exists(target_file_path): with open(target_file_path, 'w') as target: with open( os.path.join(get_module_path("core"), "doctype", "doctype", "boilerplate", template), 'r') as source: target.write(source.read().format( app_publisher=app_publisher, classname=self.name.replace(" ", ""), doctype=self.name))
def create_folder(module, dt, dn, create_init): module_path = get_module_path(module) dt, dn = scrub_dt_dn(dt, dn) # create folder folder = os.path.join(module_path, dt, dn) frappe.create_folder(folder) # create init_py_files if create_init: create_init_py(module_path, dt, dn) return folder
def export_module_json(doc, is_standard, module): """Make a folder for the given doc and add its json file (make it a standard object that will be synced)""" if (not frappe.flags.in_import and getattr(frappe.get_conf(),'developer_mode', 0) and is_standard): from frappe.modules.export_file import export_to_files from frappe.modules import get_module_path # json export_to_files(record_list=[[doc.doctype, doc.name]], record_module=module) path = os.path.join(get_module_path(module), scrub(doc.doctype), scrub(doc.name), scrub(doc.name)) return path
def add_code(self): path = os.path.join(get_module_path(self.module), 'doctype', scrub(self.name)) def _get_path(fname): return os.path.join(path, scrub(fname)) self._add_code(_get_path(self.name + '.js'), '__js') self._add_code(_get_path(self.name + '.css'), "__css") self._add_code(_get_path(self.name + '_list.js'), '__list_js') self._add_code(_get_path(self.name + '_calendar.js'), '__calendar_js') listview_template = _get_path(self.name + '_list.html') if os.path.exists(listview_template): self.set("__listview_template", get_html_format(listview_template)) self.add_code_via_hook("doctype_js", "__js") self.add_custom_script()
def make_controller_template(self): from frappe.modules import get_doc_path, get_module_path, scrub pypath = os.path.join(get_doc_path(self.module, self.doctype, self.name), scrub(self.name) + '.py') if not os.path.exists(pypath): # get app publisher for copyright app = frappe.local.module_app[frappe.scrub(self.module)] if not app: frappe.throw(_("App not found")) app_publisher = frappe.get_hooks(hook="app_publisher", app_name=app)[0] with open(pypath, 'w') as pyfile: with open(os.path.join(get_module_path("core"), "doctype", "doctype", "doctype_template.py"), 'r') as srcfile: pyfile.write(srcfile.read().format(app_publisher=app_publisher, classname=self.name.replace(" ", "")))
def on_update(self): # update custom fields in mappings self.make_custom_fields_for_mappings() if frappe.flags.in_import or frappe.flags.in_test: return if frappe.local.conf.get('developer_mode'): record_list = [['Data Migration Plan', self.name]] for m in self.mappings: record_list.append(['Data Migration Mapping', m.mapping]) export_to_files(record_list=record_list, record_module=self.module) for m in self.mappings: dt, dn = scrub_dt_dn('Data Migration Mapping', m.mapping) create_init_py(get_module_path(self.module), dt, dn)
def make_boilerplate(template, doc, opts=None): target_path = get_doc_path(doc.module, doc.doctype, doc.name) template_name = template.replace("controller", scrub(doc.name)) target_file_path = os.path.join(target_path, template_name) app_publisher = get_app_publisher(doc.module) if not os.path.exists(target_file_path): if not opts: opts = {} with open(target_file_path, 'w') as target: with open(os.path.join(get_module_path("core"), "doctype", scrub(doc.doctype), "boilerplate", template), 'r') as source: target.write(frappe.utils.encode( frappe.utils.cstr(source.read()).format(app_publisher=app_publisher, classname=doc.name.replace(" ", ""), doctype=doc.name, **opts) ))
def create_folder(module, dt, dn, create_init): if frappe.db.get_value('Module Def', module, 'custom'): module_path = get_custom_module_path(module) else: module_path = get_module_path(module) dt, dn = scrub_dt_dn(dt, dn) # create folder folder = os.path.join(module_path, dt, dn) frappe.create_folder(folder) # create init_py_files if create_init: create_init_py(module_path, dt, dn) return folder
def get_script(report_name): report = get_report_doc(report_name) module = report.module or frappe.db.get_value("DocType", report.ref_doctype, "module") is_custom_module = frappe.get_cached_value("Module Def", module, "custom") # custom modules are virtual modules those exists in DB but not in disk. module_path = '' if is_custom_module else get_module_path(module) report_folder = module_path and os.path.join(module_path, "report", scrub(report.name)) script_path = report_folder and os.path.join(report_folder, scrub(report.name) + ".js") print_path = report_folder and os.path.join(report_folder, scrub(report.name) + ".html") script = None if os.path.exists(script_path): with open(script_path, "r") as f: script = f.read() script += f"\n\n//# sourceURL={scrub(report.name)}.js" html_format = get_html_format(print_path) if not script and report.javascript: script = report.javascript script += f"\n\n//# sourceURL={scrub(report.name)}__custom" if not script: script = "frappe.query_reports['%s']={}" % report_name # load translations if frappe.lang != "en": send_translations(frappe.get_lang_dict("report", report_name)) return { "script": render_include(script), "html_format": html_format, "execution_time": frappe.cache().hget("report_execution_time", report_name) or 0, }
def add_code(doctype, doclist): import os from frappe.modules import scrub, get_module_path doc = doclist[0] path = os.path.join(get_module_path(doc.module), 'doctype', scrub(doc.name)) def _add_code(fname, fieldname): fpath = os.path.join(path, fname) if os.path.exists(fpath): with open(fpath, 'r') as f: doc.fields[fieldname] = f.read() _add_code(scrub(doc.name) + '.js', '__js') _add_code(scrub(doc.name) + '.css', '__css') _add_code('%s_list.js' % scrub(doc.name), '__list_js') _add_code('%s_calendar.js' % scrub(doc.name), '__calendar_js') _add_code('%s_map.js' % scrub(doc.name), '__map_js') add_embedded_js(doc)
def on_update(self): """ Writes the .txt for this page and if write_content is checked, it will write out a .html file """ if not frappe.flags.in_import and getattr( frappe.get_conf(), 'developer_mode', 0) and self.is_standard: from frappe.modules.export_file import export_to_files from frappe.modules import get_module_path, scrub import os # json export_to_files(record_list=[['Web Form', self.name]]) # write files path = os.path.join(get_module_path(self.module), 'web_form', scrub(self.name), scrub(self.name)) # js if not os.path.exists(path + '.js'): with open(path + '.js', 'w') as f: f.write("""frappe.ready(function() { // bind events here })""") # py if not os.path.exists(path + '.py'): with open(path + '.py', 'w') as f: f.write("""from __future__ import unicode_literals import frappe def get_context(context): # do your magic here pass """)
def reset_doc(doctype): """ doctype = name of the DocType that you want to reset """ # fetch module name module = frappe.db.get_value("DocType", doctype, "module") app = utils.get_module_app(module) # get path for doctype's json and its equivalent git url doc_path = os.path.join( get_module_path(module), "doctype", scrub(doctype), scrub(doctype) + ".json" ) try: git_link = "/".join( ["https://raw.githubusercontent.com/frappe", app, branch, doc_path.split("apps/" + app)[1]] ) original_file = urlopen(git_link).read() except: print("Did not find {0} in {1}".format(doctype, app)) return # load local and original json objects local_doc = json.loads(open(doc_path, "r").read()) original_doc = json.loads(original_file) remove_duplicate_fields(doctype) set_property_setter(doctype, local_doc, original_doc) make_custom_fields(doctype, local_doc, original_doc) with open(doc_path, "w+") as f: f.write(original_file) f.close() setup_perms_for(doctype) frappe.db.commit()