def make_asset_dirs(make_copy=False, restore=False): # don't even think of making assets_path absolute - rm -rf ahead. assets_path = os.path.join(dataent.local.sites_path, "assets") for dir_path in [ os.path.join(assets_path, 'js'), os.path.join(assets_path, 'css') ]: if not os.path.exists(dir_path): os.makedirs(dir_path) # symlink app/public > assets/app for app_name in dataent.get_all_apps(True): pymodule = dataent.get_module(app_name) app_base_path = os.path.abspath(os.path.dirname(pymodule.__file__)) symlinks = [] symlinks.append([ os.path.join(app_base_path, 'public'), os.path.join(assets_path, app_name) ]) app_doc_path = None if os.path.isdir(os.path.join(app_base_path, 'docs')): app_doc_path = os.path.join(app_base_path, 'docs') elif os.path.isdir(os.path.join(app_base_path, 'www', 'docs')): app_doc_path = os.path.join(app_base_path, 'www', 'docs') if app_doc_path: symlinks.append( [app_doc_path, os.path.join(assets_path, app_name + '_docs')]) for source, target in symlinks: source = os.path.abspath(source) if os.path.exists(source): if restore: if os.path.exists(target): if os.path.islink(target): os.unlink(target) else: shutil.rmtree(target) shutil.copytree(source, target) elif make_copy: if os.path.exists(target): warnings.warn('Target {target} already exists.'.format( target=target)) else: shutil.copytree(source, target) else: if os.path.exists(target): if os.path.islink(target): os.unlink(target) else: shutil.rmtree(target) os.symlink(source, target) else: # warnings.warn('Source {source} does not exist.'.format(source = source)) pass
def setup_app_context(self): self.docs_config = dataent.get_module(self.app + ".config.docs") version = get_version(app=self.app) self.app_context = { "app": dataent._dict({ "name": self.app, "title": self.app_title, "description": self.hooks.get("app_description")[0], "version": version, "publisher": self.hooks.get("app_publisher")[0], "icon": self.hooks.get("app_icon")[0], "email": self.hooks.get("app_email")[0], "source_link": self.docs_config.source_link, "license": self.hooks.get("app_license")[0], "branch": getattr(self.docs_config, "branch", None) or "develop", }), "metatags": { "description": self.hooks.get("app_description")[0], }, "get_doctype_app": dataent.get_doctype_app }
def get_version(): "Show the versions of all the installed apps" from dataent.utils.change_log import get_app_branch dataent.init('') for m in sorted(dataent.get_all_apps()): branch_name = get_app_branch(m) module = dataent.get_module(m) app_hooks = dataent.get_module(m + ".hooks") if hasattr(app_hooks, '{0}_version'.format(branch_name)): print("{0} {1}".format( m, getattr(app_hooks, '{0}_version'.format(branch_name)))) elif hasattr(module, "__version__"): print("{0} {1}".format(m, module.__version__))
def get_doc_module(module, doctype, name): """Get custom module for given document""" module_name = "{app}.{module}.{doctype}.{name}.{name}".format( app=dataent.local.module_app[scrub(module)], doctype=scrub(doctype), module=scrub(module), name=scrub(name)) return dataent.get_module(module_name)
def setup(): global app_paths pymodules = [] for app in dataent.get_all_apps(True): try: pymodules.append(dataent.get_module(app)) except ImportError: pass app_paths = [os.path.dirname(pymodule.__file__) for pymodule in pymodules]
def get_mapping_module(self, mapping_name): try: module_def = dataent.get_doc("Module Def", self.module) module = dataent.get_module('{app}.{module}.data_migration_mapping.{mapping_name}'.format( app= module_def.app_name, module=dataent.scrub(self.module), mapping_name=dataent.scrub(mapping_name) )) return module except ImportError: return None
def get_config(app, module): """Load module info from `[app].config.[module]`.""" config = dataent.get_module("{app}.config.{module}".format(app=app, module=module)) config = config.get_data() for section in config: for item in section["items"]: if item["type"]=="report" and dataent.db.get_value("Report", item["name"], "disabled")==1: section["items"].remove(item) continue if not "label" in item: item["label"] = _(item["name"]) return config
def get_connection_class(python_module): filename = python_module.rsplit('.', 1)[-1] classname = dataent.unscrub(filename).replace(' ', '') module = dataent.get_module(python_module) raise_error = False if hasattr(module, classname): _class = getattr(module, classname) if not issubclass(_class, BaseConnection): raise_error = True else: raise_error = True if raise_error: raise ImportError(filename) return _class
def load_doctype_module(doctype, module=None, prefix="", suffix=""): """Returns the module object for given doctype.""" if not module: module = get_doctype_module(doctype) app = get_module_app(module) key = (app, doctype, prefix, suffix) module_name = get_module_name(doctype, module, prefix, suffix) try: if key not in doctype_python_modules: doctype_python_modules[key] = dataent.get_module(module_name) except ImportError as e: raise ImportError('Module import failed for {0} ({1})'.format( doctype, module_name + ' Error: ' + str(e))) return doctype_python_modules[key]
def sync_for(app_name, force=0, sync_everything = False, verbose=False, reset_permissions=False): files = [] if app_name == "dataent": # these need to go first at time of install for d in (("core", "docfield"), ("core", "docperm"), ("core", "has_role"), ("core", "doctype"), ("core", "user"), ("core", "role"), ("custom", "custom_field"), ("custom", "property_setter"), ("website", "web_form"), ("website", "web_form_field"), ("website", "portal_menu_item"), ("data_migration", "data_migration_mapping_detail"), ("data_migration", "data_migration_mapping"), ("data_migration", "data_migration_plan_mapping"), ("data_migration", "data_migration_plan")): files.append(os.path.join(dataent.get_app_path("dataent"), d[0], "doctype", d[1], d[1] + ".json")) for module_name in dataent.local.app_modules.get(app_name) or []: folder = os.path.dirname(dataent.get_module(app_name + "." + module_name).__file__) get_doc_files(files, folder, force, sync_everything, verbose=verbose) l = len(files) if l: for i, doc_path in enumerate(files): import_file_by_path(doc_path, force=force, ignore_version=True, reset_permissions=reset_permissions, for_sync=True) #print module_name + ' | ' + doctype + ' | ' + name dataent.db.commit() # show progress bar update_progress_bar("Updating DocTypes for {0}".format(app_name), i, l) # print each progress bar on new line print()
def update_controller_context(context, controller): module = dataent.get_module(controller) if module: # get config fields for prop in ("base_template_path", "template", "no_cache", "no_sitemap", "condition_field"): if hasattr(module, prop): context[prop] = getattr(module, prop) if hasattr(module, "get_context"): try: ret = module.get_context(context) if ret: context.update(ret) except (dataent.PermissionError, dataent.DoesNotExistError, dataent.Redirect): raise except: if not dataent.flags.in_migrate: dataent.errprint(dataent.utils.get_traceback()) if hasattr(module, "get_children"): context.children = module.get_children(context)