Mercurial > hg
annotate tests/f @ 24562:e55449dae606
test-hgweb-json: fix URL for file revision tests
Likely a copy and paste fail.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 31 Mar 2015 21:49:10 -0700 |
parents | 7d0aa6269ece |
children | 6686ae524f94 |
rev | line source |
---|---|
23860
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
2 |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
3 """ |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
4 Utility for inspecting files in various ways. |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
5 |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
6 This tool is like the collection of tools found in a unix environment but are |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
7 cross platform and stable and suitable for our needs in the test suite. |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
8 |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
9 This can be used instead of tools like: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
10 [ |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
11 dd |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
12 find |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
13 head |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
14 hexdump |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
15 ls |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
16 md5sum |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
17 readlink |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
18 sha1sum |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
19 stat |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
20 tail |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
21 test |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
22 readlink.py |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
23 md5sum.py |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
24 """ |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
25 |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
26 import sys, os, errno, re, glob, optparse |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
27 |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
28 def visit(opts, filenames, outfile): |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
29 """Process filenames in the way specified in opts, writing output to |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
30 outfile.""" |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
31 for f in sorted(filenames): |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
32 isstdin = f == '-' |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
33 if not isstdin and not os.path.lexists(f): |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
34 outfile.write('%s: file not found\n' % f) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
35 continue |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
36 quiet = opts.quiet and not opts.recurse or isstdin |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
37 isdir = os.path.isdir(f) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
38 islink = os.path.islink(f) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
39 isfile = os.path.isfile(f) and not islink |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
40 dirfiles = None |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
41 content = None |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
42 facts = [] |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
43 if isfile: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
44 if opts.type: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
45 facts.append('file') |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
46 if opts.hexdump or opts.dump or opts.md5: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
47 content = file(f).read() |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
48 elif islink: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
49 if opts.type: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
50 facts.append('link') |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
51 content = os.readlink(f) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
52 elif isstdin: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
53 content = sys.stdin.read() |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
54 if opts.size: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
55 facts.append('size=%s' % len(content)) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
56 elif isdir: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
57 if opts.recurse or opts.type: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
58 dirfiles = glob.glob(f + '/*') |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
59 facts.append('directory with %s files' % len(dirfiles)) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
60 elif opts.type: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
61 facts.append('type unknown') |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
62 if not isstdin: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
63 stat = os.lstat(f) |
23911
593a5cd709a2
tests: teach f not to report directory size
Matt Mackall <mpm@selenic.com>
parents:
23860
diff
changeset
|
64 if opts.size and not isdir: |
23860
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
65 facts.append('size=%s' % stat.st_size) |
23912
7d0aa6269ece
tests: teach f not to report symlink mode bits
Matt Mackall <mpm@selenic.com>
parents:
23911
diff
changeset
|
66 if opts.mode and not islink: |
23860
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
67 facts.append('mode=%o' % (stat.st_mode & 0777)) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
68 if opts.links: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
69 facts.append('links=%s' % stat.st_nlink) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
70 if opts.newer: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
71 # mtime might be in whole seconds so newer file might be same |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
72 if stat.st_mtime >= os.stat(opts.newer).st_mtime: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
73 facts.append('newer than %s' % opts.newer) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
74 else: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
75 facts.append('older than %s' % opts.newer) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
76 if opts.md5 and content is not None: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
77 try: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
78 from hashlib import md5 |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
79 except ImportError: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
80 from md5 import md5 |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
81 facts.append('md5=%s' % md5(content).hexdigest()[:opts.bytes]) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
82 if opts.sha1 and content is not None: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
83 try: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
84 from hashlib import sha1 |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
85 except ImportError: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
86 from sha import sha as sha1 |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
87 facts.append('sha1=%s' % sha1(content).hexdigest()[:opts.bytes]) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
88 if isstdin: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
89 outfile.write(', '.join(facts) + '\n') |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
90 elif facts: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
91 outfile.write('%s: %s\n' % (f, ', '.join(facts))) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
92 elif not quiet: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
93 outfile.write('%s:\n' % f) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
94 if content is not None: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
95 chunk = content |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
96 if not islink: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
97 if opts.lines: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
98 if opts.lines >= 0: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
99 chunk = ''.join(chunk.splitlines(True)[:opts.lines]) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
100 else: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
101 chunk = ''.join(chunk.splitlines(True)[opts.lines:]) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
102 if opts.bytes: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
103 if opts.bytes >= 0: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
104 chunk = chunk[:opts.bytes] |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
105 else: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
106 chunk = chunk[opts.bytes:] |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
107 if opts.hexdump: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
108 for i in range(0, len(chunk), 16): |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
109 s = chunk[i:i+16] |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
110 outfile.write('%04x: %-47s |%s|\n' % |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
111 (i, ' '.join('%02x' % ord(c) for c in s), |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
112 re.sub('[^ -~]', '.', s))) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
113 if opts.dump: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
114 if not quiet: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
115 outfile.write('>>>\n') |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
116 outfile.write(chunk) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
117 if not quiet: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
118 if chunk.endswith('\n'): |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
119 outfile.write('<<<\n') |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
120 else: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
121 outfile.write('\n<<< no trailing newline\n') |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
122 if opts.recurse and dirfiles: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
123 assert not isstdin |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
124 visit(opts, dirfiles, outfile) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
125 |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
126 if __name__ == "__main__": |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
127 parser = optparse.OptionParser("%prog [options] [filenames]") |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
128 parser.add_option("-t", "--type", action="store_true", |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
129 help="show file type (file or directory)") |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
130 parser.add_option("-m", "--mode", action="store_true", |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
131 help="show file mode") |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
132 parser.add_option("-l", "--links", action="store_true", |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
133 help="show number of links") |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
134 parser.add_option("-s", "--size", action="store_true", |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
135 help="show size of file") |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
136 parser.add_option("-n", "--newer", action="store", |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
137 help="check if file is newer (or same)") |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
138 parser.add_option("-r", "--recurse", action="store_true", |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
139 help="recurse into directories") |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
140 parser.add_option("-S", "--sha1", action="store_true", |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
141 help="show sha1 hash of the content") |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
142 parser.add_option("-M", "--md5", action="store_true", |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
143 help="show md5 hash of the content") |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
144 parser.add_option("-D", "--dump", action="store_true", |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
145 help="dump file content") |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
146 parser.add_option("-H", "--hexdump", action="store_true", |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
147 help="hexdump file content") |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
148 parser.add_option("-B", "--bytes", type="int", |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
149 help="number of characters to dump") |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
150 parser.add_option("-L", "--lines", type="int", |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
151 help="number of lines to dump") |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
152 parser.add_option("-q", "--quiet", action="store_true", |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
153 help="no default output") |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
154 (opts, filenames) = parser.parse_args(sys.argv[1:]) |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
155 if not filenames: |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
156 filenames = ['-'] |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
157 |
bead0c7b4f68
tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
158 visit(opts, filenames, sys.stdout) |