def _findFileTag(tag, tagTitle, fileSuffix=""): fileList = [] for targetFile in tag.getElementsByTagName(tagTitle): fileName = XMLGetText(targetFile) # files should be relative to the tmp directory path if tagTitle != "remove_file" and fileName.startswith("/"): fileName = fileName.lstrip("/") if fileSuffix and not fileName.endswith(fileSuffix): log.warn("The file '%s' does not end with %s" % (fileName, fileSuffix)) if not fileName: raise InvalidCustomDriverError fileList.append(fileName) return fileList
def _findFileTag(tag, tagTitle, fileSuffix=''): fileList = [] for targetFile in tag.getElementsByTagName(tagTitle): fileName = XMLGetText(targetFile) # files should be relative to the tmp directory path if tagTitle != 'remove_file' and fileName.startswith('/'): fileName = fileName.lstrip('/') if fileSuffix and not fileName.endswith(fileSuffix): log.warn("The file '%s' does not end with %s" % (fileName, fileSuffix)) if not fileName: raise InvalidCustomDriverError fileList.append(fileName) return fileList
def parseTimezoneList(self, fname='timezone.xml'): fpath = GetWeaselXMLFilePath(fname) doc = xml.dom.minidom.parse(fpath) for offsetNode in doc.getElementsByTagName("offset"): offset = offsetNode.getAttribute('name') # careful not to get a child city's mappos offsetPos = None for child in offsetNode.childNodes: if hasattr(child, 'tagName') and child.tagName == 'mappos': offsetPos = XMLGetText(child) break for cityNode in offsetNode.getElementsByTagName('city'): zoneName = GetTextOrEmpty(cityNode, 'zone') cityName = GetTextOrEmpty(cityNode, 'name') cityOffsetName = GetTextOrEmpty(cityNode, 'offsetname') cityPos = GetTextOrEmpty(cityNode, 'mappos') showAsMapOffset = GetTextOrEmpty(cityNode, 'showasmapoffset') # sanity check the data we got from the XML... if showAsMapOffset and offsetPos: msg = ('Parsing timezone XML file: timzeone %s has both ' 'showmapasoffset and an offset with a mappos') %\ zoneName raise ValueError(msg) fileName = os.path.join('/usr/share/zoneinfo/', zoneName) if not os.path.exists(fileName): log.warn('Timezone missing: Could not find %s' % fileName) continue # for these args, None is prefered over an empty string kwargs = {'offsetPos': (offsetPos or None), 'cityPos': (cityPos or None), 'showAsMapOffset': (showAsMapOffset or None), } zone = Timezone(zoneName, offset, cityName, cityOffsetName, **kwargs) self._timezones.append(zone) if cityNode.getAttribute('default') == '1': self.defaultTimezone = zone
def __init__(self, supportedPackageGroups, fullPath="packages.xml", mediaRoot="."): '''Warning: the constructor can potentially raise remote_files exceptions. ''' log.debug("Reading packages.xml...") getTagText = XMLGetTextInUniqueElement # handy alias if isURL(fullPath): # this can potentially raise HTTPError or URLError log.debug('Downloading the packages.xml file') fullPath = downloadLocally(fullPath, integrityChecker=self.parse) doc = self.parse(fullPath, shouldRaise=True) products = doc.getElementsByTagName("product") if len(products) != 1: log.warn('Expected to find only one <product> in packages.xml') product = products[0] self.name = getTagText(product, 'name') self.esxVersion = getTagText(product, 'esx_version') self.esxThirdPartyVersion = getTagText(product, 'esx_tp_version') self.esxThirdPartyCompatVersion = getTagText(product, 'esx_tp_compat_version') self.release = '%s.%s' % (getTagText(product, 'esx_release'), getTagText(product, 'release')) # bootloader.py needs these two self.kernLabel = getTagText(product, "kernel_name") self.kernVersion = getTagText(product, "kernel_version") self.installDepot = getTagText(product, 'install_depot') if isURL(mediaRoot): self.fullInstallDepot = urljoin(mediaRoot, self.installDepot) else: self.fullInstallDepot = os.path.join(mediaRoot, self.installDepot) log.info("Full install depot is %s" % (self.fullInstallDepot)) self.rpmBasenames = [] for depot in doc.getElementsByTagName("depot"): element = depot.getAttribute("name") if supportedPackageGroups != None: #NOTE: [] != None if element not in supportedPackageGroups: log.debug("Skipping depot %s" % (element)) continue for rpmlist in depot.getElementsByTagName("rpmlist"): repo = rpmlist.getAttribute('repo') for node in rpmlist.getElementsByTagName("rpm"): archOpt = node.getAttribute("arch") #TODO: at some point 'both' should be 'i386,x86_64' and we # should split on ',' if archOpt == "both": archList = ['i386', 'x86_64'] else: archList = [getTagText(depot, 'arch')] reqOpt = node.getAttribute("requirement").lower() if reqOpt not in REQUIREMENT_OPTIONS: reqOpt = "required" package = node.getAttribute('package') changeset = node.getAttribute('changeset') for arch in archList: basename = XMLGetText(node) basename = basename.replace("${esx_version}", self.esxVersion) basename = basename.replace("${esx_tp_version}", self.esxThirdPartyVersion) basename = basename.replace("${esx_tp_compat_version}", self.esxThirdPartyCompatVersion) basename = basename.replace("${release}", self.release) basename = basename.replace("${driver_release}", self.release) basename = basename.replace("${arch}", arch) basename = basename.replace('${repo}', repo) basename = basename.replace('${package}', package) basename = basename.replace('${changeset}', changeset) self.rpmBasenames.append((basename, reqOpt))
def __init__(self, supportedPackageGroups, fullPath="packages.xml", mediaRoot="."): '''Warning: the constructor can potentially raise remote_files exceptions. ''' log.debug("Reading packages.xml...") getTagText = XMLGetTextInUniqueElement # handy alias if isURL(fullPath): # this can potentially raise HTTPError or URLError log.debug('Downloading the packages.xml file') fullPath = downloadLocally(fullPath, integrityChecker=self.parse) doc = self.parse(fullPath, shouldRaise=True) products = doc.getElementsByTagName("product") if len(products) != 1: log.warn('Expected to find only one <product> in packages.xml') product = products[0] self.name = getTagText(product, 'name') self.esxVersion = getTagText(product, 'esx_version') self.esxThirdPartyVersion = getTagText(product, 'esx_tp_version') self.esxThirdPartyCompatVersion = getTagText(product, 'esx_tp_compat_version') self.release = '%s.%s' % (getTagText( product, 'esx_release'), getTagText(product, 'release')) # bootloader.py needs these two self.kernLabel = getTagText(product, "kernel_name") self.kernVersion = getTagText(product, "kernel_version") self.installDepot = getTagText(product, 'install_depot') if isURL(mediaRoot): self.fullInstallDepot = urljoin(mediaRoot, self.installDepot) else: self.fullInstallDepot = os.path.join(mediaRoot, self.installDepot) log.info("Full install depot is %s" % (self.fullInstallDepot)) self.rpmBasenames = [] for depot in doc.getElementsByTagName("depot"): element = depot.getAttribute("name") if supportedPackageGroups != None: #NOTE: [] != None if element not in supportedPackageGroups: log.debug("Skipping depot %s" % (element)) continue for rpmlist in depot.getElementsByTagName("rpmlist"): repo = rpmlist.getAttribute('repo') for node in rpmlist.getElementsByTagName("rpm"): archOpt = node.getAttribute("arch") #TODO: at some point 'both' should be 'i386,x86_64' and we # should split on ',' if archOpt == "both": archList = ['i386', 'x86_64'] else: archList = [getTagText(depot, 'arch')] reqOpt = node.getAttribute("requirement").lower() if reqOpt not in REQUIREMENT_OPTIONS: reqOpt = "required" package = node.getAttribute('package') changeset = node.getAttribute('changeset') for arch in archList: basename = XMLGetText(node) basename = basename.replace("${esx_version}", self.esxVersion) basename = basename.replace("${esx_tp_version}", self.esxThirdPartyVersion) basename = basename.replace( "${esx_tp_compat_version}", self.esxThirdPartyCompatVersion) basename = basename.replace("${release}", self.release) basename = basename.replace("${driver_release}", self.release) basename = basename.replace("${arch}", arch) basename = basename.replace('${repo}', repo) basename = basename.replace('${package}', package) basename = basename.replace('${changeset}', changeset) self.rpmBasenames.append((basename, reqOpt))