def _parse_xml_element(dataclass_object: dataclass, xml_element: ET) -> dataclass: for key in dataclass_object.__annotations__: try: if dataclass_object.__annotations__[key] == int: dataclass_object.__dict__[key] = int( xml_element.findtext(key.replace("_", "-"))) elif dataclass_object.__annotations__[key] == Union[None, datetime]: dataclass_object.__dict__[key] = datetime.strptime( xml_element.findtext(key.replace("_", "-")), "%Y-%m-%d %H:%M:%S %Z", ) elif (dataclass_object.__annotations__[key] == Union[ None, IPv4Address, IPv6Address]): dataclass_object.__dict__[key] = ip_address( xml_element.findtext(key.replace("_", "-"))) else: dataclass_object.__dict__[key] = str( xml_element.findtext(key.replace("_", "-"))) except ValueError: continue except TypeError: continue return dataclass_object
def _prep_xmltext(et: Et, key: str) -> str: """Wrapper to quickly get settings. :param et: Element Tree from parsed Xml :type et: xml.etree.ElementTree :param key: Name of the setting :type key: str :return: Parsed value for setting :rtype: str """ t = et.find(key).text.strip() if et.findtext(key) and ( et.find(key).text is not None) else None return None if not t or t == "" else t
class App(object): def __init__(self, env, source_dir): self.env = env self.source_dir = fix_path(source_dir) self.resources_dir = os.path.join(self.source_dir, 'Resources') self.modules = [] self.read_manifest() self.read_tiapp() # There are some basic attributes that we need to know to continue. # If these weren't passed, we should abort here. for attr in ['name', 'id', 'guid', 'version', 'runtime_version']: if not hasattr(self, attr): raise Exception('Neither the tiapp.xml nor the manifest defined "%s"' % attr) # Cache the SDK directory for the runtime here, because we'll # need it quite a bit if we do staging and packaging. self.sdk_dir = fix_path((self.env.get_sdk_dir(self.runtime_version))) def read_manifest(self): manifest_path = p.join(self.source_dir, "manifest") if not p.exists(manifest_path): raise Exception("Could not find manifest at %s" % manifest_path) contents = codecs.open(manifest_path, 'r', 'utf-8').read().split('\n') for line in contents: if line.find(u':') == -1: continue (key, value) = line.split(':', 1) key = key.strip() value = value.strip() if key == u'#appname': self.name = value elif key == u'#appid': self.id = value elif key == u'#guid': self.guid = value elif key == u'#description': self.description = value elif key == u'#image': self.image = value elif key == u'#publisher': self.publisher = value elif key == u'#url': self.url = value elif key == u'#version': self.version = value elif key == u'#loglevel': self.loglevel = value elif key == u'#stream': self.stream = value elif key.find(u'#') == 0: continue else: # This is for staging applications in our source directory. # If no version is specified for this application, just use # the current build environment version. if not value: value = self.env.version if key == u'runtime': self.runtime_version = value elif key == u'sdk': self.sdk_version = value elif key == u'mobilesdk': self.mobilesdk_version = value else: self.modules.append((key, value)) def get_tiapp_element_as_prop(self, element_name, prop): t = self.tiapp.findtext(element_name) if t: self.__setattr__(prop, unicode(t)) def read_tiapp(self): tiapp_path = p.join(self.source_dir, "tiapp.xml") if not p.exists(tiapp_path): raise Exception("Could not find tiapp.xml at %s" % tiapp_path) self.tiapp = ElementTree() self.tiapp.parse(tiapp_path) self.get_tiapp_element_as_prop('name', 'name') self.get_tiapp_element_as_prop('id', 'id') self.get_tiapp_element_as_prop('version', 'version') self.get_tiapp_element_as_prop('icon', 'image') self.get_tiapp_element_as_prop('description', 'description') self.get_tiapp_element_as_prop('publisher', 'publisher') self.get_tiapp_element_as_prop('url', 'url') self.get_tiapp_element_as_prop('log-level', 'loglevel') def write_manifest(self, path): f = codecs.open(p.join(path, 'manifest'), 'wb', 'utf-8') def write_line(str): f.write(str.replace(u'\n', u'') + '\n') write_line(u'#appname: ' + self.name) write_line(u'#appid: ' + self.id) write_line(u'#guid: ' + self.guid) write_line(u'#version: ' + self.version) if hasattr(self, 'image'): write_line(u'#image: ' + self.image) if hasattr(self, 'publisher'): write_line(u'#publisher: ' + self.publisher) if hasattr(self, 'description'): write_line(u'#description: ' + self.description) if hasattr(self, 'url'): write_line(u'#url: ' + self.url) if hasattr(self, 'loglevel'): write_line(u'#loglevel: ' + self.url) if hasattr(self, 'stream'): write_line(u'#stream: ' + self.url) write_line(u'runtime: ' + self.runtime_version) if hasattr(self, 'sdk_version'): write_line(u'sdk: ' + self.sdk_version) if hasattr(self, 'mobilesdk_version'): write_line(u'mobilesdk: ' + self.mobilesdk_version) for module in self.modules: write_line(module[0] + ': ' + module[1]) f.close() def write_tiapp(self, path): xml.etree.ElementTree._namespace_map['http://ti.appcelerator.org'] = 'ti' xml.etree.ElementTree._namespace_map['http://www.appcelerator.org'] = 'appc' self.tiapp.write(p.join(path, 'tiapp.xml'), "utf-8") def get_contents_dir(self): return self.stage_dir def stage(self, stage_dir, bundle=False, no_install=False): print('Staging %s' % self.name) self.stage_dir = fix_path(stage_dir) contents = self.contents = self.get_contents_dir() self.env.log(u'Copying contents from %s to %s' % (self.source_dir, contents)) excludes = self.env.get_excludes() # Don't prematurely copy custom modules (we only want them if they're in the manifest) excludes.append(p.join(self.source_dir, 'modules')) # If we are staging into a subdirectory of the original # application directory (like Titanium Developer), then # ignore the immediate child of the original app directory # on the way to the stagin directory. Example: # App directory: /tmp/MyProject # Staging directory: /tmp/MyProject/dist/linux/MyProject # then we ignore: /tmp/MyProject/dist if contents.find(p.join(self.source_dir, '')) != -1: (current, child) = p.split(contents) while current != self.source_dir: (current, child) = p.split(current) excludes.append(p.join(current, child)) effess.copy_tree(self.source_dir, contents, exclude=self.env.get_excludes()) # If we are not including the installer and this is bundled, do not copy # the installer and make the app as installed. if no_install and bundle: f = open(p.join(self.get_contents_dir(), '.installed'), 'w') f.write("installed") f.close() else: installer_source = p.join(self.sdk_dir, 'installer') self.env.log(u'Copying installer from %s to %s' % (installer_source, contents)) effess.copy_to_dir(installer_source, contents, exclude=self.env.get_excludes() + ['.dll', '.msm']) self.write_manifest(contents) self.write_tiapp(contents) if bundle: self.env.log(u'Copying runtime to %s' % self.stage_dir) effess.copy_tree(self.env.get_runtime_dir(self.runtime_version), p.join(contents, "runtime", self.runtime_version), exclude=self.env.get_excludes()) if hasattr(self, 'sdk_version'): self.env.log(u'Copying SDK to %s' % contents) effess.copy_tree(self.sdk_dir, p.join(contents, "sdk", self.sdk_version), exclude=self.env.get_excludes()) # We don't bundle the MobileSDK currently. #if hasattr(self, 'mobilesdk_version'): # self.env.log(u'Copying MobileSDK to %s' % contents) # effess.copy_tree(self.sdk_dir, # p.join(contents, "mobilesdk", self.mobilesdk_version), # exclude=self.env.get_excludes()) for module in self.modules: # If this module already exists in the source directory as a bundled # module than don't overwrite it with an installed module source = p.join(self.source_dir, 'modules', module[0], module[1]) if not(p.exists(source)): source = self.env.get_module_dir(module) effess.lightweight_copy_tree(source, p.join(contents, 'modules', module[0], module[1]), exclude=self.env.get_excludes()) def run(self): self.env.run(self.executable_path) def get_installer_image(self, tag_name, default=None): # Try to find 'tag_name' and also 'tag-name' (typical XML style) elem = self.tiapp.findtext(tag_name) if not elem: elem = self.tiapp.findtext(tag_name.replace('_', '-')) if not elem: return default # Try to find the image in both the Contents and Resources directories. image = unicode(elem) if p.exists(p.join(self.contents, image)): return p.join(self.contents, image) if p.exists(p.join(self.contents, 'Resources', image)): return p.join(self.contents, 'Resources', image) else: self.env.log("Could not find %s: %s. Using default." % \ (tag_name, default)) return default
def get_module_name(pom_file): tree = ElementTree() parser = XMLParser(target=CommentedTreeBuilder()) tree.parse(pom_file, parser=parser) return tree.findtext("./{%s}artifactId" % maven_pom_xml_namespace)
class App(object): def __init__(self, env, source_dir): self.env = env self.source_dir = fix_path(source_dir) self.resources_dir = os.path.join(self.source_dir, 'Resources') self.modules = [] self.read_manifest() self.read_tiapp() # There are some basic attributes that we need to know to continue. # If these weren't passed, we should abort here. for attr in ['name', 'id', 'guid', 'version', 'runtime_version']: if not hasattr(self, attr): raise Exception( 'Neither the tiapp.xml nor the manifest defined "%s"' % attr) # Cache the SDK directory for the runtime here, because we'll # need it quite a bit if we do staging and packaging. self.sdk_dir = fix_path((self.env.get_sdk_dir(self.runtime_version))) def read_manifest(self): manifest_path = p.join(self.source_dir, "manifest") if not p.exists(manifest_path): raise Exception("Could not find manifest at %s" % manifest_path) contents = codecs.open(manifest_path, 'r', 'utf-8').read().split('\n') for line in contents: if line.find(u':') == -1: continue (key, value) = line.split(':', 1) key = key.strip() value = value.strip() if key == u'#appname': self.name = value elif key == u'#appid': self.id = value elif key == u'#guid': self.guid = value elif key == u'#description': self.description = value elif key == u'#image': self.image = value elif key == u'#publisher': self.publisher = value elif key == u'#url': self.url = value elif key == u'#version': self.version = value elif key == u'#loglevel': self.loglevel = value elif key == u'#stream': self.stream = value elif key.find(u'#') == 0: continue else: # This is for staging applications in our source directory. # If no version is specified for this application, just use # the current build environment version. if not value: value = self.env.version if key == u'runtime': self.runtime_version = value elif key == u'sdk': self.sdk_version = value elif key == u'mobilesdk': self.mobilesdk_version = value else: self.modules.append((key, value)) def get_tiapp_element_as_prop(self, element_name, prop): t = self.tiapp.findtext(element_name) if t: self.__setattr__(prop, unicode(t)) def read_tiapp(self): tiapp_path = p.join(self.source_dir, "tiapp.xml") if not p.exists(tiapp_path): raise Exception("Could not find tiapp.xml at %s" % tiapp_path) self.tiapp = ElementTree() self.tiapp.parse(tiapp_path) self.get_tiapp_element_as_prop('name', 'name') self.get_tiapp_element_as_prop('id', 'id') self.get_tiapp_element_as_prop('version', 'version') self.get_tiapp_element_as_prop('icon', 'image') self.get_tiapp_element_as_prop('description', 'description') self.get_tiapp_element_as_prop('publisher', 'publisher') self.get_tiapp_element_as_prop('url', 'url') self.get_tiapp_element_as_prop('log-level', 'loglevel') self.get_tiapp_element_as_prop('stream', 'stream') def write_manifest(self, path): f = codecs.open(p.join(path, 'manifest'), 'wb', 'utf-8') def write_line(str): f.write(str.replace(u'\n', u'') + '\n') write_line(u'#appname: ' + self.name) write_line(u'#appid: ' + self.id) write_line(u'#guid: ' + self.guid) write_line(u'#version: ' + self.version) if hasattr(self, 'image'): write_line(u'#image: ' + self.image) if hasattr(self, 'publisher'): write_line(u'#publisher: ' + self.publisher) if hasattr(self, 'description'): write_line(u'#description: ' + self.description) if hasattr(self, 'url'): write_line(u'#url: ' + self.url) if hasattr(self, 'loglevel'): write_line(u'#loglevel: ' + self.loglevel) if hasattr(self, 'stream'): write_line(u'#stream: ' + self.stream) write_line(u'runtime: ' + self.runtime_version) if hasattr(self, 'sdk_version'): write_line(u'sdk: ' + self.sdk_version) if hasattr(self, 'mobilesdk_version'): write_line(u'mobilesdk: ' + self.mobilesdk_version) for module in self.modules: write_line(module[0] + ': ' + module[1]) f.close() def write_tiapp(self, path): xml.etree.ElementTree._namespace_map[ 'http://ti.appcelerator.org'] = 'ti' xml.etree.ElementTree._namespace_map[ 'http://www.appcelerator.org'] = 'appc' self.tiapp.write(p.join(path, 'tiapp.xml'), "utf-8") def get_contents_dir(self): return self.stage_dir def stage(self, stage_dir, bundle=False, no_install=False, js_obfuscate=False, ignore_patterns=""): print('Staging %s' % self.name) self.stage_dir = fix_path(stage_dir) contents = self.contents = self.get_contents_dir() self.env.log(u'Copying contents from %s to %s' % (self.source_dir, contents)) excludes = self.env.get_excludes() # Add ignore_patterns to excludes if ignore_patterns != "": excludes.extend(ignore_patterns.split(',')) # Don't prematurely copy custom modules (we only want them if they're in the manifest) excludes.append(p.join(self.source_dir, 'modules')) # If we are staging into a subdirectory of the original # application directory (like TideSDK Developer), then # ignore the immediate child of the original app directory # on the way to the stagin directory. Example: # App directory: /tmp/MyProject # Staging directory: /tmp/MyProject/dist/linux/MyProject # then we ignore: /tmp/MyProject/dist if contents.find(p.join(self.source_dir, '')) != -1: (current, child) = p.split(contents) while current != self.source_dir: (current, child) = p.split(current) excludes.append(p.join(current, child)) effess.copy_tree(self.source_dir, contents, exclude=self.env.get_excludes()) if js_obfuscate: file_paths = [] for dir_path, dir_names, file_names in os.walk(self.source_dir): file_paths.extend( os.path.join(dir_path, f) for f in fnmatch.filter(file_names, '*.js')) for file_name in file_paths: if os.path.isfile(file_name): if "Windows" in platform.platform(): head, tail = file_name.split('Resources\\') else: head, tail = file_name.split('Resources/') compiler_jar = os.path.join(self.sdk_dir, 'closure', 'compiler.jar') output_file = os.path.join(contents, "Resources") output_file = os.path.join(output_file, tail) source_file = os.path.join(self.source_dir, file_name) exec_cmd = "java -jar " + '"' + compiler_jar + '"' + " --js " + '"' + source_file + '"' + " --compilation_level SIMPLE_OPTIMIZATIONS --js_output_file " + '"' + output_file + '"' os.system(exec_cmd) # If we are not including the installer and this is bundled, do not copy # the installer and make the app as installed. if no_install and bundle: f = open(p.join(self.get_contents_dir(), '.installed'), 'w') f.write("installed") f.close() else: installer_source = p.join(self.sdk_dir, 'installer') self.env.log(u'Copying installer from %s to %s' % (installer_source, contents)) effess.copy_to_dir(installer_source, contents, exclude=self.env.get_excludes() + ['.dll', '.msm']) self.write_manifest(contents) self.write_tiapp(contents) if bundle: self.env.log(u'Copying runtime to %s' % self.stage_dir) effess.copy_tree(self.env.get_runtime_dir(self.runtime_version), p.join(contents, "runtime", self.runtime_version), exclude=self.env.get_excludes()) if hasattr(self, 'sdk_version'): self.env.log(u'Copying SDK to %s' % contents) effess.copy_tree(self.sdk_dir, p.join(contents, "sdk", self.sdk_version), exclude=self.env.get_excludes()) # We don't bundle the MobileSDK currently. #if hasattr(self, 'mobilesdk_version'): # self.env.log(u'Copying MobileSDK to %s' % contents) # effess.copy_tree(self.sdk_dir, # p.join(contents, "mobilesdk", self.mobilesdk_version), # exclude=self.env.get_excludes()) for module in self.modules: # If this module already exists in the source directory as a bundled # module than don't overwrite it with an installed module source = p.join(self.source_dir, 'modules', module[0], module[1]) if not (p.exists(source)): source = self.env.get_module_dir(module) effess.lightweight_copy_tree(source, p.join(contents, 'modules', module[0], module[1]), exclude=self.env.get_excludes()) def run(self): self.env.run(self.executable_path) def get_installer_image(self, tag_name, default=None): # Try to find 'tag_name' and also 'tag-name' (typical XML style) elem = self.tiapp.findtext(tag_name) if not elem: elem = self.tiapp.findtext(tag_name.replace('_', '-')) if not elem: return default # Try to find the image in both the Contents and Resources directories. image = unicode(elem) if p.exists(p.join(self.contents, image)): return p.join(self.contents, image) if p.exists(p.join(self.contents, 'Resources', image)): return p.join(self.contents, 'Resources', image) else: self.env.log("Could not find %s: %s. Using default." % \ (tag_name, default)) return default
def _text(self, et: ElementTree, path: str): """Return the text content of the node.""" return et.findtext(self._fix_path(path))
class App(object): def __init__(self, env, source_dir): self.env = env self.source_dir = fix_path(source_dir) self.resources_dir = os.path.join(self.source_dir, "Resources") self.modules = [] self.read_manifest() self.read_tiapp() # There are some basic attributes that we need to know to continue. # If these weren't passed, we should abort here. for attr in ["name", "id", "guid", "version", "runtime_version"]: if not hasattr(self, attr): raise Exception('Neither the tiapp.xml nor the manifest defined "%s"' % attr) # Cache the SDK directory for the runtime here, because we'll # need it quite a bit if we do staging and packaging. self.sdk_dir = fix_path((self.env.get_sdk_dir(self.runtime_version))) def read_manifest(self): manifest_path = p.join(self.source_dir, "manifest") if not p.exists(manifest_path): raise Exception("Could not find manifest at %s" % manifest_path) contents = codecs.open(manifest_path, "r", "utf-8").read().split("\n") for line in contents: if line.find(u":") == -1: continue (key, value) = line.split(":", 1) key = key.strip() value = value.strip() if key == u"#appname": self.name = value elif key == u"#appid": self.id = value elif key == u"#guid": self.guid = value elif key == u"#description": self.description = value elif key == u"#image": self.image = value elif key == u"#publisher": self.publisher = value elif key == u"#url": self.url = value elif key == u"#version": self.version = value elif key == u"#loglevel": self.loglevel = value elif key == u"#stream": self.stream = value elif key.find(u"#") == 0: continue else: # This is for staging applications in our source directory. # If no version is specified for this application, just use # the current build environment version. if not value: value = self.env.version if key == u"runtime": self.runtime_version = value elif key == u"sdk": self.sdk_version = value elif key == u"mobilesdk": self.mobilesdk_version = value else: self.modules.append((key, value)) def get_tiapp_element_as_prop(self, element_name, prop): t = self.tiapp.findtext(element_name) if t: self.__setattr__(prop, unicode(t)) def read_tiapp(self): tiapp_path = p.join(self.source_dir, "tiapp.xml") if not p.exists(tiapp_path): raise Exception("Could not find tiapp.xml at %s" % tiapp_path) self.tiapp = ElementTree() self.tiapp.parse(tiapp_path) self.get_tiapp_element_as_prop("name", "name") self.get_tiapp_element_as_prop("id", "id") self.get_tiapp_element_as_prop("version", "version") self.get_tiapp_element_as_prop("icon", "image") self.get_tiapp_element_as_prop("description", "description") self.get_tiapp_element_as_prop("publisher", "publisher") self.get_tiapp_element_as_prop("url", "url") self.get_tiapp_element_as_prop("log-level", "loglevel") def write_manifest(self, path): f = codecs.open(p.join(path, "manifest"), "wb", "utf-8") def write_line(str): f.write(str.replace(u"\n", u"") + "\n") write_line(u"#appname: " + self.name) write_line(u"#appid: " + self.id) write_line(u"#guid: " + self.guid) write_line(u"#version: " + self.version) if hasattr(self, "image"): write_line(u"#image: " + self.image) if hasattr(self, "publisher"): write_line(u"#publisher: " + self.publisher) if hasattr(self, "description"): write_line(u"#description: " + self.description) if hasattr(self, "url"): write_line(u"#url: " + self.url) if hasattr(self, "loglevel"): write_line(u"#loglevel: " + self.url) if hasattr(self, "stream"): write_line(u"#stream: " + self.url) write_line(u"runtime: " + self.runtime_version) if hasattr(self, "sdk_version"): write_line(u"sdk: " + self.sdk_version) if hasattr(self, "mobilesdk_version"): write_line(u"mobilesdk: " + self.mobilesdk_version) for module in self.modules: write_line(module[0] + ": " + module[1]) f.close() def write_tiapp(self, path): xml.etree.ElementTree._namespace_map["http://ti.appcelerator.org"] = "ti" xml.etree.ElementTree._namespace_map["http://www.appcelerator.org"] = "appc" self.tiapp.write(p.join(path, "tiapp.xml"), "utf-8") def get_contents_dir(self): return self.stage_dir def stage(self, stage_dir, bundle=False, no_install=False, js_obfuscate=False): print("Staging %s" % self.name) self.stage_dir = fix_path(stage_dir) contents = self.contents = self.get_contents_dir() self.env.log(u"Copying contents from %s to %s" % (self.source_dir, contents)) excludes = self.env.get_excludes() # Don't prematurely copy custom modules (we only want them if they're in the manifest) excludes.append(p.join(self.source_dir, "modules")) # If we are staging into a subdirectory of the original # application directory (like Titanium Developer), then # ignore the immediate child of the original app directory # on the way to the stagin directory. Example: # App directory: /tmp/MyProject # Staging directory: /tmp/MyProject/dist/linux/MyProject # then we ignore: /tmp/MyProject/dist if contents.find(p.join(self.source_dir, "")) != -1: (current, child) = p.split(contents) while current != self.source_dir: (current, child) = p.split(current) excludes.append(p.join(current, child)) effess.copy_tree(self.source_dir, contents, exclude=self.env.get_excludes()) if js_obfuscate: file_paths = [] for dir_path, dir_names, file_names in os.walk(self.source_dir): file_paths.extend(os.path.join(dir_path, f) for f in fnmatch.filter(file_names, "*.js")) for file_name in file_paths: if os.path.isfile(file_name): if "Windows" in platform.platform(): head, tail = file_name.split("Resources\\") else: head, tail = file_name.split("Resources/") compiler_jar = os.path.join(self.sdk_dir, "google_closure", "compiler.jar") output_file = os.path.join(contents, "Resources") output_file = os.path.join(output_file, tail) source_file = os.path.join(self.source_dir, file_name) exec_cmd = ( "java -jar " + '"' + compiler_jar + '"' + " --js " + '"' + source_file + '"' + " --compilation_level SIMPLE_OPTIMIZATIONS --js_output_file " + '"' + output_file + '"' ) os.system(exec_cmd) # If we are not including the installer and this is bundled, do not copy # the installer and make the app as installed. if no_install and bundle: f = open(p.join(self.get_contents_dir(), ".installed"), "w") f.write("installed") f.close() else: installer_source = p.join(self.sdk_dir, "installer") self.env.log(u"Copying installer from %s to %s" % (installer_source, contents)) effess.copy_to_dir(installer_source, contents, exclude=self.env.get_excludes() + [".dll", ".msm"]) self.write_manifest(contents) self.write_tiapp(contents) if bundle: self.env.log(u"Copying runtime to %s" % self.stage_dir) effess.copy_tree( self.env.get_runtime_dir(self.runtime_version), p.join(contents, "runtime", self.runtime_version), exclude=self.env.get_excludes(), ) if hasattr(self, "sdk_version"): self.env.log(u"Copying SDK to %s" % contents) effess.copy_tree( self.sdk_dir, p.join(contents, "sdk", self.sdk_version), exclude=self.env.get_excludes() ) # We don't bundle the MobileSDK currently. # if hasattr(self, 'mobilesdk_version'): # self.env.log(u'Copying MobileSDK to %s' % contents) # effess.copy_tree(self.sdk_dir, # p.join(contents, "mobilesdk", self.mobilesdk_version), # exclude=self.env.get_excludes()) for module in self.modules: # If this module already exists in the source directory as a bundled # module than don't overwrite it with an installed module source = p.join(self.source_dir, "modules", module[0], module[1]) if not (p.exists(source)): source = self.env.get_module_dir(module) effess.lightweight_copy_tree( source, p.join(contents, "modules", module[0], module[1]), exclude=self.env.get_excludes() ) def run(self): self.env.run(self.executable_path) def get_installer_image(self, tag_name, default=None): # Try to find 'tag_name' and also 'tag-name' (typical XML style) elem = self.tiapp.findtext(tag_name) if not elem: elem = self.tiapp.findtext(tag_name.replace("_", "-")) if not elem: return default # Try to find the image in both the Contents and Resources directories. image = unicode(elem) if p.exists(p.join(self.contents, image)): return p.join(self.contents, image) if p.exists(p.join(self.contents, "Resources", image)): return p.join(self.contents, "Resources", image) else: self.env.log("Could not find %s: %s. Using default." % (tag_name, default)) return default
def from_pubmed_xml(cls, pubmed_article: ET, source: str = None): assert pubmed_article.tag == "PubmedArticle" pmid = pubmed_article.findtext("./MedlineCitation/PMID") return cls(pmid, pubmed_article, source=source)