[Python-checkins] r68038 - in sandbox/trunk/pep0: genpepindex.py pep0/__init__.py
benjamin.peterson
python-checkins at python.org
Mon Dec 29 23:49:45 CET 2008
Author: benjamin.peterson
Date: Mon Dec 29 23:49:45 2008
New Revision: 68038
Log:
make a proper script out this
Added:
sandbox/trunk/pep0/genpepindex.py (contents, props changed)
Modified:
sandbox/trunk/pep0/pep0/__init__.py
Added: sandbox/trunk/pep0/genpepindex.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/pep0/genpepindex.py Mon Dec 29 23:49:45 2008
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+"""Auto-generate PEP 0 (PEP index).
+
+Generating the PEP index is a multi-step process. To begin, you must first
+parse the PEP files themselves, which in and of itself takes a couple of steps:
+
+ 1. Parse metadata.
+ 2. Validate metadata.
+
+With the PEP information collected, to create the index itself you must:
+
+ 1. Output static text.
+ 2. Format an entry for the PEP.
+ 3. Output the PEP (both by category and numerical index).
+
+"""
+from __future__ import absolute_import, with_statement
+
+import sys
+import os
+import codecs
+
+from operator import attrgetter
+
+from pep0.output import write_pep0
+from pep0.pep import PEP
+
+
+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):
+ abs_file_path = os.path.join(path, file_path)
+ if not os.path.isfile(abs_file_path):
+ continue
+ if (not file_path.startswith('pep-') or
+ not file_path.endswith('.txt')):
+ continue
+ with codecs.open(abs_file_path, 'r', encoding='UTF-8') as pep_file:
+ peps.append(PEP(pep_file))
+ else:
+ 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-0.txt', 'w', encoding='UTF-8') as pep0_file:
+ write_pep0(peps, pep0_file)
+
+if __name__ == "__main__":
+ main(sys.argv)
Modified: sandbox/trunk/pep0/pep0/__init__.py
==============================================================================
--- sandbox/trunk/pep0/pep0/__init__.py (original)
+++ sandbox/trunk/pep0/pep0/__init__.py Mon Dec 29 23:49:45 2008
@@ -1,53 +1 @@
-"""Auto-generate PEP 0 (PEP index).
-
-Generating the PEP index is a multi-step process. To begin, you must first
-parse the PEP files themselves, which in and of itself takes a couple of steps:
-
- 1. Parse metadata.
- 2. Validate metadata.
-
-With the PEP information collected, to create the index itself you must:
-
- 1. Output static text.
- 2. Format an entry for the PEP.
- 3. Output the PEP (both by category and numerical index).
-
-"""
-from __future__ import absolute_import, with_statement
-
-import codecs
-
-if __name__ == '__main__':
- from pep0.output import write_pep0
- from pep0.pep import PEP
-
- from operator import attrgetter
- import os.path
- from sys import argv, stdout
-
- if not argv[1:]:
- path = '.'
- else:
- path = argv[1]
-
- peps = []
- 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 (not file_path.startswith('pep-') or
- not file_path.endswith('.txt')):
- continue
- with codecs.open(abs_file_path, 'r', encoding='UTF-8') as pep_file:
- peps.append(PEP(pep_file))
- else:
- 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-0.txt', 'w', encoding='UTF-8') as pep0_file:
- write_pep0(peps, pep0_file)
+# Empty
More information about the Python-checkins
mailing list