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