/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tools/win32/ostools.py

  • Committer: Robert Collins
  • Date: 2007-09-19 05:14:14 UTC
  • mto: (2835.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 2836.
  • Revision ID: robertc@robertcollins.net-20070919051414-2tgjqteg7k3ps4h0
* ``pull``, ``merge`` and ``push`` will no longer silently correct some
  repository index errors that occured as a result of the Weave disk format.
  Instead the ``reconcile`` command needs to be run to correct those
  problems if they exist (and it has been able to fix most such problems
  since bzr 0.8). Some new problems have been identified during this release
  and you should run ``bzr check`` once on every repository to see if you
  need to reconcile. If you cannot ``pull`` or ``merge`` from a remote
  repository due to mismatched parent errors - a symptom of index errors -
  you should simply take a full copy of that remote repository to a clean
  directory outside any local repositories, then run reconcile on it, and
  finally pull from it locally. (And naturally email the repositories owner
  to ask them to upgrade and run reconcile).
  (Robert Collins)

* ``VersionedFile.fix_parents`` has been removed as a harmful API.
  ``VersionedFile.join`` will no longer accept different parents on either
  side of a join - it will either ignore them, or error, depending on the
  implementation. See notes when upgrading for more information.
  (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
"""Cross-platform os tools: files/directories manipulations
 
4
Usage:
 
5
 
 
6
    ostools.py help
 
7
                    prints this help
 
8
 
 
9
    ostools.py copytodir FILES... DIR
 
10
                    copy files to specified directory
 
11
 
 
12
    ostools.py copytree FILES... DIR
 
13
                    copy files to specified directory keeping relative paths
 
14
 
 
15
    ostools.py remove [FILES...] [DIRS...]
 
16
                    remove files or directories (recursive)
 
17
"""
 
18
 
 
19
import glob
 
20
import os
 
21
import shutil
 
22
import sys
 
23
 
 
24
 
 
25
def main(argv=None):
 
26
    if argv is None:
 
27
        argv = sys.argv[1:]
 
28
 
 
29
    if not argv:
 
30
        argv = ['help']
 
31
 
 
32
    cmd = argv.pop(0)
 
33
 
 
34
    if cmd == 'help':
 
35
        print __doc__
 
36
        return 0
 
37
 
 
38
    if cmd == 'copytodir':
 
39
        if len(argv) < 2:
 
40
            print "Usage:  ostools.py copytodir FILES... DIR"
 
41
            return 1
 
42
 
 
43
        todir = argv.pop()
 
44
        if not os.path.exists(todir):
 
45
            os.makedirs(todir)
 
46
        if not os.path.isdir(todir):
 
47
            print "Error: Destination is not a directory"
 
48
            return 2
 
49
 
 
50
        files = []
 
51
        for possible_glob in argv:
 
52
            files += glob.glob(possible_glob)
 
53
 
 
54
        for src in files:
 
55
            dest = os.path.join(todir, os.path.basename(src))
 
56
            shutil.copy(src, dest)
 
57
            print "Copied:", src, "=>", dest
 
58
 
 
59
        return 0
 
60
 
 
61
    if cmd == 'copytree':
 
62
        if len(argv) < 2:
 
63
            print "Usage:  ostools.py copytree FILES... DIR"
 
64
            return 1
 
65
 
 
66
        todir = argv.pop()
 
67
        if not os.path.exists(todir):
 
68
            os.makedirs(todir)
 
69
        if not os.path.isdir(todir):
 
70
            print "Error: Destination is not a directory"
 
71
            return 2
 
72
 
 
73
        files = []
 
74
        for possible_glob in argv:
 
75
            files += glob.glob(possible_glob)
 
76
 
 
77
        for src in files:
 
78
            relative_path = src
 
79
            dest = os.path.join(todir, relative_path)
 
80
            dest_dir = os.path.dirname(dest)
 
81
            if not os.path.isdir(dest_dir):
 
82
                os.makedirs(dest_dir)
 
83
            shutil.copy(src, dest)
 
84
            print "Copied:", src, "=>", dest
 
85
 
 
86
        return 0
 
87
 
 
88
    if cmd == 'remove':
 
89
        if len(argv) == 0:
 
90
            print "Usage:  ostools.py remove [FILES...] [DIRS...]"
 
91
            return 1
 
92
 
 
93
        filesdirs = []
 
94
        for possible_glob in argv:
 
95
            filesdirs += glob.glob(possible_glob)
 
96
 
 
97
        for i in filesdirs:
 
98
            if os.path.isdir(i):
 
99
                shutil.rmtree(i)
 
100
                print "Removed:", i
 
101
            elif os.path.isfile(i):
 
102
                os.remove(i)
 
103
                print "Removed:", i
 
104
            else:
 
105
                print "Not found:", i
 
106
 
 
107
        return 0
 
108
 
 
109
    print "Usage error"
 
110
    print __doc__
 
111
    return 1
 
112
 
 
113
 
 
114
if __name__ == "__main__":
 
115
    sys.exit(main())