Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
def update_translations(lang, untranslated_file, translated_file):
	clear_cache()
	full_dict = get_full_dict(lang)
	
	full_dict.update(dict(zip(webnotes.get_file_items(untranslated_file), 
		webnotes.get_file_items(translated_file))))

	for app in webnotes.get_all_apps(True):
		write_translations_file(app, lang, full_dict)
Esempio n. 4
0
def get_app_list():
	out = {}
	installed = webnotes.get_installed_apps()
	for app in webnotes.get_all_apps(True):
		out[app] = {}
		app_hooks = webnotes.get_hooks(app_name=app)
		for key in ("app_name", "app_title", "app_description", "app_icon",
			"app_publisher", "app_version", "app_url", "app_color"):
			 val = app_hooks.get(key) or []
			 out[app][key] = val[0] if len(val) else ""
			
		if app in installed:
			out[app]["installed"] = 1
		
	return out
Esempio n. 5
0
def make_asset_dirs():
	assets_path = os.path.join(webnotes.local.sites_path, "assets")
	site_public_path = os.path.join(webnotes.local.site_path, 'public')
	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 webnotes.get_all_apps(True):
		pymodule = webnotes.get_module(app_name)
		source = os.path.join(os.path.abspath(os.path.dirname(pymodule.__file__)), 'public')
		target = os.path.join(assets_path, app_name)

		if not os.path.exists(target) and os.path.exists(source):
			os.symlink(os.path.abspath(source), target)
Esempio n. 6
0
def get_untranslated(lang, untranslated_file):
	"""translate objects using Google API. Add you own API key for translation"""	
	clear_cache()
	apps = webnotes.get_all_apps(True)
	
	messages = []
	untranslated = []
	for app in apps:
		messages.extend(get_messages_for_app(app))
	
	full_dict = get_full_dict(lang)
		
	for m in messages:
		if not full_dict.get(m):
			untranslated.append(m)
	
	if untranslated:
		print str(len(untranslated)) + " missing translations of " + str(len(messages))
		with open(untranslated_file, "w") as f:
			f.write("\n".join(untranslated))
	else:
		print "all translated!"