コード例 #1
0
def getManifest(addon):
	manifest_path = os.path.join(addon.path, addonHandler.MANIFEST_FILENAME)
	if os.path.exists(manifest_path):
		with open(manifest_path) as f:
			manifest = addonHandler.AddonManifest(f)
			return manifest
	return None
コード例 #2
0
def _createBuildVarsFile(addon):
	# Translators: title of dialog
	dialogTitle = _("Creation of buildVars.py file")
	templateFile = os.path.join(_curModuleFilePath, "buildVars.py.tpl")
	with codecs.open(templateFile, "r", "utf-8") as f:
		buildVars_template = f.read()
	manifest_path = os.path.join(addon.path, addonHandler.MANIFEST_FILENAME)
	if not os.path.exists(manifest_path):

		gui.messageBox(
			# Translators: message to user.
			_("Error: %s file is not found") % addonHandler.MANIFEST_FILENAME,
			dialogTitle, wx.OK)
		return
	with open(manifest_path) as f:
		manifest = addonHandler.AddonManifest(f)
	dest = os.path.join(addon.path, "buildVars.py")
	if os.path.exists(dest):
		# Translators: message to user.
		msg = _("Warning: buildVars.py already exist. Do you want to replace it ?")
		if gui.messageBox(msg, dialogTitle, wx.YES | wx.NO) == wx.NO:
			return

	default_vars = {
		"name": "addonTemplate",
		"summary": "Add-on user visible name",
		"description": """Description for the add-on. It can span multiple lines.""",  # noqa:E501
		"version": "x.y",
		"author": _unicode("name <*****@*****.**>"),
		"url": None,
		"docFileName": "readme.html",
		"minimumNVDAVersion": None,
		"lastTestedNVDAVersion": None,
		"updateChannel": None
		}
	vars = {}
	vars.update(_buildVarsStrings)
	vars.update(default_vars)
	for var in manifest:
		if manifest[var] is None:
			continue
		if type(manifest[var]) == tuple:
			tempList = [str(x) for x in manifest[var]]
			vars[var] = ".".join(tempList)
			continue
		vars[var] = manifest[var]
	buildVars = buildVars_template.format(**vars)
	buildVars = buildVars.replace("\"None\"", "None")
	buildVars = buildVars.replace("_(\"\"\"None\"\"\")", "None")
	with codecs.open(dest, "w", "utf-8") as f:
		f.write(buildVars)
	# Translators message to user to report buildVars.py has been created
		msg = _("buildVars.py file created")
	gui.messageBox(msg, dialogTitle, wx.OK)
	# clean up
	clean(addon)
コード例 #3
0
def getMmanifestInfos(addon, lang):
	path = addon.path
	manifest_path = os.path.join(path, addonHandler.MANIFEST_FILENAME)
	with open(manifest_path) as f:
		translatedInput = None
		translatedPath = os.path.join("locale", lang)
		p = os.path.join(path, translatedPath, addonHandler.MANIFEST_FILENAME)
		if os.path.exists(p):
			log.debug("Using manifest translation from %s", p)
			translatedInput = open(p, 'rb')
			try:
				return addonHandler.AddonManifest(f, translatedInput)
			except:  # noqa:E722
				# Translators: dialog title on errorr.
				dialogTitle = _("error")
				gui.messageBox(
					# Translators: message to the user on getting addon manifest.
					_("Cannot get add-on translated manifest of %s language") % lang,
					dialogTitle, wx.OK | wx.ICON_ERROR)
	return addonHandler.AddonManifest(manifest_path)