def get_build_maps(): """get all build.jsons with absolute paths""" # framework js and css files pymodules = [webnotes.get_module(app) for app in webnotes.get_all_apps(True)] app_paths = [os.path.dirname(pymodule.__file__) for pymodule in pymodules] 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 json.loads(f.read()).iteritems(): # update app path source_paths = [] for source in sources: if isinstance(source, list): s = webnotes.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 Exception, e: print path raise
def load_lang(lang, apps=None): out = {} for app in (apps or webnotes.get_all_apps(True)): path = os.path.join(webnotes.get_pymodule_path(app), "translations", lang + ".csv") if os.path.exists(path): cleaned = dict([item for item in dict(read_csv_file(path)).iteritems() if item[1]]) out.update(cleaned) return out
def get_server_messages(app): messages = [] for basepath, folders, files in os.walk(webnotes.get_pymodule_path(app)): for dontwalk in (".git", "public", "locale"): if dontwalk in folders: folders.remove(dontwalk) for f in files: if f.endswith(".py") or f.endswith(".html"): messages.extend(get_messages_from_file(os.path.join(basepath, f))) return clean(messages)
def after_install(): # import custom fields data_import_tool.import_doclist(webnotes.get_pymodule_path("aapkamanch", "data", "custom_fields.csv"), overwrite=True) from .import_units import import_units import_units() website_settings = webnotes.bean("Website Settings", "Website Settings") website_settings.doc.home_page = "index" website_settings.doc.disable_signup = 1 website_settings.save() webnotes.conn.commit()
def build_website_sitemap_config(app): config = {"pages": {}, "generators":{}} basepath = webnotes.get_pymodule_path(app) # pages for config_type in ("pages", "generators"): path = os.path.join(basepath, "templates", config_type) if os.path.exists(path): for fname in os.listdir(path): fname = webnotes.utils.cstr(fname) if fname.split(".")[-1] in ("html", "xml", "js", "css"): name = add_website_sitemap_config("Page" if config_type=="pages" else "Generator", app, path, fname, basepath) webnotes.conn.commit()
def run_all_tests(app=None, verbose=False): import os apps = [app] if app else webnotes.get_installed_apps() test_suite = unittest.TestSuite() for app in apps: for path, folders, files in os.walk(webnotes.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"): # print filename[:-3] _run_test(path, filename, verbose, test_suite=test_suite, run=False) return unittest.TextTestRunner(verbosity=1+(verbose and 1 or 0)).run(test_suite)
def import_units(): """rebuild all units from units.json""" webnotes.conn.sql("""delete from tabUnit""") webnotes.conn.auto_commit_on_many_writes = True with open(webnotes.get_pymodule_path("aapkamanch", "data", "units.json")) as f: data = json.loads(f.read()) def create_units(unit_name, unit_title, parent_unit, children_name, unit_type): units = [] units.append(webnotes.bean({"doctype":"Unit", "unit_name": unit_name, "unit_title":unit_title, "parent_unit": parent_unit, "unit_type": unit_type, "public":1}).insert()) for det in ((children_name, "Public"), ("Forum", "Public"), ("Discussion", "Private")): units.append(webnotes.bean({ "doctype":"Unit", "parent_unit": units[0].doc.name, "unit_type": unit_type, "unit_title": det[0], "public": 1 if det[1]=="Public" else 0, "unit_name": unit_name + "-" + det[0] }).insert()) return units india = create_units("India", "India", "", "States", "Country") for state in data: state_units = create_units(state, state, india[1].doc.name, "Districts", "State") for district in data[state]: district_units = create_units(state_units[0].doc.name + "-" + district, district, state_units[1].doc.name, "Blocks", "District") for block in data[state][district] or []: block_unit = create_units(district_units[0].doc.name + "-" + block, block, district_units[1].doc.name, "Primary", "Block") webnotes.conn.commit()
def get_all_patches(): patches = [] for app in webnotes.get_installed_apps(): patches.extend(webnotes.get_file_items(webnotes.get_pymodule_path(app, "patches.txt"))) return patches
def write_translations_file(app, lang, full_dict=None): tpath = webnotes.get_pymodule_path(app, "translations") webnotes.create_folder(tpath) write_csv_file(os.path.join(tpath, lang + ".csv"), get_messages_for_app(app), full_dict or get_full_dict(lang))