/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: Vincent Ladeuil
  • Date: 2009-04-11 16:06:53 UTC
  • mto: (4286.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4287.
  • Revision ID: v.ladeuil+lp@free.fr-20090411160653-eq1gfn41q3lzhmss
Cleanup test imports and use features to better track skipped tests.

* bzrlib/tests/workingtree_implementations/__init__.py: 
Fix imports. Delete obsolete comment.

* bzrlib/tests/tree_implementations/test_walkdirs.py:
(TestWalkdirs.get_all_subdirs_expected): Reduce duplication.

* bzrlib/tests/tree_implementations/test_test_trees.py: 
Fix import.

* bzrlib/tests/tree_implementations/test_path_content_summary.py: 
Fix imports.

(TestPathContentSummary.test_unicode_symlink_content_summary,
TestPathContentSummary.test_unicode_symlink_target_summary):Use
UnicodeFilenameFeature instead of try/except UnicodeError.

* bzrlib/tests/tree_implementations/test_inv.py: 
Fix imports.
(TestInventoryWithSymlinks): Factor out test that requires
symlinks and use _test_needs_features.
(TestInventory.test_canonical_path,
TestInventory.test_canonical_path_dir,
TestInventory.test_canonical_path_root,
TestInventory.test_canonical_path_invalid_all,
TestInventory.test_canonical_invalid_child): Use assert(expected,
actual)

* bzrlib/tests/tree_implementations/test_get_symlink_target.py: 
Fix imports.
(TestGetSymlinkTarget.test_get_unicode_symlink_target): Use
UnicodeFilenameFeature instead of try/except UnicodeError.

* bzrlib/tests/tree_implementations/__init__.py: 
Fix imports.

(TestCaseWithTree.get_tree_with_subdirs_and_all_supported_content_types,
TestCaseWithTree._create_tree_with_utf8): Use
UnicodeFilenameFeature instead of try/except UnicodeError.

* bzrlib/tests/test_workingtree_4.py:
Fix too long lines.

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())