def partIdRandomize(self): '''Force a unique id by using an MD5 ''' idNew = 'P%s' % common.getMd5() #environLocal.printDebug(['incrementing instrument from', # self.partId, 'to', idNew]) self.partId = idNew
def md5OfCorpusFile(fileDir, scoreNumber=None): ''' returns the md5 hash of the text file contents. the file must be the full name of the corpus file >>> from music21.demos.bhadley.mrjobaws.awsutility import md5OfCorpusFile >>> a = md5OfCorpusFile('bach/bwv431.mxl') >>> a '3b8c4b8db4288c43efde44ddcdb4d8d2' >>> s = corpus.parse('bwv431') >>> s.corpusFilepath 'bach/bwv431.mxl' >>> b = md5OfCorpusFile(s.corpusFilepath) >>> b '3b8c4b8db4288c43efde44ddcdb4d8d2' >>> a == b True >>> md5OfCorpusFile('airdsAirs/book3.abc', '413') 'c1666c19d63fc0940f111008e2269f75.413' ''' corpusFP = common.getCorpusFilePath() / pathlib.Path(fileDir) with corpusFP.open('rb') as fileIn: md5 = common.getMd5(fileIn.read()) if scoreNumber: return md5 + '.' + scoreNumber else: return md5
def md5OfCorpusFile(fileDir, scoreNumber=None): """ returns the md5 hash of the text file contents. the file must be the full name of the corpus file >>> from music21.demos.bhadley.mrjobaws.awsutility import md5OfCorpusFile >>> a = md5OfCorpusFile('bach/bwv431.mxl') >>> a '3b8c4b8db4288c43efde44ddcdb4d8d2' >>> s = corpus.parse('bwv431') >>> s.corpusFilepath u'bach/bwv431.mxl' >>> b = md5OfCorpusFile(s.corpusFilepath) >>> b '3b8c4b8db4288c43efde44ddcdb4d8d2' >>> a == b True >>> md5OfCorpusFile('airdsAirs/book3.abc','413') 'c1666c19d63fc0940f111008e2269f75.413' """ corpusFP = common.getCorpusFilePath() fileIn = open(corpusFP + os.sep + fileDir, "rb") md5 = common.getMd5(fileIn.read()) if scoreNumber: return md5 + "." + scoreNumber else: return md5
def getPickleFp(self, directory: Union[str, pathlib.Path]) -> pathlib.Path: if not isinstance(directory, pathlib.Path): directory = pathlib.Path(directory) # cannot get data from stream, as offsets are broken streamStr = str(time.time()) return directory / ('m21-' + common.getMd5(streamStr) + '.p')
def getPickleFp(self, directory): if directory is None: raise ValueError if not isinstance(directory, pathlib.Path): directory = pathlib.Path(directory) # cannot get data from stream, as offsets are broken streamStr = str(time.time()) return directory / ('m21-' + common.getMd5(streamStr) + '.p')
def _getDownloadFp(self, dir, ext, url): if dir == None: raise ValueError return os.path.join(dir, 'm21-' + common.getMd5(url) + ext)
def _getPickleFp(self, dir): if dir == None: raise ValueError # cannot get data from stream, as offsets are broken streamStr = str(time.time()) return os.path.join(dir, 'm21-' + common.getMd5(streamStr) + '.p')
def _getPickleFp(self, dir): if dir == None: raise ValueError return os.path.join(dir, 'm21-' + common.getMd5(self.fp) + '.p')