Beispiel #1
0
def main(argv):
    if not argv[1:]:
        path = '.'
    else:
        path = argv[1]

    reps = []
    if os.path.isdir(path):
        for file_path in os.listdir(path):
            abs_file_path = os.path.join(path, file_path)
            if not os.path.isfile(abs_file_path):
                continue
            if file_path.startswith("rep-") and \
                    file_path.endswith(".rst") and \
                    not file_path == 'rep-0000.rst':
                with codecs.open(abs_file_path, 'r',
                                 encoding='UTF-8') as rep_file:
                    try:
                        rep = REP(rep_file)
                        if rep.number != int(file_path[4:-4]):
                            raise REPError(
                                'REP number does not match file ' + 'name',
                                file_path, rep.number)
                        reps.append(rep)
                    except REPError as e:
                        errmsg = "Error processing REP %s (%s), excluding:" % \
                            (e.number, e.filename)
                        print(errmsg, e, file=sys.stderr)
                        sys.exit(1)
        reps.sort(key=attrgetter('number'))
    elif os.path.isfile(path):
        with open(path, 'r') as rep_file:
            reps.append(REP(rep_file))
    else:
        raise ValueError("argument must be a directory or file path")

    with codecs.open('rep-0000.rst', 'w', encoding='UTF-8') as rep0_file:
        write_rep0(reps, rep0_file)
Beispiel #2
0
def main(argv):
    if not argv[1:]:
        path = '.'
    else:
        path = argv[1]

    reps = []
    if os.path.isdir(path):
        for file_path in os.listdir(path):
            abs_file_path = os.path.join(path, file_path)
            if not os.path.isfile(abs_file_path):
                continue
            if file_path.startswith("rep-") and \
                    file_path.endswith(".rst") and \
                    not file_path == 'rep-0000.rst':
                with codecs.open(
                        abs_file_path, 'r', encoding='UTF-8') as rep_file:
                    try:
                        rep = REP(rep_file)
                        if rep.number != int(file_path[4:-4]):
                            raise REPError('REP number does not match file ' +
                                           'name', file_path, rep.number)
                        reps.append(rep)
                    except REPError as e:
                        errmsg = "Error processing REP %s (%s), excluding:" % \
                            (e.number, e.filename)
                        print(errmsg, e, file=sys.stderr)
                        sys.exit(1)
        reps.sort(key=attrgetter('number'))
    elif os.path.isfile(path):
        with open(path, 'r') as rep_file:
            reps.append(REP(rep_file))
    else:
        raise ValueError("argument must be a directory or file path")

    with codecs.open('rep-0000.rst', 'w', encoding='UTF-8') as rep0_file:
        write_rep0(reps, rep0_file)
Beispiel #3
0
                continue
            if file_path.startswith("rep-") and file_path.endswith(
                    ".rst") and not file_path == 'rep-0000.rst':
                with codecs.open(abs_file_path, 'r',
                                 encoding='UTF-8') as rep_file:
                    try:
                        rep = REP(rep_file)
                        if rep.number != int(file_path[4:-4]):
                            raise REPError(
                                'REP number does not match file name',
                                file_path, rep.number)
                        reps.append(rep)
                    except REPError, e:
                        errmsg = "Error processing REP %s (%s), excluding:" % \
                            (e.number, e.filename)
                        print >> sys.stderr, errmsg, e
                        sys.exit(1)
        reps.sort(key=attrgetter('number'))
    elif os.path.isfile(path):
        with open(path, 'r') as rep_file:
            reps.append(REP(rep_file))
    else:
        raise ValueError("argument must be a directory or file path")

    with codecs.open('rep-0000.rst', 'w', encoding='UTF-8') as rep0_file:
        write_rep0(reps, rep0_file)


if __name__ == "__main__":
    main(sys.argv)
Beispiel #4
0
    if os.path.isdir(path):
        for file_path in os.listdir(path):
            abs_file_path = os.path.join(path, file_path)
            if not os.path.isfile(abs_file_path):
                continue
            if file_path.startswith("rep-") and file_path.endswith(".rst") and not file_path == 'rep-0000.rst':
                with codecs.open(abs_file_path, 'r', encoding='UTF-8') as rep_file:
                    try:
                        rep = REP(rep_file)
                        if rep.number != int(file_path[4:-4]):
                            raise REPError('REP number does not match file name',
                                           file_path, rep.number)
                        reps.append(rep)
                    except REPError, e:
                        errmsg = "Error processing REP %s (%s), excluding:" % \
                            (e.number, e.filename)
                        print >>sys.stderr, errmsg, e
                        sys.exit(1)
        reps.sort(key=attrgetter('number'))
    elif os.path.isfile(path):
        with open(path, 'r') as rep_file:
            reps.append(REP(rep_file))
    else:
        raise ValueError("argument must be a directory or file path")

    with codecs.open('rep-0000.rst', 'w', encoding='UTF-8') as rep0_file:
        write_rep0(reps, rep0_file)

if __name__ == "__main__":
    main(sys.argv)