Merge lp:~summer-is-gone/duplicity/tz-incremental-fix into lp:duplicity/0.6

Proposed by Ivan Gromov
Status: Merged
Merged at revision: 805
Proposed branch: lp:~summer-is-gone/duplicity/tz-incremental-fix
Merge into: lp:duplicity/0.6
Diff against target: 122 lines (+45/-24)
2 files modified
duplicity/dup_time.py (+15/-8)
testing/dup_timetest.py (+30/-16)
To merge this branch: bzr merge lp:~summer-is-gone/duplicity/tz-incremental-fix
Reviewer Review Type Date Requested Status
Kenneth Loafman Pending
Review via email: mp+81146@code.launchpad.net

Description of the change

This branch fixes tzdata issues on incremental backups and tests in dup_timtest.py.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'duplicity/dup_time.py'
2--- duplicity/dup_time.py 2011-03-29 17:00:36 +0000
3+++ duplicity/dup_time.py 2011-11-03 13:29:47 +0000
4@@ -21,8 +21,7 @@
5
6 """Provide time related exceptions and functions"""
7
8-import time, types, re
9-
10+import time, types, re, calendar
11 from duplicity import globals
12
13
14@@ -119,12 +118,20 @@
15 # works in terms of the current timezone and we have a
16 # timezone offset in the string.
17 timetuple = (year, month, day, hour, minute, second, -1, -1, 0)
18- local_in_secs = time.mktime(timetuple)
19- # mktime assumed that the tuple was a local time. Compensate
20- # by subtracting the value for the current timezone.
21- # We don't need to worry about DST here because we turned it
22- # off in the tuple
23- utc_in_secs = local_in_secs - time.timezone
24+
25+ if len(timestring) == 16:
26+ # as said in documentation, time.gmtime() and timegm() are each others' inverse.
27+ # As far as UTC format is used in new file format,
28+ # do not rely on system's python DST and tzdata settings
29+ # and use functions that working with UTC
30+ utc_in_secs = calendar.timegm(timetuple)
31+ else:
32+ # mktime assumed that the tuple was a local time. Compensate
33+ # by subtracting the value for the current timezone.
34+ # We don't need to worry about DST here because we turned it
35+ # off in the tuple
36+ local_in_secs = time.mktime(timetuple)
37+ utc_in_secs = local_in_secs - time.timezone
38 # Now apply the offset that we were given in the time string
39 # This gives the correct number of seconds from the epoch
40 # even when we're not in the same timezone that wrote the
41
42=== modified file 'testing/dup_timetest.py'
43--- testing/dup_timetest.py 2009-09-17 16:13:40 +0000
44+++ testing/dup_timetest.py 2011-11-03 13:29:47 +0000
45@@ -21,7 +21,7 @@
46
47 import config
48 import sys, unittest, time, types
49-
50+from copy import copy
51 from duplicity import globals
52 from duplicity import dup_time
53
54@@ -41,9 +41,12 @@
55
56 def testConversion_separator(self):
57 """Same as testConversion, but change time Separator"""
58- globals.time_separator = "_"
59- self.testConversion()
60- globals.time_separator = ":"
61+ prev_sep = copy(globals.time_separator)
62+ try:
63+ globals.time_separator = "_"
64+ self.testConversion()
65+ finally:
66+ globals.time_separator = prev_sep
67
68 def testCmp(self):
69 """Test time comparisons"""
70@@ -61,16 +64,19 @@
71
72 def testCmp_separator(self):
73 """Like testCmp but with new separator"""
74- globals.time_separator = "_"
75- cmp = dup_time.cmp
76- assert cmp(1,2) == -1
77- assert cmp(2,2) == 0
78- assert cmp(5,1) == 1
79- assert cmp("2001-09-01T21_49_04Z", "2001-08-01T21_49_04Z") == 1
80- assert cmp("2001-09-01T04_49_04+03_23", "2001-09-01T21_49_04Z") == -1
81- assert cmp("2001-09-01T12_00_00Z", "2001-09-01T04_00_00-08_00") == 0
82- assert cmp("2001-09-01T12_00_00-08_00", "2001-09-01T12_00_00-07_00") == 1
83- globals.time_separator = ":"
84+ prev_sep = copy(globals.time_separator)
85+ try:
86+ globals.time_separator = "_"
87+ cmp = dup_time.cmp
88+ assert cmp(1,2) == -1
89+ assert cmp(2,2) == 0
90+ assert cmp(5,1) == 1
91+ assert cmp("2001-09-01T21_49_04Z", "2001-08-01T21_49_04Z") == 1
92+ assert cmp("2001-09-01T04_49_04+03_23", "2001-09-01T21_49_04Z") == -1
93+ assert cmp("2001-09-01T12_00_00Z", "2001-09-01T04_00_00-08_00") == 0
94+ assert cmp("2001-09-01T12_00_00-08_00", "2001-09-01T12_00_00-07_00") == 1
95+ finally:
96+ globals.time_separator = prev_sep
97
98 def testStringtotime(self):
99 """Test converting string to time"""
100@@ -133,12 +139,20 @@
101 self.assertRaises(dup_time.TimeException, g2t, "hello")
102 self.assertRaises(dup_time.TimeException, g2t, "")
103 self.assertRaises(dup_time.TimeException, g2t, "3q")
104+
105+ def testConvertion(self):
106+ t = int(time.time())
107+ assert dup_time.stringtotime(dup_time.timetostring(t)) == t
108
109 class TimeTest1(TimeTest, unittest.TestCase):
110- globals.old_filenames = False
111+
112+ def setUp(self):
113+ globals.old_filenames = False
114
115 class TimeTest2(TimeTest, unittest.TestCase):
116- globals.old_filenames = True
117+
118+ def setUp(self):
119+ globals.old_filenames = True
120
121 if __name__ == '__main__':
122 unittest.main()

Subscribers

People subscribed via source and target branches

to all changes: