/usr/lib/python2.7/dist-packages/tables/scripts/pt2to3.py is in python-tables 3.2.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | # -*- coding: utf-8 -*-
########################################################################
#
# License: BSD
# Created: April 9, 2013
# Author: Anthony Scopatz - scopatz@gmail.com
#
# $Id$
#
########################################################################
"""This utility helps you migrate from PyTables 2.x APIs to 3.x APIs, which
are PEP 8 compliant.
"""
import os
import re
import sys
import argparse
from tables._past import old2newnames, new2oldnames
# Note that it is tempting to use the ast module here, but then this
# breaks transforming cython files. So instead we are going to do the
# dumb thing with replace.
def make_subs(ns):
names = new2oldnames if ns.reverse else old2newnames
s = '(?<=\W)({0})(?=\W)'.format('|'.join(names.keys()))
if ns.ignore_previous:
s += '(?!\s*?=\s*?previous_api(_property)?\()'
s += '(?!\* to \*\w+\*)'
s += '(?!\* parameter has been renamed into \*\w+\*\.)'
s += '(?! is pending deprecation, import \w+ instead\.)'
subs = re.compile(s, flags=re.MULTILINE)
def repl(m):
return names.get(m.group(1), m.group(0))
return subs, repl
def main():
desc = ('PyTables 2.x -> 3.x API transition tool\n\n'
'This tool displays to standard out, so it is \n'
'common to pipe this to another file:\n\n'
'$ pt2to3 oldfile.py > newfile.py')
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('-r', '--reverse', action='store_true', default=False,
dest='reverse',
help="reverts changes, going from 3.x -> 2.x.")
parser.add_argument('-p', '--no-ignore-previous', action='store_false',
default=True, dest='ignore_previous',
help="ignores previous_api() calls.")
parser.add_argument('-o', default=None, dest='output',
help="output file to write to.")
parser.add_argument('-i', '--inplace', action='store_true', default=False,
dest='inplace', help="overwrites the file in-place.")
parser.add_argument('filename', help='path to input file.')
ns = parser.parse_args()
if not os.path.isfile(ns.filename):
sys.exit('file {0!r} not found'.format(ns.filename))
with open(ns.filename, 'r') as f:
src = f.read()
subs, repl = make_subs(ns)
targ = subs.sub(repl, src)
ns.output = ns.filename if ns.inplace else ns.output
if ns.output is None:
sys.stdout.write(targ)
else:
with open(ns.output, 'w') as f:
f.write(targ)
if __name__ == '__main__':
main()
|