def cacheMetadata( corpusNames=('local', 'core', 'virtual'), useMultiprocessing=True, ): ''' Cache metadata from corpuses in `corpusNames` as local cache files: Call as ``metadata.cacheMetadata()`` ''' from music21 import corpus from music21 import metadata if not common.isListLike(corpusNames): corpusNames = (corpusNames, ) timer = common.Timer() timer.start() # store list of file paths that caused an error failingFilePaths = [] # the core cache is based on local files stored in music21 # virtual is on-line for corpusName in corpusNames: if corpusName == 'core': metadataBundle = metadata.MetadataBundle.fromCoreCorpus() paths = corpus.getCorePaths() useCorpus = True elif corpusName == 'local': metadataBundle = metadata.MetadataBundle.fromLocalCorpus() paths = corpus.getLocalPaths() useCorpus = False elif corpusName == 'virtual': metadataBundle = metadata.MetadataBundle.fromVirtualCorpus() paths = corpus.getVirtualPaths() useCorpus = False else: message = 'invalid corpus name provided: {0!r}'.format(corpusName) raise MetadataCacheException(message) message = 'metadata cache: starting processing of paths: {0}'.format( len(paths)) environLocal.printDebug(message) failingFilePaths += metadataBundle.addFromPaths( paths, useCorpus=useCorpus, useMultiprocessing=useMultiprocessing, ) message = 'cache: writing time: {0} md items: {1}'.format( timer, len(metadataBundle)) environLocal.printDebug(message) del metadataBundle message = 'cache: final writing time: {0} seconds'.format(timer) environLocal.printDebug(message) for failingFilePath in failingFilePaths: message = 'path failed to parse: {0}'.format(failingFilePath) environLocal.printDebug(message)
def cacheMetadata( corpusNames=('local', 'core', 'virtual'), useMultiprocessing=True, ): ''' Cache metadata from corpuses in `corpusNames` as local cache files: Call as ``metadata.cacheMetadata()`` ''' from music21 import corpus from music21 import metadata if not common.isListLike(corpusNames): corpusNames = (corpusNames,) timer = common.Timer() timer.start() # store list of file paths that caused an error failingFilePaths = [] # the core cache is based on local files stored in music21 # virtual is on-line for corpusName in corpusNames: if corpusName == 'core': metadataBundle = metadata.MetadataBundle.fromCoreCorpus() paths = corpus.getCorePaths() useCorpus = True elif corpusName == 'local': metadataBundle = metadata.MetadataBundle.fromLocalCorpus() paths = corpus.getLocalPaths() useCorpus = False elif corpusName == 'virtual': metadataBundle = metadata.MetadataBundle.fromVirtualCorpus() paths = corpus.getVirtualPaths() useCorpus = False else: message = 'invalid corpus name provided: {0!r}'.format(corpusName) raise MetadataCacheException(message) message = 'metadata cache: starting processing of paths: {0}'.format( len(paths)) environLocal.printDebug(message) failingFilePaths += metadataBundle.addFromPaths( paths, useCorpus=useCorpus, useMultiprocessing=useMultiprocessing, ) message = 'cache: writing time: {0} md items: {1}'.format( timer, len(metadataBundle)) environLocal.printDebug(message) del metadataBundle message = 'cache: final writing time: {0} seconds'.format(timer) environLocal.printDebug(message) for failingFilePath in failingFilePaths: message = 'path failed to parse: {0}'.format(failingFilePath) environLocal.printDebug(message)