def list_apps(context): "List apps in site" site = get_site(context) dataent.init(site=site) dataent.connect() print("\n".join(dataent.get_installed_apps())) dataent.destroy()
def get_version(name): print(name) global installed if not installed: installed = dataent.get_installed_apps() def _for_module(m): app_name = m.split(".")[0] try: docs_version = dataent.get_attr(app_name + ".config.docs.docs_version") except AttributeError: docs_version = None if docs_version: return docs_version return getattr(importlib.import_module(m.split(".")[0]), "__version__", "0.0.0") if "." in name or name in installed: return _for_module(name) else: return _for_module(get_controller(name).__module__)
def before_tests(): if len(dataent.get_installed_apps()) > 1: # don't run before tests if any other app is installed return dataent.db.sql("delete from `tabCustom Field`") dataent.db.sql("delete from `tabEvent`") dataent.db.commit() dataent.clear_cache() # complete setup if missing from dataent.desk.page.setup_wizard.setup_wizard import setup_complete if not int( dataent.db.get_single_value('System Settings', 'setup_complete') or 0): setup_complete({ "language": "english", "email": "*****@*****.**", "full_name": "Test User", "password": "******", "country": "United States", "timezone": "America/New_York", "currency": "USD" }) dataent.db.commit() dataent.clear_cache()
def add_to_installed_apps(app_name, rebuild_website=True): installed_apps = dataent.get_installed_apps() if not app_name in installed_apps: installed_apps.append(app_name) dataent.db.set_global("installed_apps", json.dumps(installed_apps)) dataent.db.commit() post_install(rebuild_website)
def run_all_tests(app=None, verbose=False, profile=False, ui_tests=False, failfast=False): import os apps = [app] if app else dataent.get_installed_apps() test_suite = unittest.TestSuite() for app in apps: for path, folders, files in os.walk(dataent.get_pymodule_path(app)): for dontwalk in ('locals', '.git', 'public'): if dontwalk in folders: folders.remove(dontwalk) # print path for filename in files: filename = cstr(filename) if filename.startswith("test_") and filename.endswith(".py")\ and filename != 'test_runner.py': # print filename[:-3] _add_test(app, path, filename, verbose, test_suite, ui_tests) if profile: pr = cProfile.Profile() pr.enable() out = unittest_runner(verbosity=1+(verbose and 1 or 0), failfast=failfast).run(test_suite) if profile: pr.disable() s = StringIO() ps = pstats.Stats(pr, stream=s).sort_stats('cumulative') ps.print_stats() print(s.getvalue()) return out
def _reinstall(site, admin_password=None, mariadb_root_username=None, mariadb_root_password=None, yes=False, verbose=False): if not yes: click.confirm( 'This will wipe your database. Are you sure you want to reinstall?', abort=True) try: dataent.init(site=site) dataent.connect() dataent.clear_cache() installed = dataent.get_installed_apps() dataent.clear_cache() except Exception: installed = [] finally: if dataent.db: dataent.db.close() dataent.destroy() dataent.init(site=site) _new_site(dataent.conf.db_name, site, verbose=verbose, force=True, reinstall=True, install_apps=installed, mariadb_root_username=mariadb_root_username, mariadb_root_password=mariadb_root_password, admin_password=admin_password)
def create_payment_gateway_and_account(): """If EPAAS is installed, create Payment Gateway and Payment Gateway Account""" if "epaas" not in dataent.get_installed_apps(): return create_payment_gateway() create_payment_gateway_account()
def get_jloader(): import dataent if not getattr(dataent.local, 'jloader', None): from jinja2 import ChoiceLoader, PackageLoader, PrefixLoader if dataent.local.flags.in_setup_help: apps = ['dataent'] else: apps = dataent.get_hooks('template_apps') if not apps: apps = dataent.local.flags.web_pages_apps or dataent.get_installed_apps( sort=True) apps.reverse() if not "dataent" in apps: apps.append('dataent') dataent.local.jloader = ChoiceLoader( # search for something like app/templates/... [ PrefixLoader( dict((app, PackageLoader(app, ".")) for app in apps)) ] # search for something like templates/... + [PackageLoader(app, ".") for app in apps]) return dataent.local.jloader
def make_demo(context, site, domain='Manufacturing', days=100, resume=False, reinstall=False): "Reinstall site and setup demo" from dataent.commands.site import _reinstall from dataent.installer import install_app site = get_site(context) if resume: with dataent.init_site(site): dataent.connect() from epaas.demo import demo demo.simulate(days=days) else: if reinstall: _reinstall(site, yes=True) with dataent.init_site(site=site): dataent.connect() if not 'epaas' in dataent.get_installed_apps(): install_app('epaas') # import needs site from epaas.demo import demo demo.make(domain, days)
def get_versions(): """Get versions of all installed apps. Example: { "dataent": { "title": "Dataent Framework", "version": "5.0.0" } }""" versions = {} for app in dataent.get_installed_apps(sort=True): app_hooks = dataent.get_hooks(app_name=app) versions[app] = { "title": app_hooks.get("app_title")[0], "description": app_hooks.get("app_description")[0], "branch": get_app_branch(app) } if versions[app]['branch'] != 'master': branch_version = app_hooks.get('{0}_version'.format( versions[app]['branch'])) if branch_version: versions[app][ 'branch_version'] = branch_version[0] + ' ({0})'.format( get_app_last_commit_ref(app)) try: versions[app]["version"] = dataent.get_attr(app + ".__version__") except AttributeError: versions[app]["version"] = '0.0.1' return versions
def remove_from_installed_apps(app_name): installed_apps = dataent.get_installed_apps() if app_name in installed_apps: installed_apps.remove(app_name) dataent.db.set_global("installed_apps", json.dumps(installed_apps)) dataent.db.commit() if dataent.flags.in_install: post_install()
def execute(): dataent.clear_cache() installed = dataent.get_installed_apps() if "webnotes" in installed: installed.remove("webnotes") if "dataent" not in installed: installed = ["dataent"] + installed dataent.db.set_global("installed_apps", json.dumps(installed)) dataent.clear_cache()
def _get(): installed_apps = dataent.get_installed_apps() doctypes = dataent.get_hooks("website_generators") doctypes += [ d.name for d in dataent.get_all('DocType', 'name, module', dict(has_web_view=1)) if dataent.local.module_app[dataent.scrub(d.module)] in installed_apps ] return doctypes
def sync_all(force=0, verbose=False, reset_permissions=False): block_user(True) for app in dataent.get_installed_apps(): sync_for(app, force, verbose=verbose, reset_permissions=reset_permissions) block_user(False) dataent.clear_cache()
def get_jenv_customization(customizable_type): import dataent if getattr(dataent.local, "site", None): for app in dataent.get_installed_apps(): for jenv_customizable, jenv_customizable_definition in dataent.get_hooks( app_name=app).get("jenv", {}).items(): if customizable_type == jenv_customizable: for data in jenv_customizable_definition: split_data = data.split(":") yield split_data[0], split_data[1]
def get_all_patches(): patches = [] for app in dataent.get_installed_apps(): if app == "shopping_cart": continue # 3-to-4 fix if app=="webnotes": app="dataent" patches.extend(dataent.get_file_items(dataent.get_pymodule_path(app, "patches.txt"))) return patches
def build_config_from_file(module): """Build module info from `app/config/desktop.py` files.""" data = [] module = dataent.scrub(module) for app in dataent.get_installed_apps(): try: data += get_config(app, module) except ImportError: pass return filter_by_restrict_to_domain(data)
def is_static_file(path): if ('.' not in path): return False extn = path.rsplit('.', 1)[-1] if extn in ('html', 'md', 'js', 'xml', 'css', 'txt', 'py'): return False for app in dataent.get_installed_apps(): file_path = dataent.get_app_path(app, 'www') + '/' + path if os.path.exists(file_path): dataent.flags.file_path = file_path return True return False
def execute(): # setup not complete if not dataent.db.sql("""select name from tabCompany limit 1"""): return if "shopping_cart" in dataent.get_installed_apps(): dataent.reload_doc("shopping_cart", "doctype", "shopping_cart_settings") if not dataent.db.sql("select name from `tabPrice List` where buying=1"): create_price_list(_("Standard Buying"), buying=1) if not dataent.db.sql("select name from `tabPrice List` where selling=1"): create_price_list(_("Standard Selling"), selling=1)
def execute(): installed_apps = dataent.get_installed_apps() for app_details in app_list: if app_details["app_name"] in installed_apps: settings = get_app_settings(app_details) if app_details["remove"]: uninstall_app(app_details["app_name"]) try: setup_integration_service(app_details, settings) except DataError: pass dataent.delete_doc("DocType", "Dropbox Backup")
def sync_global_search(): '''Sync page content in global search''' from dataent.website.render import render_page from dataent.utils.global_search import sync_global_search from bs4 import BeautifulSoup if dataent.flags.update_global_search: sync_global_search() dataent.flags.update_global_search = [] dataent.session.user = '******' dataent.local.no_cache = True dataent.db.sql( 'delete from __global_search where doctype="Static Web Page"') for app in dataent.get_installed_apps(dataent_last=True): app_path = dataent.get_app_path(app) folders = get_start_folders() for start in folders: for basepath, folders, files in os.walk( os.path.join(app_path, start)): for f in files: if f.endswith('.html') or f.endswith('.md'): path = os.path.join(basepath, f.rsplit('.', 1)[0]) try: content = render_page(path) soup = BeautifulSoup(content, 'html.parser') text = '' route = os.path.relpath( path, os.path.join(app_path, start)) for div in soup.findAll("div", {'class': 'page-content'}): text += div.text dataent.flags.update_global_search.append( dict(doctype='Static Web Page', name=route, content=text_type(text), published=1, title=text_type(soup.title.string), route=route)) except Exception: pass sync_global_search()
def get_code_files_via_hooks(hook, name): code_files = [] for app_name in dataent.get_installed_apps(): code_hook = dataent.get_hooks(hook, default={}, app_name=app_name) if not code_hook: continue files = code_hook.get(name, []) if not isinstance(files, list): files = [files] for file in files: path = dataent.get_app_path(app_name, *file.strip("/").split("/")) code_files.append(path) return code_files
def _build(app): pages = {} if app: apps = [app] else: apps = dataent.local.flags.web_pages_apps or dataent.get_installed_apps( ) for app in apps: app_path = dataent.get_app_path(app) for start in get_start_folders(): pages.update(get_pages_from_path(start, app, app_path)) return pages
def inline_style_in_html(html): ''' Convert email.css and html to inline-styled html ''' from premailer import Premailer apps = dataent.get_installed_apps() css_files = [] for app in apps: path = 'assets/{0}/css/email.css'.format(app) if os.path.exists(os.path.abspath(path)): css_files.append(path) p = Premailer(html=html, external_styles=css_files, strip_important=False) return p.transform()
def get_page_info_from_template(path): '''Return page_info from path''' for app in dataent.get_installed_apps(dataent_last=True): app_path = dataent.get_app_path(app) folders = get_start_folders() for start in folders: search_path = os.path.join(app_path, start, path) options = (search_path, search_path + '.html', search_path + '.md', search_path + '/index.html', search_path + '/index.md') for o in options: option = dataent.as_unicode(o) if os.path.exists(option) and not os.path.isdir(option): return get_page_info(option, app, start, app_path=app_path) return None
def get_all_messages_from_js_files(app_name=None): """Extracts all translatable strings from app `.js` files""" messages = [] for app in ([app_name] if app_name else dataent.get_installed_apps()): if os.path.exists(dataent.get_app_path(app, "public")): for basepath, folders, files in os.walk( dataent.get_app_path(app, "public")): if "dataent/public/js/lib" in basepath: continue for fname in files: if fname.endswith(".js") or fname.endswith(".html"): messages.extend( get_messages_from_file( os.path.join(basepath, fname))) return messages
def execute(): dataent.reload_doc('desk', 'doctype', 'desktop_icon') dataent.db.sql('delete from `tabDesktop Icon`') modules_list = [] for app in dataent.get_installed_apps(): modules_list += sync_from_app(app) # sync hidden modules hidden_modules = dataent.db.get_global('hidden_modules') if hidden_modules: for m in json.loads(hidden_modules): try: desktop_icon = dataent.get_doc('Desktop Icon', { 'module_name': m, 'standard': 1, 'app': app }) desktop_icon.db_set('hidden', 1) except dataent.DoesNotExistError: pass # sync user sort for user in dataent.get_all('User', filters={'user_type': 'System User'}): user_list = dataent.defaults.get_user_default('_user_desktop_items', user=user.name) if user_list: user_list = json.loads(user_list) for i, module_name in enumerate(user_list): try: desktop_icon = get_user_copy(module_name, user=user.name) desktop_icon.db_set('idx', i) except dataent.DoesNotExistError: pass # set remaining icons as hidden for module_name in list( set([m['module_name'] for m in modules_list]) - set(user_list)): try: desktop_icon = get_user_copy(module_name, user=user.name) desktop_icon.db_set('hidden', 1) except dataent.DoesNotExistError: pass
def get_html_format(print_path): html_format = None if os.path.exists(print_path): with open(print_path, "r") as f: html_format = f.read() for include_directive, path in re.findall( """({% include ['"]([^'"]*)['"] %})""", html_format): for app_name in dataent.get_installed_apps(): include_path = dataent.get_app_path(app_name, *path.split(os.path.sep)) if os.path.exists(include_path): with open(include_path, "r") as f: html_format = html_format.replace( include_directive, f.read()) break return html_format
def sync_customizations(app=None): '''Sync custom fields and property setters from custom folder in each app module''' if app: apps = [app] else: apps = dataent.get_installed_apps() for app_name in apps: for module_name in dataent.local.app_modules.get(app_name) or []: folder = dataent.get_app_path(app_name, module_name, 'custom') if os.path.exists(folder): for fname in os.listdir(folder): with open(os.path.join(folder, fname), 'r') as f: data = json.loads(f.read()) if data.get('sync_on_migrate'): sync_customizations_for_doctype(data, folder)
def set_redirect(razorpay_express_payment): """ EPAAS related redirects. You need to set Razorpay Payment.flags.redirect_to on status change. Called via RazorpayPayment.on_update """ if "epaas" not in dataent.get_installed_apps(): return if not razorpay_express_payment.flags.status_changed_to: return reference_doctype = razorpay_express_payment.reference_doctype reference_docname = razorpay_express_payment.reference_docname if not (reference_doctype and reference_docname): return reference_doc = dataent.get_doc(reference_doctype, reference_docname) shopping_cart_settings = dataent.get_doc("Shopping Cart Settings") if razorpay_express_payment.flags.status_changed_to == "Authorized": reference_doc.run_method("set_as_paid") # if shopping cart enabled and in session if (shopping_cart_settings.enabled and hasattr(dataent.local, "session") and dataent.local.session.user != "Guest"): success_url = shopping_cart_settings.payment_success_url if success_url: razorpay_express_payment.flags.redirect_to = ({ "Orders": "orders", "Invoices": "invoices", "My Account": "me" }).get(success_url, "me") else: razorpay_express_payment.flags.redirect_to = get_url( "/orders/{0}".format(reference_doc.reference_name))