diff options
| author | DasIch <dasdasich@gmail.com> | 2010-08-15 11:55:46 +0200 |
|---|---|---|
| committer | DasIch <dasdasich@gmail.com> | 2010-08-15 11:55:46 +0200 |
| commit | 7926331c6fa1d80e08ae4d6c19bc1cfdce9e16c8 (patch) | |
| tree | c31e72f4dc43e03502213c08a6d036492ea98856 /utils/convert.py | |
| parent | c8f16b61cc6682fbbe47a5902b3c92e4b9336be0 (diff) | |
| parent | c0e116c026aebb10854d8e083e702f6290403116 (diff) | |
| download | sphinx-7926331c6fa1d80e08ae4d6c19bc1cfdce9e16c8.tar.gz | |
merge with lehmannro/sphinx-i18n
Diffstat (limited to 'utils/convert.py')
| -rw-r--r-- | utils/convert.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/utils/convert.py b/utils/convert.py new file mode 100644 index 00000000..f025c49a --- /dev/null +++ b/utils/convert.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +# coding: utf-8 +""" + Converts files with 2to3 + ~~~~~~~~~~~~~~~~~~~~~~~~ + + Creates a Python 3 version of each file. + + The Python3 version of a file foo.py will be called foo3.py. + + :copyright: Copyright 2010 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" +import os +import sys +from glob import iglob +from optparse import OptionParser +from shutil import copy +from distutils.util import run_2to3 + +def main(argv): + parser = OptionParser(usage='%prog [path]') + parser.add_option('-i', '--ignorepath', dest='ignored_paths', + action='append', default=[]) + options, args = parser.parse_args(argv) + + ignored_paths = {os.path.abspath(p) for p in options.ignored_paths} + + path = os.path.abspath(args[0]) if args else os.getcwd() + convertables = [] + for filename in iglob(os.path.join(path, '*.py')): + if filename in ignored_paths: + continue + basename, ext = os.path.splitext(filename) + if basename.endswith('3'): + continue + filename3 = basename + '3' + ext + copy(filename, filename3) + convertables.append(filename3) + run_2to3(convertables) + +if __name__ == "__main__": + main(sys.argv[1:]) |
