Esempio n. 1
0
def update_csv(problem_file_ids, oldcsv, newcsv, logfile):
    ''' Indicate error files in csv. '''
    message = ['Omitting problem files in CSV file...', 'IDs of problem files:']
    log_lines(message, logfile)
    print_lines(message)

    makedirs_filepath(newcsv)

    with open(oldcsv, newline='') as oldf, open(newcsv, 'w') as newf:
        reader = csv.DictReader(oldf)
        writer = csv.DictWriter(newf, fieldnames = reader.fieldnames)
        writer.writeheader()
        for row in reader:
            ID = row['id']
            # for rows with empty string '' as ids, better to fix upstream
            if len(ID) > 0:
                if ID in problem_file_ids:
                    log_lines([ID], logfile)
                    print_lines([ID])
                    row['error-status?'] = 'error'
                    # problem_file_ids.discard(ID)
                    row['omit?'] = 'T'
                    row['omit-reason'] = problem_file_ids[ID]
            writer.writerow(row)
        print('Done with CSV.\nOld:', oldcsv, '\nNew:', newcsv)
Esempio n. 2
0
def run_lilypond_and_log(command, logfile, row, lyfile, errorfile):
    try:
        returncode, console_out = run_command(command)
        # TODO: take advantage of returncode, and also write full error logs to error file
        problem_ids = error_check(console_out, row['id'], os.path.join(row['path'], lyfile), errorfile)
    except Exception as e:
        console_out = ["Exception raised when running LilyPond command: " + str(e)]
        problem_ids = {row['id']: 'exception raised'}
    log_lines(console_out, logfile)
    print_lines(console_out)
    return problem_ids
Esempio n. 3
0
def handle_rows(rows, args):
    ''' args includes: rootdir, logfile, midi, midionly, noletter, noa4,
                       errorfile, ly_stable, ly_dev, stable_version '''
    problem_file_ids = dict()
    for row in rows:
        lyfilenames = row['filename'].split(',,, ')
        version = row['ly-version']
        executable = args.ly_stable if version[:4] == args.stable_version else args.ly_dev

        for lyfile in lyfilenames:
            file_no_extension = lyfile.split('.')[0]
            file_path_ly = os.path.join(args.rootdir, row['path'], lyfile)
            file_path_no_extension = os.path.join(args.rootdir, row['path'], file_no_extension)

            # log 'header' details for this piece in console and args.logfile
            header_out = get_row_log_header(row, lyfile)
            log_lines(header_out, args.logfile)
            print_lines(header_out)

            # MIDI ONLY
            if args.midionly:
                command = get_command_midi_only(file_path_no_extension, file_path_ly, executable)
                midi_problems = run_lilypond_and_log(command, args.logfile, row, lyfile, args.errorfile)
                problem_file_ids.update(midi_problems)

            else:
                midi_letter = args.midi
                midi_a4 = True if args.midi and args.noletter else False

                # LETTER PDF
                if not args.noletter:
                    command = get_command("letter", midi_letter, file_path_no_extension, file_path_ly, executable)
                    letter_problems = run_lilypond_and_log(command, args.logfile, row, lyfile, args.errorfile)
                    problem_file_ids.update(letter_problems)
                    rename_pdf(file_path_no_extension, "-let", args.logfile)

                # A4 PDF
                if not args.noa4:
                    command = get_command("a4", midi_a4, file_path_no_extension, file_path_ly, executable)
                    a4_problems = run_lilypond_and_log(command, args.logfile, row, lyfile, args.errorfile)
                    problem_file_ids.update(a4_problems)
                    rename_pdf(file_path_no_extension, "-a4", args.logfile)

    return problem_file_ids
Esempio n. 4
0
def main(args):
    if not os.path.exists(args.indir):
        print(
            'Oops, bad path given for the directory that should contain the ly files.'
        )
        return
    if not os.path.exists(args.csvpath):
        print('Oops, bad path given for the csv input file.')
        return
    makedirs_filepath(args.logfile)
    makedirs_filepath(args.errorfile)

    error_summary = []
    muto = args.mode == 'mutopia'
    csv_data = read_csv(args.csvpath)
    rows = csv_data[:int(args.count)] if args.count else csv_data
    for row in rows:
        vsn = row['ly-version']

        if (vsn_compare(vsn, greater_than, args.lowvsn)
                and vsn_compare(vsn, less_than, args.highvsn)
                and row['omit?'] != 'T'):

            if muto:
                lypaths = get_ly_paths(os.path.join(args.indir, row['path']))
            else:
                lypaths = [
                    os.path.join(args.indir, row['path'], row['filename'])
                ]

            print('____________________________')
            print(row['id'])
            mutocomp = row['mutopiacomposer'] if muto else ''
            print(row['parse-order'], ': ', mutocomp, row['cn-title'])

            for filepath in lypaths:
                command = get_command(row['ly-version'], args.highvsn,
                                      filepath)
                returncode, console_out = run_command(command)

                console_out_returncode = console_out + [str(returncode)]
                log_lines(console_out_returncode, args.logfile)
                print_lines(console_out_returncode)

                if returncode == 1:
                    error_summary.append(filepath)
                    log_lines(console_out, args.errorfile)

    error_header = ['CONVERT-LY ERROR SUMMARY']
    print('Done. There were', len(error_summary), 'errors.')
    log_lines(error_header + error_summary, args.errorfile)
def main(args):
    if not os.path.exists(args.indir):
        print('Oops, bad path given for the directory that should contain the abc files.')
        return

    makedirs_dirpath(args.outdir)
    makedirs_filepath(args.errorfile)
    makedirs_filepath(args.logfile)

    error_summary = []
    for dirpath, dirnames, filenames in os.walk(args.indir):
        if filenames:
            # get list of all .abc files in directory
            abcs = filter(lambda name: name[-4:] == '.abc', filenames)
            abc_filenames = list(abcs)[:int(args.count)] if args.count else abcs

            for name in abc_filenames:
                readpath = os.path.join(dirpath, name)
                writepath = os.path.join(args.outdir, name[0:-4] + '.ly')

                returncode, console_out = run_command([
                    'abc2ly',
                    '--output=' + writepath,
                    '--strict',
                    readpath
                ])

                console_out_returncode = console_out[:-1] + [str(returncode)]
                log_lines(console_out_returncode, args.logfile)
                print_lines(console_out_returncode)

                if returncode == 1:
                    error_summary.append(readpath)
                    log_lines(console_out, args.errorfile)

    error_header = ['ABC2LY ERROR SUMMARY']
    print('Done. There were', len(error_summary), 'errors.')
    log_lines(error_header + error_summary, args.errorfile)