示例#1
0
    def _findPaths(self, rootDirectoryPath, fileExtensions):
        '''
        Given a root filePath file path, recursively search all contained paths
        for files in `rootFilePath` matching any of the file extensions in
        `fileExtensions`.

        The `fileExtensions` is a list of file file extensions.

        NB: we've tried optimizing with `fnmatch` but it does not save any
        time.
        '''
        from music21 import corpus
        matched = []
        if six.PY2:
            rootDirectoryPath = six.u(rootDirectoryPath)

        for rootDirectory, directoryNames, filenames in os.walk(rootDirectoryPath):
            if '.svn' in directoryNames:
                directoryNames.remove('.svn')
            for filename in filenames:
                try:
                    if filename.startswith('.'):
                        continue
                except UnicodeDecodeError as error:
                    raise corpus.CorpusException(
                        'Incorrect filename in corpus path: {0}: {1!r}'.format(filename, error))
                for extension in fileExtensions:
                    if filename.endswith(extension):
                        matched.append(os.path.join(rootDirectory, filename))
                        break
        return matched
示例#2
0
def accidentalLabelToUnicode(label):
    u'''
    Changes a label possibly containing a modifier such as "-" or "#" into
    a unicode string.
    
    >>> print(graph.utilities.accidentalLabelToUnicode('B-4'))
    B♭4
     
    Since matplotlib's default fonts do not support double sharps or double flats,
    etc. these are converted as best we can...
    
    >>> print(graph.utilities.accidentalLabelToUnicode('B--4'))
    B♭♭4
     
    In Python 2, all strings are converted to unicode strings even if there is
    no need to.
    '''
    if not isinstance(label, six.string_types):
        return label
    if six.PY2 and isinstance(label, str):
        label = six.u(label)
    
    for modifier, unicodeAcc in pitch.unicodeFromModifier.items():
        if modifier != '' and modifier in label and modifier in ('-', '#'):
            # ideally eventually matplotlib will do the other accidentals...
            label = label.replace(modifier, unicodeAcc)
            break 

    return label
示例#3
0
    totalCells2 = len(rowvalues2)
    extraCells = 0
    if (totalCells1 > totalCells2):
        longrow = 1
        extraCells = (totalCells1 - totalCells2)
        minCells = totalCells2
    elif (totalCells1 > totalCells2):
        longrow = 2
        extraCells = (totalCells2 - totalCells1)
        minCells = totalCells1
    else:
        minCells = totalCells1 # doesnt matter which
    for j in range(minCells):
        if (rowvalues1[j] != rowvalues2[j]):
            print("%3d,%2s--%34s : %34s" % (i + 1,xlrd.colname(j),
                                               six.u(rowvalues1[j]).encode('utf-8')[:34],
                                               six.u(rowvalues2[j]).encode('utf-8')[:34]))
    if (extraCells > 0):
        print("%3d extra cells in row %3d in" % (extraCells, i + 1), end='')
        if (longrow == 1):
            print(book1name + ":" + sheetname1)
        elif (longrow == 2):
            print(book2name + ":" + sheetname2)
        else:
            raise Exception("What?  longrow was not set!")

if (extraRows > 0):
    print("%3d extra rows in" % extraRows,)
    if (longsheet == 1):
        print(book1name + ":" + sheetname1)
    elif (longsheet == 2):
示例#4
0
        extraCells = totalCells1 - totalCells2
        minCells = totalCells2
    elif totalCells1 > totalCells2:
        longrow = 2
        extraCells = totalCells2 - totalCells1
        minCells = totalCells1
    else:
        minCells = totalCells1  # doesnt matter which
    for j in range(0, minCells):
        if rowvalues1[j] != rowvalues2[j]:
            print(
                "%3d,%2s--%34s : %34s"
                % (
                    i + 1,
                    xlrd.colname(j),
                    six.u(rowvalues1[j]).encode("utf-8")[:34],
                    six.u(rowvalues2[j]).encode("utf-8")[:34],
                )
            )
    if extraCells > 0:
        print("%3d extra cells in row %3d in" % (extraCells, i + 1))
        if longrow == 1:
            print(book1name + ":" + sheetname1)
        elif longrow == 2:
            print(book2name + ":" + sheetname2)
        else:
            raise Exception("What?  longrow was not set!")

if extraRows > 0:
    print("%3d extra rows in" % extraRows)
    if longsheet == 1:
示例#5
0
    totalCells2 = len(rowvalues2)
    extraCells = 0
    if (totalCells1 > totalCells2):
        longrow = 1
        extraCells = (totalCells1 - totalCells2)
        minCells = totalCells2
    elif (totalCells1 > totalCells2):
        longrow = 2
        extraCells = (totalCells2 - totalCells1)
        minCells = totalCells1
    else:
        minCells = totalCells1  # doesnt matter which
    for j in range(0, minCells):
        if (rowvalues1[j] != rowvalues2[j]):
            print("%3d,%2s--%34s : %34s" %
                  (i + 1, xlrd.colname(j), six.u(
                      rowvalues1[j]).encode('utf-8')[:34], six.u(
                          rowvalues2[j]).encode('utf-8')[:34]))
    if (extraCells > 0):
        print("%3d extra cells in row %3d in" % (extraCells, i + 1), )
        if (longrow == 1):
            print(book1name + ":" + sheetname1)
        elif (longrow == 2):
            print(book2name + ":" + sheetname2)
        else:
            raise Exception("What?  longrow was not set!")

if (extraRows > 0):
    print("%3d extra rows in" % extraRows, )
    if (longsheet == 1):
        print(book1name + ":" + sheetname1)
    elif (longsheet == 2):