Ejemplo n.º 1
0
def load_lang(lang, apps=None):
    """Combine all translations from `.csv` files in all `apps`.
	For derivative languages (es-GT), take translations from the
	base language (es) and then update translations from the child (es-GT)"""

    if lang == 'en':
        return {}

    out = dataent.cache().hget("lang_full_dict", lang, shared=True)
    if not out:
        out = {}
        for app in (apps or dataent.get_all_apps(True)):
            path = os.path.join(dataent.get_pymodule_path(app), "translations",
                                lang + ".csv")
            out.update(get_translation_dict_from_file(path, lang, app) or {})

        if '-' in lang:
            parent = lang.split('-')[0]
            parent_out = load_lang(parent)
            parent_out.update(out)
            out = parent_out

        dataent.cache().hset("lang_full_dict", lang, out, shared=True)

    return out or {}
Ejemplo n.º 2
0
def get_build_maps():
    """get all build.jsons with absolute paths"""
    # framework js and css files

    build_maps = {}
    for app_path in app_paths:
        path = os.path.join(app_path, 'public', 'build.json')
        if os.path.exists(path):
            with open(path) as f:
                try:
                    for target, sources in iteritems(json.loads(f.read())):
                        # update app path
                        source_paths = []
                        for source in sources:
                            if isinstance(source, list):
                                s = dataent.get_pymodule_path(
                                    source[0], *source[1].split("/"))
                            else:
                                s = os.path.join(app_path, source)
                            source_paths.append(s)

                        build_maps[target] = source_paths
                except ValueError as e:
                    print(path)
                    print('JSON syntax error {0}'.format(str(e)))
    return build_maps
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
def set_all_patches_as_completed(app):
    patch_path = os.path.join(dataent.get_pymodule_path(app), "patches.txt")
    if os.path.exists(patch_path):
        for patch in dataent.get_file_items(patch_path):
            dataent.get_doc({
                "doctype": "Patch Log",
                "patch": patch
            }).insert(ignore_permissions=True)
        dataent.db.commit()
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
def get_server_messages(app):
    """Extracts all translatable strings (tagged with :func:`dataent._`) from Python modules
		inside an app"""
    messages = []
    file_extensions = ('.py', '.html', '.js', '.vue')
    for basepath, folders, files in os.walk(dataent.get_pymodule_path(app)):
        for dontwalk in (".git", "public", "locale"):
            if dontwalk in folders: folders.remove(dontwalk)

        for f in files:
            f = dataent.as_unicode(f)
            if f.endswith(file_extensions):
                messages.extend(
                    get_messages_from_file(os.path.join(basepath, f)))

    return messages
Ejemplo n.º 7
0
def write_translations_file(app, lang, full_dict=None, app_messages=None):
    """Write a translation file for a given language.

	:param app: `app` for which translations are to be written.
	:param lang: Language code.
	:param full_dict: Full translated language dict (optional).
	:param app_messages: Source strings (optional).
	"""
    if not app_messages:
        app_messages = get_messages_for_app(app)

    if not app_messages:
        return

    tpath = dataent.get_pymodule_path(app, "translations")
    dataent.create_folder(tpath)
    write_csv_file(os.path.join(tpath, lang + ".csv"), app_messages, full_dict
                   or get_full_dict(lang))
Ejemplo n.º 8
0
def _add_test(app, path, filename, verbose, test_suite=None, ui_tests=False):
	import os

	if os.path.sep.join(["doctype", "doctype", "boilerplate"]) in path:
		# in /doctype/doctype/boilerplate/
		return

	app_path = dataent.get_pymodule_path(app)
	relative_path = os.path.relpath(path, app_path)
	if relative_path=='.':
		module_name = app
	else:
		module_name = '{app}.{relative_path}.{module_name}'.format(app=app,
			relative_path=relative_path.replace('/', '.'), module_name=filename[:-3])

	module = importlib.import_module(module_name)

	if hasattr(module, "test_dependencies"):
		for doctype in module.test_dependencies:
			make_test_records(doctype, verbose=verbose)

	is_ui_test = True if hasattr(module, 'TestDriver') else False

	if is_ui_test != ui_tests:
		return

	if not test_suite:
		test_suite = unittest.TestSuite()

	if os.path.basename(os.path.dirname(path))=="doctype":
		txt_file = os.path.join(path, filename[5:].replace(".py", ".json"))
		with open(txt_file, 'r') as f:
			doc = json.loads(f.read())
		doctype = doc["name"]
		make_test_records(doctype, verbose)

	test_suite.addTest(unittest.TestLoader().loadTestsFromModule(module))