~ubuntu-branches/ubuntu/trusty/duplicity/trusty

« back to all changes in this revision

Viewing changes to debian/patches/07caching.dpatch

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2012-12-11 14:52:15 UTC
  • Revision ID: package-import@ubuntu.com-20121211145215-f69sm10v3677eobf
Tags: 0.6.20-0ubuntu3
* debian/patches/07caching.dpatch:
  - Backport caching work done by Steve Atwell, on behalf of Chris J Arges
  (LP: #1013446) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh /usr/share/dpatch/dpatch-run
 
2
## 07caching.dpatch by Chris J Arges <chris.j.arges@canonical.com>
 
3
##
 
4
## All lines beginning with `## DP:' are a description of the patch.
 
5
## DP: This patch backports caching support. (LP: #1013446)
 
6
 
 
7
@DPATCH@
 
8
diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' duplicity-0.6.18~/cached_ops.py duplicity-0.6.18/cached_ops.py
 
9
--- duplicity-0.6.18~/cached_ops.py     1969-12-31 18:00:00.000000000 -0600
 
10
+++ duplicity-0.6.18/cached_ops.py      2012-11-14 10:38:07.139372741 -0600
 
11
@@ -0,0 +1,62 @@
 
12
+# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
 
13
+#
 
14
+# Copyright 2012 Google Inc.
 
15
+#
 
16
+# This file is part of duplicity.
 
17
+#
 
18
+# Duplicity is free software; you can redistribute it and/or modify it
 
19
+# under the terms of the GNU General Public License as published by the
 
20
+# Free Software Foundation; either version 2 of the License, or (at your
 
21
+# option) any later version.
 
22
+#
 
23
+# Duplicity is distributed in the hope that it will be useful, but
 
24
+# WITHOUT ANY WARRANTY; without even the implied warranty of
 
25
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
26
+# General Public License for more details.
 
27
+#
 
28
+# You should have received a copy of the GNU General Public License
 
29
+# along with duplicity; if not, write to the Free Software Foundation,
 
30
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
31
+
 
32
+"""Cache-wrapped functions for grp and pwd lookups."""
 
33
+
 
34
+import grp
 
35
+import pwd
 
36
+
 
37
+
 
38
+class CachedCall(object):
 
39
+    """Decorator for caching the results of function calls."""
 
40
+
 
41
+    def __init__(self, f):
 
42
+        self.cache = {}
 
43
+        self.f = f
 
44
+
 
45
+    def __call__(self, *args):
 
46
+        try:
 
47
+            return self.cache[args]
 
48
+        except (KeyError, TypeError), e:
 
49
+            result = self.f(*args)
 
50
+            if not isinstance(e, TypeError):
 
51
+                # TypeError most likely means that args is not hashable
 
52
+                self.cache[args] = result
 
53
+            return result
 
54
+
 
55
+
 
56
+@CachedCall
 
57
+def getgrgid(gid):
 
58
+    return grp.getgrgid(gid)
 
59
+
 
60
+
 
61
+@CachedCall
 
62
+def getgrnam(name):
 
63
+    return grp.getgrnam(name)
 
64
+
 
65
+
 
66
+@CachedCall
 
67
+def getpwnam(name):
 
68
+    return pwd.getpwnam(name)
 
69
+
 
70
+
 
71
+@CachedCall
 
72
+def getpwuid(uid):
 
73
+    return pwd.getpwuid(uid)
 
74
diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' duplicity-0.6.18~/duplicity/cached_ops.py duplicity-0.6.18/duplicity/cached_ops.py
 
75
--- duplicity-0.6.18~/duplicity/cached_ops.py   1969-12-31 18:00:00.000000000 -0600
 
76
+++ duplicity-0.6.18/duplicity/cached_ops.py    2012-11-14 10:38:11.539372820 -0600
 
77
@@ -0,0 +1,62 @@
 
78
+# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
 
79
+#
 
80
+# Copyright 2012 Google Inc.
 
81
+#
 
82
+# This file is part of duplicity.
 
83
+#
 
84
+# Duplicity is free software; you can redistribute it and/or modify it
 
85
+# under the terms of the GNU General Public License as published by the
 
86
+# Free Software Foundation; either version 2 of the License, or (at your
 
87
+# option) any later version.
 
88
+#
 
89
+# Duplicity is distributed in the hope that it will be useful, but
 
90
+# WITHOUT ANY WARRANTY; without even the implied warranty of
 
91
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
92
+# General Public License for more details.
 
93
+#
 
94
+# You should have received a copy of the GNU General Public License
 
95
+# along with duplicity; if not, write to the Free Software Foundation,
 
96
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
97
+
 
98
+"""Cache-wrapped functions for grp and pwd lookups."""
 
99
+
 
100
+import grp
 
101
+import pwd
 
102
+
 
103
+
 
104
+class CachedCall(object):
 
105
+    """Decorator for caching the results of function calls."""
 
106
+
 
107
+    def __init__(self, f):
 
108
+        self.cache = {}
 
109
+        self.f = f
 
110
+
 
111
+    def __call__(self, *args):
 
112
+        try:
 
113
+            return self.cache[args]
 
114
+        except (KeyError, TypeError), e:
 
115
+            result = self.f(*args)
 
116
+            if not isinstance(e, TypeError):
 
117
+                # TypeError most likely means that args is not hashable
 
118
+                self.cache[args] = result
 
119
+            return result
 
120
+
 
121
+
 
122
+@CachedCall
 
123
+def getgrgid(gid):
 
124
+    return grp.getgrgid(gid)
 
125
+
 
126
+
 
127
+@CachedCall
 
128
+def getgrnam(name):
 
129
+    return grp.getgrnam(name)
 
130
+
 
131
+
 
132
+@CachedCall
 
133
+def getpwnam(name):
 
134
+    return pwd.getpwnam(name)
 
135
+
 
136
+
 
137
+@CachedCall
 
138
+def getpwuid(uid):
 
139
+    return pwd.getpwuid(uid)
 
140
diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' duplicity-0.6.18~/duplicity/path.py duplicity-0.6.18/duplicity/path.py
 
141
--- duplicity-0.6.18~/duplicity/path.py 2012-02-29 13:24:04.000000000 -0600
 
142
+++ duplicity-0.6.18/duplicity/path.py  2012-11-14 10:38:11.539372820 -0600
 
143
@@ -26,7 +26,7 @@
 
144
 
 
145
 """
 
146
 
 
147
-import stat, errno, socket, time, re, gzip, pwd, grp
 
148
+import stat, errno, socket, time, re, gzip
 
149
 
 
150
 from duplicity import tarfile
 
151
 from duplicity import file_naming
 
152
@@ -36,6 +36,7 @@
 
153
 from duplicity import librsync
 
154
 from duplicity import log #@UnusedImport
 
155
 from duplicity import dup_time
 
156
+from duplicity import cached_ops
 
157
 from duplicity.lazy import * #@UnusedWildImport
 
158
 
 
159
 _copy_blocksize = 64 * 1024
 
160
@@ -206,13 +207,13 @@
 
161
         try:
 
162
             if globals.numeric_owner:
 
163
                 raise KeyError
 
164
-            self.stat.st_uid = pwd.getpwnam(tarinfo.uname)[2]
 
165
+            self.stat.st_uid = cached_ops.getpwnam(tarinfo.uname)[2]
 
166
         except KeyError:
 
167
             self.stat.st_uid = tarinfo.uid
 
168
         try:
 
169
             if globals.numeric_owner:
 
170
                 raise KeyError
 
171
-            self.stat.st_gid = grp.getgrnam(tarinfo.gname)[2]
 
172
+            self.stat.st_gid = cached_ops.getgrnam(tarinfo.gname)[2]
 
173
         except KeyError:
 
174
             self.stat.st_gid = tarinfo.gid
 
175
 
 
176
@@ -284,11 +285,11 @@
 
177
                 ti.mtime = int(self.stat.st_mtime)
 
178
 
 
179
             try:
 
180
-                ti.uname = pwd.getpwuid(ti.uid)[0]
 
181
+                ti.uname = cached_ops.getpwuid(ti.uid)[0]
 
182
             except KeyError:
 
183
                 ti.uname = ''
 
184
             try:
 
185
-                ti.gname = grp.getgrgid(ti.gid)[0]
 
186
+                ti.gname = cached_ops.getgrgid(ti.gid)[0]
 
187
             except KeyError:
 
188
                 ti.gname = ''
 
189
 
 
190
diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' duplicity-0.6.18~/duplicity/tarfile.py duplicity-0.6.18/duplicity/tarfile.py
 
191
--- duplicity-0.6.18~/duplicity/tarfile.py      2012-02-29 13:24:04.000000000 -0600
 
192
+++ duplicity-0.6.18/duplicity/tarfile.py       2012-11-14 10:38:11.539372820 -0600
 
193
@@ -53,10 +53,8 @@
 
194
 import re
 
195
 import operator
 
196
 
 
197
-try:
 
198
-    import grp, pwd
 
199
-except ImportError:
 
200
-    grp = pwd = None
 
201
+from duplicity import cached_ops
 
202
+grp = pwd = cached_ops
 
203
 
 
204
 # from tarfile import *
 
205
 __all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError"]