annotate tests/f @ 29218:fd288d118074

largefiles: send statlfile remote calls only for nonexisting locally files Files that are already in local store should be checked locally. The problem with this implementation is how difference in messages between local and remote checks should look like. For now local errors for file missing and content corrupted looks like this: 'changeset cset: filename references missing storepath\n' 'changeset cset: filename references corrupted storepath\n' for remote it looks like: 'changeset cset: filename missing\n' 'changeset cset: filename: contents differ\n' Contents differ error for remote calls is never raised currently - for now statlfile implementation lacks checking file content.
author liscju <piotr.listkiewicz@gmail.com>
date Mon, 09 May 2016 10:05:32 +0200
parents 0362605b82cf
children b68af177937d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
29160
0362605b82cf py3: make tests/f use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28046
diff changeset
26 from __future__ import absolute_import
0362605b82cf py3: make tests/f use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28046
diff changeset
27
0362605b82cf py3: make tests/f use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28046
diff changeset
28 import errno
0362605b82cf py3: make tests/f use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28046
diff changeset
29 import glob
0362605b82cf py3: make tests/f use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28046
diff changeset
30 import optparse
0362605b82cf py3: make tests/f use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28046
diff changeset
31 import os
0362605b82cf py3: make tests/f use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28046
diff changeset
32 import re
0362605b82cf py3: make tests/f use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28046
diff changeset
33 import sys
23860
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
34
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
35 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
36 """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
37 outfile."""
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
38 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
39 isstdin = f == '-'
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
40 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
41 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
42 continue
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
43 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
44 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
45 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
46 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
47 dirfiles = None
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
48 content = None
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
49 facts = []
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
50 if isfile:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
51 if opts.type:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
52 facts.append('file')
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
53 if opts.hexdump or opts.dump or opts.md5:
26950
6686ae524f94 tests: make 'f' tool open files in binary mode when hexdumping
Matt Harbison <matt_harbison@yahoo.com>
parents: 23912
diff changeset
54 content = file(f, 'rb').read()
23860
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
55 elif islink:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
56 if opts.type:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
57 facts.append('link')
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
58 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
59 elif isstdin:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
60 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
61 if opts.size:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
62 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
63 elif isdir:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
64 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
65 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
66 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
67 elif opts.type:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
68 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
69 if not isstdin:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
70 stat = os.lstat(f)
23911
593a5cd709a2 tests: teach f not to report directory size
Matt Mackall <mpm@selenic.com>
parents: 23860
diff changeset
71 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
72 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
73 if opts.mode and not islink:
28046
742cf5b979ec f: use modern octal number formatting
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28044
diff changeset
74 facts.append('mode=%o' % (stat.st_mode & 0o777))
23860
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
75 if opts.links:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
76 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
77 if opts.newer:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
78 # 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
79 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
80 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
81 else:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
82 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
83 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
84 try:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
85 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
86 except ImportError:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
87 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
88 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
89 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
90 try:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
91 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
92 except ImportError:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
93 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
94 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
95 if isstdin:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
96 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
97 elif facts:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
98 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
99 elif not quiet:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
100 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
101 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
102 chunk = content
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
103 if not islink:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
104 if opts.lines:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
105 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
106 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
107 else:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
108 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
109 if opts.bytes:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
110 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
111 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
112 else:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
113 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
114 if opts.hexdump:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
115 for i in range(0, len(chunk), 16):
28044
e4f70e79a65f f: add whitespace around operator
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26950
diff changeset
116 s = chunk[i:i + 16]
23860
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
117 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
118 (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
119 re.sub('[^ -~]', '.', s)))
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
120 if opts.dump:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
121 if not quiet:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
122 outfile.write('>>>\n')
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
123 outfile.write(chunk)
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
124 if not quiet:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
125 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
126 outfile.write('<<<\n')
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
127 else:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
128 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
129 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
130 assert not isstdin
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
131 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
132
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
133 if __name__ == "__main__":
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
134 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
135 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
136 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
137 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
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 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
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155 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
156 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
157 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
158 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
159 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
160 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
161 (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
162 if not filenames:
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
163 filenames = ['-']
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
164
bead0c7b4f68 tests: add 'f' tool for cross platform file operations in the tests
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
165 visit(opts, filenames, sys.stdout)