~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to tools/win32/ostools.py

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
    ostools.py copytodir FILES... DIR
10
10
                    copy files to specified directory
11
11
 
 
12
    ostools.py copytree FILES... DIR
 
13
                    copy files to specified directory keeping relative paths
 
14
 
12
15
    ostools.py remove [FILES...] [DIRS...]
13
16
                    remove files or directories (recursive)
14
17
"""
18
21
import shutil
19
22
import sys
20
23
 
 
24
def makedir(dirname):
 
25
    if not os.path.exists(dirname):
 
26
        os.makedirs(dirname)
 
27
    if not os.path.isdir(dirname):
 
28
        print "Error: Destination is not a directory", dirname
 
29
        return 2
 
30
    return 0
21
31
 
22
32
def main(argv=None):
23
33
    if argv is None:
38
48
            return 1
39
49
 
40
50
        todir = argv.pop()
41
 
        if not os.path.exists(todir):
42
 
            os.makedirs(todir)
43
 
        if not os.path.isdir(todir):
44
 
            print "Error: Destination is not a directory"
45
 
            return 2
 
51
        retcode = makedir(todir)
 
52
        if retcode:
 
53
            return retcode
46
54
 
47
55
        files = []
48
56
        for possible_glob in argv:
55
63
 
56
64
        return 0
57
65
 
 
66
    if cmd == 'copytree':
 
67
        if len(argv) < 2:
 
68
            print "Usage:  ostools.py copytree FILES... DIR"
 
69
            return 1
 
70
 
 
71
        todir = argv.pop()
 
72
        retcode = makedir(todir)
 
73
        if retcode:
 
74
            return retcode
 
75
 
 
76
        files = []
 
77
        for possible_glob in argv:
 
78
            files += glob.glob(possible_glob)
 
79
 
 
80
        for src in files:
 
81
            relative_path = src
 
82
            dest = os.path.join(todir, relative_path)
 
83
            dest_dir = os.path.dirname(dest)
 
84
            retcode = makedir(dest_dir)
 
85
            if retcode:
 
86
                return retcode
 
87
            shutil.copy(src, dest)
 
88
            print "Copied:", src, "=>", dest
 
89
 
 
90
        return 0
 
91
 
58
92
    if cmd == 'remove':
59
93
        if len(argv) == 0:
60
94
            print "Usage:  ostools.py remove [FILES...] [DIRS...]"
76
110
 
77
111
        return 0
78
112
 
 
113
    if cmd == "basename":
 
114
        if len(argv) == 0:
 
115
            print "Usage:  ostools.py basename [PATH | URL]"
 
116
            return 1
 
117
 
 
118
        for path in argv:
 
119
            print os.path.basename(path)
 
120
        return 0
 
121
 
 
122
    if cmd == 'makedir':
 
123
        if len(argv) == 0:
 
124
            print "Usage:  ostools.py makedir DIR"
 
125
            return 1
 
126
 
 
127
        retcode = makedir(argv.pop())
 
128
        if retcode:
 
129
            return retcode
 
130
        return 0
 
131
 
79
132
    print "Usage error"
80
133
    print __doc__
81
134
    return 1