]> arthur.barton.de Git - bup.git/blob - t/ns-timestamp-resolutions
subtree-hash: handle non-ASCII path chars
[bup.git] / t / ns-timestamp-resolutions
1 #!/usr/bin/env python
2
3 import os, sys
4
5 argv = sys.argv
6 exe = os.path.realpath(argv[0])
7 exepath = os.path.split(exe)[0] or '.'
8 exeprefix = os.path.split(os.path.abspath(exepath))[0]
9
10 # fix the PYTHONPATH to include our lib dir
11 libpath = os.path.join(exepath, '..', 'lib')
12 sys.path[:0] = [libpath]
13 os.environ['PYTHONPATH'] = libpath + ':' + os.environ.get('PYTHONPATH', '')
14
15 import bup.xstat as xstat
16 from bup.helpers import handle_ctrl_c, saved_errors
17 from bup import metadata, options
18
19 optspec = """
20 ns-timestamp-resolutions TEST_FILE_NAME
21 --
22 """
23
24 handle_ctrl_c()
25
26 o = options.Options(optspec)
27 (opt, flags, extra) = o.parse(sys.argv[1:])
28
29 if len(extra) != 1:
30     o.fatal('must specify a test file name')
31
32 target = extra[0]
33
34 open(target, 'w').close()
35 xstat.utime(target, (123456789, 123456789))
36 meta = metadata.from_path(target)
37
38 def ns_resolution(x):
39     n = 1;
40     while n < 10**9 and x % 10 == 0:
41         x /= 10
42         n *= 10
43     return n
44
45 print ns_resolution(meta.atime), ns_resolution(meta.mtime)
46
47 if saved_errors:
48     log('warning: %d errors encountered\n' % len(saved_errors))
49     sys.exit(1)