def joinBlocks(inputMd, blockPrefix=None): mdImages = MetaData() mdAll = MetaData() mdBlocks = getBlocksInMetaDataFile(inputMd) for mdBlock in mdBlocks: if blockPrefix is not None: if mdBlock.startswith(blockPrefix): mdImages.read(mdBlock + "@" + inputMd) mdAll.unionAll(mdImages) else: mdImages.read(mdBlock + "@" + inputMd) mdAll.unionAll(mdImages) return mdAll
def getFirstRow(filename): """ Create a MetaData but only read the first row. This method should be used for validations of labels or metadata size, but the full metadata is not needed. """ md = MetaData() md.read(filename, 1) if md.getParsedLines(): row = Row() row.readFromMd(md, md.firstObject()) else: row = None return row
def iterRows(md, sortByLabel=None): """ Iterate over the rows of the given metadata. Params: md: a MetaData object or a filename (MetaData will be read) sortByLabel: a label to sort the metadata before iterate. """ # If md is string, take as filename and create the metadata if isinstance(md, basestring): md = MetaData(md) if sortByLabel is not None: md.sort(sortByLabel) row = Row() for objId in md: row.readFromMd(md, objId) yield row
def getFirstRow(mdOrFn): """ Return the first object of a metadata. Params: mdOrFn: you can pass a metadata or a filename as argument. """ if isinstance(mdOrFn, basestring): md = MetaData() md.read(mdOrFn, 1) else: # mdOrFn is MetaData md = mdOrFn if md.getParsedLines(): row = Row() row.readFromMd(md, md.firstObject()) else: row = None return row
def getSize(filename): """ Return the metadata size without parsing entirely. """ md = MetaData() md.read(filename, 1) return md.getParsedLines()