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

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

    with codecs.open('pep-0000.txt', 'w', encoding='UTF-8') as pep0_file:
        write_pep0(peps, pep0_file)
示例#2
0
def main(argv):
    if not argv[1:]:
        path = '.'
    else:
        path = argv[1]

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

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

    with codecs.open('pep-0000.txt', 'w', encoding='UTF-8') as pep0_file:
        write_pep0(peps, pep0_file)


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

    with codecs.open('pep-0000.txt', 'w', encoding='UTF-8') as pep0_file:
        write_pep0(peps, pep0_file)

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