scripts/utils.py
def format_songsheet(song_sheet):
    """Format the songsheet to make sense in non mono-space fonts"""
    c = re.compile('^[A-G](b|#)?(add|maj|min|m|M|\+|-|dim|aug)?[0-9]*(sus)?[0-9]*(\/[A-G](b|#)?)?$')

    result_lines = []
    song_sheet_trimmed = re.compile("\n+").split(song_sheet, 1)[1]
    for line in song_sheet_trimmed.splitlines():
        chord_candidates = line.split()
        result_is_chord = []
        for cand in chord_candidates:
            if c.match(cand):
                result_is_chord.append(True)
            else:
                result_is_chord.append(False)
        # More non-chords than chords?
        if result_is_chord.count(False) >= result_is_chord.count(True):
            result_lines.append(line)
        else:
            result_lines.append(' | '.join(chord_candidates))
    return "\n".join(result_lines)
Format the songsheet to make sense in non mono-space fonts
Format the songsheet to make sense in non mono-space fonts
Format the songsheet to make sense in non mono - space fonts
def format_songsheet(song_sheet):
    c = re.compile('^[A-G](b|#)?(add|maj|min|m|M|\+|-|dim|aug)?[0-9]*(sus)?[0-9]*(\/[A-G](b|#)?)?$')
    result_lines = []
    song_sheet_trimmed = re.compile("\n+").split(song_sheet, 1)[1]
    for line in song_sheet_trimmed.splitlines():
        chord_candidates = line.split()
        result_is_chord = []
        for cand in chord_candidates:
            if c.match(cand):
                result_is_chord.append(True)
            else:
                result_is_chord.append(False)
        if result_is_chord.count(False) >= result_is_chord.count(True):
            result_lines.append(line)
        else:
            result_lines.append(' | '.join(chord_candidates))
    return "\n".join(result_lines)
def format_songsheet ( song_sheet ) : c = re . compile ( '^[A-G](b|#)?(add|maj|min|m|M|\+|-|dim|aug)?[0-9]*(sus)?[0-9]*(\/[A-G](b|#)?)?$' ) result_lines = [ ] song_sheet_trimmed = re . compile ( "\n+" ) . split ( song_sheet , 1 ) [ 1 ] for line in song_sheet_trimmed . splitlines ( ) : chord_candidates = line . split ( ) result_is_chord = [ ] for cand in chord_candidates : if c . match ( cand ) : result_is_chord . append ( True ) else : result_is_chord . append ( False ) if result_is_chord . count ( False ) >= result_is_chord . count ( True ) : result_lines . append ( line ) else : result_lines . append ( ' | ' . join ( chord_candidates ) ) return "\n" . join ( result_lines )
Format the songsheet to make sense in non mono-space fonts
Format the songsheet to make sense in non mono - space fonts
"""Format the songsheet to make sense in non mono-space fonts""" # More non-chords than chords?
song_sheet