File: make3.py

package info (click to toggle)
python-bsddb3 5.2.0-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,012 kB
  • sloc: python: 15,027; ansic: 8,521; makefile: 114; sh: 5
file content (53 lines) | stat: -rw-r--r-- 1,387 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python

import sys, os
refactor_path="/usr/local/lib/python3.2/"

def make2to3(path_from, path_to) :
    if os.path.isdir(path_from) :
        if path_from.endswith(".svn") : return
        if path_from.endswith(".hg") : return
        try :
            os.mkdir(path_to)
        except :
            pass
        for i in os.listdir(path_from) :
            make2to3(path_from+"/"+i,path_to+"/"+i)
        return

    cwd = os.getcwd()
    if (not path_from.endswith(".py")) or (os.path.exists(path_to) and \
        (os.stat(path_from).st_mtime < os.stat(path_to).st_mtime)) :
            return
    print "*** Converting", path_to
    if path_from[0] != "/" :
        path_from = cwd+"/"+path_from
    if path_to[0] != "/" :
        path_to = cwd+"/"+path_to

    retcode = 0
    try :
        open(path_to, "w").write(open(path_from, "r").read())
        import subprocess, cStringIO
        process = subprocess.Popen(["2to3", "-w", path_to], cwd=refactor_path)
        retcode = process.wait()
    except :
        os.remove(path_to)
        raise

    try :
        os.remove(path_to+".bak")
    except :
        pass

    if retcode :
        os.remove(path_to)
        print "ERROR!"

    return bool(retcode)

print "Using '%s' for 2to3 conversion tool" %refactor_path

make2to3("setup2.py", "setup3.py")
make2to3("test2.py", "test3.py")
make2to3("Lib", "Lib3")