예제 #1
0
def read_cuesheet_string(cuesheet):
    """given a unicode string of cuesheet data returns a Cuesheet object

    raises SheetException if some error occurs parsing the file"""

    import audiotools.ply.lex as lex
    import audiotools.ply.yacc as yacc
    from audiotools.ply.yacc import NullLogger
    import audiotools.cue.tokrules
    import audiotools.cue.yaccrules
    from sys import version_info

    str_type = str if (version_info[0] >= 3) else unicode

    assert (isinstance(cuesheet, str_type))

    lexer = lex.lex(module=audiotools.cue.tokrules)
    lexer.input(cuesheet)
    parser = yacc.yacc(module=audiotools.cue.yaccrules,
                       debug=0,
                       errorlog=NullLogger(),
                       write_tables=0)
    try:
        return parser.parse(lexer=lexer)
    except ValueError as err:
        raise SheetException(str(err))
예제 #2
0
def read_tocfile(filename):
    """returns a Sheet from a TOC filename on disk

    raises TOCException if some error occurs reading or parsing the file
    """

    try:
        return read_tocfile_string(open(filename, "rb").read())
    except IOError:
        raise SheetException("unable to open file")
예제 #3
0
def read_cuesheet(filename):
    """returns a Cuesheet from a cuesheet filename on disk

    raises SheetException if some error occurs reading or parsing the file
    """

    from audiotools import SheetException

    try:
        return read_cuesheet_string(open(filename, "rb").read())
    except IOError:
        raise SheetException("unable to open file")
예제 #4
0
def read_tocfile_string(tocfile):
    """given a plain string of .toc data, returns a TOCFile object

    raises SheetException if some error occurs parsing the file"""

    import audiotools.ply.lex as lex
    import audiotools.ply.yacc as yacc
    from audiotools.ply.yacc import NullLogger
    import audiotools.toc.tokrules
    import audiotools.toc.yaccrules

    lexer = lex.lex(module=audiotools.toc.tokrules)
    lexer.input(tocfile)
    parser = yacc.yacc(module=audiotools.toc.yaccrules,
                       debug=0,
                       errorlog=NullLogger(),
                       write_tables=0)
    try:
        return parser.parse(lexer=lexer)
    except ValueError as err:
        raise SheetException(str(err))