Merge lp:~mterry/duplicity/require-2.6 into lp:duplicity/0.6
- require-2.6
- Merge into 0.6-series
Status: | Merged |
---|---|
Merged at revision: | 971 |
Proposed branch: | lp:~mterry/duplicity/require-2.6 |
Merge into: | lp:duplicity/0.6 |
Prerequisite: | lp:~mterry/duplicity/modern-testing |
Diff against target: |
4735 lines (+235/-3624) 24 files modified
README (+1/-2) bin/duplicity.1 (+1/-1) dist/duplicity.spec.template (+2/-2) duplicity/__init__.py (+1/-8) duplicity/_librsyncmodule.c (+0/-9) duplicity/backend.py (+40/-50) duplicity/backends/botobackend.py (+0/-4) duplicity/backends/webdavbackend.py (+2/-2) duplicity/commandline.py (+1/-3) duplicity/log.py (+5/-24) duplicity/tarfile.py (+33/-2592) duplicity/urlparse_2_5.py (+0/-385) po/POTFILES.in (+0/-1) po/duplicity.pot (+125/-123) setup.py (+2/-4) tarfile-CHANGES (+0/-3) tarfile-LICENSE (+0/-92) testing/__init__.py (+0/-3) testing/run-tests (+1/-1) testing/run-tests-ve (+1/-1) testing/tests/__init__.py (+0/-9) testing/tests/test_parsedurl.py (+10/-1) testing/tests/test_tarfile.py (+8/-300) testing/tests/test_unicode.py (+2/-4) |
To merge this branch: | bzr merge lp:~mterry/duplicity/require-2.6 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
duplicity-team | Pending | ||
Review via email: mp+216210@code.launchpad.net |
Commit message
Description of the change
Require at least Python 2.6.
Our code base already requires 2.6, because 2.6-isms have crept in. Usually because we or a contributor didn't think to test with 2.4. And frankly, I'm not even sure how to test with 2.4 on a modern system [1].
You know I've been pushing for this change for a while, but it seems that at this point, it's just moving from de facto to de jure.
Benefits of this:
- We can start using newer syntax and features
- We can drop a bunch of code (notably our internal copies of urlparse and tarfile)
Most of this branch is just removing code that we kept around only for 2.4. I didn't start using any new 2.6-isms. Those can be separate branches if this is accepted.
[1] https:/
Michael Terry (mterry) wrote : | # |
Preview Diff
1 | === modified file 'README' | |||
2 | --- README 2014-02-21 17:35:24 +0000 | |||
3 | +++ README 2014-04-16 20:51:42 +0000 | |||
4 | @@ -19,7 +19,7 @@ | |||
5 | 19 | 19 | ||
6 | 20 | REQUIREMENTS: | 20 | REQUIREMENTS: |
7 | 21 | 21 | ||
9 | 22 | * Python v2.4 or later | 22 | * Python v2.6 or later |
10 | 23 | * librsync v0.9.6 or later | 23 | * librsync v0.9.6 or later |
11 | 24 | * GnuPG v1.x for encryption | 24 | * GnuPG v1.x for encryption |
12 | 25 | * python-lockfile for concurrency locking | 25 | * python-lockfile for concurrency locking |
13 | @@ -28,7 +28,6 @@ | |||
14 | 28 | * for ftp over SSL -- lftp version 3.7.15 or later | 28 | * for ftp over SSL -- lftp version 3.7.15 or later |
15 | 29 | * Boto 2.0 or later for single-processing S3 or GCS access (default) | 29 | * Boto 2.0 or later for single-processing S3 or GCS access (default) |
16 | 30 | * Boto 2.1.1 or later for multi-processing S3 access | 30 | * Boto 2.1.1 or later for multi-processing S3 access |
17 | 31 | * Python v2.6 or later for multi-processing S3 access | ||
18 | 32 | * Boto 2.7.0 or later for Glacier S3 access | 31 | * Boto 2.7.0 or later for Glacier S3 access |
19 | 33 | 32 | ||
20 | 34 | If you install from the source package, you will also need: | 33 | If you install from the source package, you will also need: |
21 | 35 | 34 | ||
22 | === modified file 'bin/duplicity.1' | |||
23 | --- bin/duplicity.1 2014-03-09 20:37:24 +0000 | |||
24 | +++ bin/duplicity.1 2014-04-16 20:51:42 +0000 | |||
25 | @@ -51,7 +51,7 @@ | |||
26 | 51 | .SH REQUIREMENTS | 51 | .SH REQUIREMENTS |
27 | 52 | Duplicity requires a POSIX-like operating system with a | 52 | Duplicity requires a POSIX-like operating system with a |
28 | 53 | .B python | 53 | .B python |
30 | 54 | interpreter version 2.4+ installed. | 54 | interpreter version 2.6+ installed. |
31 | 55 | It is best used under GNU/Linux. | 55 | It is best used under GNU/Linux. |
32 | 56 | 56 | ||
33 | 57 | Some backends also require additional components (probably available as packages for your specific platform): | 57 | Some backends also require additional components (probably available as packages for your specific platform): |
34 | 58 | 58 | ||
35 | === modified file 'dist/duplicity.spec.template' | |||
36 | --- dist/duplicity.spec.template 2011-11-25 17:47:57 +0000 | |||
37 | +++ dist/duplicity.spec.template 2014-04-16 20:51:42 +0000 | |||
38 | @@ -10,8 +10,8 @@ | |||
39 | 10 | License: GPL | 10 | License: GPL |
40 | 11 | Group: Applications/Archiving | 11 | Group: Applications/Archiving |
41 | 12 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) | 12 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) |
44 | 13 | requires: librsync >= 0.9.6, %{PYTHON_NAME} >= 2.4, gnupg >= 1.0.6 | 13 | requires: librsync >= 0.9.6, %{PYTHON_NAME} >= 2.6, gnupg >= 1.0.6 |
45 | 14 | BuildPrereq: %{PYTHON_NAME}-devel >= 2.4, librsync-devel >= 0.9.6 | 14 | BuildPrereq: %{PYTHON_NAME}-devel >= 2.6, librsync-devel >= 0.9.6 |
46 | 15 | 15 | ||
47 | 16 | %description | 16 | %description |
48 | 17 | Duplicity incrementally backs up files and directory by encrypting | 17 | Duplicity incrementally backs up files and directory by encrypting |
49 | 18 | 18 | ||
50 | === modified file 'duplicity/__init__.py' | |||
51 | --- duplicity/__init__.py 2013-12-27 06:39:00 +0000 | |||
52 | +++ duplicity/__init__.py 2014-04-16 20:51:42 +0000 | |||
53 | @@ -19,12 +19,5 @@ | |||
54 | 19 | # along with duplicity; if not, write to the Free Software Foundation, | 19 | # along with duplicity; if not, write to the Free Software Foundation, |
55 | 20 | # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 20 | # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
56 | 21 | 21 | ||
57 | 22 | import __builtin__ | ||
58 | 23 | import gettext | 22 | import gettext |
66 | 24 | 23 | gettext.install('duplicity', unicode=True, names=['ngettext']) | |
60 | 25 | t = gettext.translation('duplicity', fallback=True) | ||
61 | 26 | t.install(unicode=True) | ||
62 | 27 | |||
63 | 28 | # Once we can depend on python >=2.5, we can just use names='ngettext' above. | ||
64 | 29 | # But for now, do the install manually. | ||
65 | 30 | __builtin__.__dict__['ngettext'] = t.ungettext | ||
67 | 31 | 24 | ||
68 | === modified file 'duplicity/_librsyncmodule.c' | |||
69 | --- duplicity/_librsyncmodule.c 2013-01-17 16:17:42 +0000 | |||
70 | +++ duplicity/_librsyncmodule.c 2014-04-16 20:51:42 +0000 | |||
71 | @@ -26,15 +26,6 @@ | |||
72 | 26 | #include <librsync.h> | 26 | #include <librsync.h> |
73 | 27 | #define RS_JOB_BLOCKSIZE 65536 | 27 | #define RS_JOB_BLOCKSIZE 65536 |
74 | 28 | 28 | ||
75 | 29 | /* Support Python 2.4 and 2.5 */ | ||
76 | 30 | #ifndef PyVarObject_HEAD_INIT | ||
77 | 31 | #define PyVarObject_HEAD_INIT(type, size) \ | ||
78 | 32 | PyObject_HEAD_INIT(type) size, | ||
79 | 33 | #endif | ||
80 | 34 | #ifndef Py_TYPE | ||
81 | 35 | #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) | ||
82 | 36 | #endif | ||
83 | 37 | |||
84 | 38 | static PyObject *librsyncError; | 29 | static PyObject *librsyncError; |
85 | 39 | 30 | ||
86 | 40 | /* Sets python error string from result */ | 31 | /* Sets python error string from result */ |
87 | 41 | 32 | ||
88 | === modified file 'duplicity/backend.py' | |||
89 | --- duplicity/backend.py 2014-02-07 19:04:51 +0000 | |||
90 | +++ duplicity/backend.py 2014-04-16 20:51:42 +0000 | |||
91 | @@ -32,13 +32,12 @@ | |||
92 | 32 | import getpass | 32 | import getpass |
93 | 33 | import gettext | 33 | import gettext |
94 | 34 | import urllib | 34 | import urllib |
95 | 35 | import urlparse | ||
96 | 35 | 36 | ||
97 | 36 | from duplicity import dup_temp | 37 | from duplicity import dup_temp |
98 | 37 | from duplicity import dup_threading | ||
99 | 38 | from duplicity import file_naming | 38 | from duplicity import file_naming |
100 | 39 | from duplicity import globals | 39 | from duplicity import globals |
101 | 40 | from duplicity import log | 40 | from duplicity import log |
102 | 41 | from duplicity import urlparse_2_5 as urlparser | ||
103 | 42 | from duplicity import progress | 41 | from duplicity import progress |
104 | 43 | 42 | ||
105 | 44 | from duplicity.util import exception_traceback | 43 | from duplicity.util import exception_traceback |
106 | @@ -58,6 +57,28 @@ | |||
107 | 58 | _forced_backend = None | 57 | _forced_backend = None |
108 | 59 | _backends = {} | 58 | _backends = {} |
109 | 60 | 59 | ||
110 | 60 | # These URL schemes have a backend with a notion of an RFC "network location". | ||
111 | 61 | # The 'file' and 's3+http' schemes should not be in this list. | ||
112 | 62 | # 'http' and 'https' are not actually used for duplicity backend urls, but are needed | ||
113 | 63 | # in order to properly support urls returned from some webdav servers. adding them here | ||
114 | 64 | # is a hack. we should instead not stomp on the url parsing module to begin with. | ||
115 | 65 | # | ||
116 | 66 | # This looks similar to urlparse's 'uses_netloc' list, but urlparse doesn't use | ||
117 | 67 | # that list for parsing, only creating urls. And doesn't include our custom | ||
118 | 68 | # schemes anyway. So we keep our own here for our own use. | ||
119 | 69 | uses_netloc = ['ftp', | ||
120 | 70 | 'ftps', | ||
121 | 71 | 'hsi', | ||
122 | 72 | 'rsync', | ||
123 | 73 | 's3', | ||
124 | 74 | 'u1', | ||
125 | 75 | 'scp', 'ssh', 'sftp', | ||
126 | 76 | 'webdav', 'webdavs', | ||
127 | 77 | 'gdocs', | ||
128 | 78 | 'http', 'https', | ||
129 | 79 | 'imap', 'imaps', | ||
130 | 80 | 'mega'] | ||
131 | 81 | |||
132 | 61 | 82 | ||
133 | 62 | def import_backends(): | 83 | def import_backends(): |
134 | 63 | """ | 84 | """ |
135 | @@ -165,47 +186,6 @@ | |||
136 | 165 | raise BackendException(_("Could not initialize backend: %s") % str(sys.exc_info()[1])) | 186 | raise BackendException(_("Could not initialize backend: %s") % str(sys.exc_info()[1])) |
137 | 166 | 187 | ||
138 | 167 | 188 | ||
139 | 168 | _urlparser_initialized = False | ||
140 | 169 | _urlparser_initialized_lock = dup_threading.threading_module().Lock() | ||
141 | 170 | |||
142 | 171 | def _ensure_urlparser_initialized(): | ||
143 | 172 | """ | ||
144 | 173 | Ensure that the appropriate clobbering of variables in the | ||
145 | 174 | urlparser module has been done. In the future, the need for this | ||
146 | 175 | clobbering to begin with should preferably be eliminated. | ||
147 | 176 | """ | ||
148 | 177 | def init(): | ||
149 | 178 | global _urlparser_initialized | ||
150 | 179 | |||
151 | 180 | if not _urlparser_initialized: | ||
152 | 181 | # These URL schemes have a backend with a notion of an RFC "network location". | ||
153 | 182 | # The 'file' and 's3+http' schemes should not be in this list. | ||
154 | 183 | # 'http' and 'https' are not actually used for duplicity backend urls, but are needed | ||
155 | 184 | # in order to properly support urls returned from some webdav servers. adding them here | ||
156 | 185 | # is a hack. we should instead not stomp on the url parsing module to begin with. | ||
157 | 186 | # | ||
158 | 187 | # todo: eliminate the need for backend specific hacking here completely. | ||
159 | 188 | urlparser.uses_netloc = ['ftp', | ||
160 | 189 | 'ftps', | ||
161 | 190 | 'hsi', | ||
162 | 191 | 'rsync', | ||
163 | 192 | 's3', | ||
164 | 193 | 'u1', | ||
165 | 194 | 'scp', 'ssh', 'sftp', | ||
166 | 195 | 'webdav', 'webdavs', | ||
167 | 196 | 'gdocs', | ||
168 | 197 | 'http', 'https', | ||
169 | 198 | 'imap', 'imaps', | ||
170 | 199 | 'mega'] | ||
171 | 200 | |||
172 | 201 | # Do not transform or otherwise parse the URL path component. | ||
173 | 202 | urlparser.uses_query = [] | ||
174 | 203 | urlparser.uses_fragm = [] | ||
175 | 204 | |||
176 | 205 | _urlparser_initialized = True | ||
177 | 206 | |||
178 | 207 | dup_threading.with_lock(_urlparser_initialized_lock, init) | ||
179 | 208 | |||
180 | 209 | class ParsedUrl: | 189 | class ParsedUrl: |
181 | 210 | """ | 190 | """ |
182 | 211 | Parse the given URL as a duplicity backend URL. | 191 | Parse the given URL as a duplicity backend URL. |
183 | @@ -219,7 +199,6 @@ | |||
184 | 219 | """ | 199 | """ |
185 | 220 | def __init__(self, url_string): | 200 | def __init__(self, url_string): |
186 | 221 | self.url_string = url_string | 201 | self.url_string = url_string |
187 | 222 | _ensure_urlparser_initialized() | ||
188 | 223 | 202 | ||
189 | 224 | # While useful in some cases, the fact is that the urlparser makes | 203 | # While useful in some cases, the fact is that the urlparser makes |
190 | 225 | # all the properties in the URL deferred or lazy. This means that | 204 | # all the properties in the URL deferred or lazy. This means that |
191 | @@ -227,7 +206,7 @@ | |||
192 | 227 | # problems here, so they will be caught early. | 206 | # problems here, so they will be caught early. |
193 | 228 | 207 | ||
194 | 229 | try: | 208 | try: |
196 | 230 | pu = urlparser.urlparse(url_string) | 209 | pu = urlparse.urlparse(url_string) |
197 | 231 | except Exception: | 210 | except Exception: |
198 | 232 | raise InvalidBackendURL("Syntax error in: %s" % url_string) | 211 | raise InvalidBackendURL("Syntax error in: %s" % url_string) |
199 | 233 | 212 | ||
200 | @@ -273,26 +252,37 @@ | |||
201 | 273 | self.port = None | 252 | self.port = None |
202 | 274 | try: | 253 | try: |
203 | 275 | self.port = pu.port | 254 | self.port = pu.port |
205 | 276 | except Exception: | 255 | except Exception: # not raised in python2.7+, just returns None |
206 | 277 | # old style rsync://host::[/]dest, are still valid, though they contain no port | 256 | # old style rsync://host::[/]dest, are still valid, though they contain no port |
207 | 278 | if not ( self.scheme in ['rsync'] and re.search('::[^:]*$', self.url_string)): | 257 | if not ( self.scheme in ['rsync'] and re.search('::[^:]*$', self.url_string)): |
208 | 279 | raise InvalidBackendURL("Syntax error (port) in: %s A%s B%s C%s" % (url_string, (self.scheme in ['rsync']), re.search('::[^:]+$', self.netloc), self.netloc ) ) | 258 | raise InvalidBackendURL("Syntax error (port) in: %s A%s B%s C%s" % (url_string, (self.scheme in ['rsync']), re.search('::[^:]+$', self.netloc), self.netloc ) ) |
209 | 280 | 259 | ||
210 | 260 | # Our URL system uses two slashes more than urlparse's does when using | ||
211 | 261 | # non-netloc URLs. And we want to make sure that if urlparse assuming | ||
212 | 262 | # a netloc where we don't want one, that we correct it. | ||
213 | 263 | if self.scheme not in uses_netloc: | ||
214 | 264 | if self.netloc: | ||
215 | 265 | self.path = '//' + self.netloc + self.path | ||
216 | 266 | self.netloc = '' | ||
217 | 267 | self.hostname = None | ||
218 | 268 | elif self.path.startswith('/'): | ||
219 | 269 | self.path = '//' + self.path | ||
220 | 270 | |||
221 | 281 | # This happens for implicit local paths. | 271 | # This happens for implicit local paths. |
223 | 282 | if not pu.scheme: | 272 | if not self.scheme: |
224 | 283 | return | 273 | return |
225 | 284 | 274 | ||
226 | 285 | # Our backends do not handle implicit hosts. | 275 | # Our backends do not handle implicit hosts. |
228 | 286 | if pu.scheme in urlparser.uses_netloc and not pu.hostname: | 276 | if self.scheme in uses_netloc and not self.hostname: |
229 | 287 | raise InvalidBackendURL("Missing hostname in a backend URL which " | 277 | raise InvalidBackendURL("Missing hostname in a backend URL which " |
230 | 288 | "requires an explicit hostname: %s" | 278 | "requires an explicit hostname: %s" |
231 | 289 | "" % (url_string)) | 279 | "" % (url_string)) |
232 | 290 | 280 | ||
233 | 291 | # Our backends do not handle implicit relative paths. | 281 | # Our backends do not handle implicit relative paths. |
235 | 292 | if pu.scheme not in urlparser.uses_netloc and not pu.path.startswith('//'): | 282 | if self.scheme not in uses_netloc and not self.path.startswith('//'): |
236 | 293 | raise InvalidBackendURL("missing // - relative paths not supported " | 283 | raise InvalidBackendURL("missing // - relative paths not supported " |
237 | 294 | "for scheme %s: %s" | 284 | "for scheme %s: %s" |
239 | 295 | "" % (pu.scheme, url_string)) | 285 | "" % (self.scheme, url_string)) |
240 | 296 | 286 | ||
241 | 297 | def geturl(self): | 287 | def geturl(self): |
242 | 298 | return self.url_string | 288 | return self.url_string |
243 | 299 | 289 | ||
244 | === modified file 'duplicity/backends/botobackend.py' | |||
245 | --- duplicity/backends/botobackend.py 2014-02-21 17:14:37 +0000 | |||
246 | +++ duplicity/backends/botobackend.py 2014-04-16 20:51:42 +0000 | |||
247 | @@ -22,14 +22,10 @@ | |||
248 | 22 | 22 | ||
249 | 23 | import duplicity.backend | 23 | import duplicity.backend |
250 | 24 | from duplicity import globals | 24 | from duplicity import globals |
251 | 25 | import sys | ||
252 | 26 | from _boto_multi import BotoBackend as BotoMultiUploadBackend | 25 | from _boto_multi import BotoBackend as BotoMultiUploadBackend |
253 | 27 | from _boto_single import BotoBackend as BotoSingleUploadBackend | 26 | from _boto_single import BotoBackend as BotoSingleUploadBackend |
254 | 28 | 27 | ||
255 | 29 | if globals.s3_use_multiprocessing: | 28 | if globals.s3_use_multiprocessing: |
256 | 30 | if sys.version_info[:2] < (2, 6): | ||
257 | 31 | print "Sorry, S3 multiprocessing requires version 2.6 or later of python" | ||
258 | 32 | sys.exit(1) | ||
259 | 33 | duplicity.backend.register_backend("gs", BotoMultiUploadBackend) | 29 | duplicity.backend.register_backend("gs", BotoMultiUploadBackend) |
260 | 34 | duplicity.backend.register_backend("s3", BotoMultiUploadBackend) | 30 | duplicity.backend.register_backend("s3", BotoMultiUploadBackend) |
261 | 35 | duplicity.backend.register_backend("s3+http", BotoMultiUploadBackend) | 31 | duplicity.backend.register_backend("s3+http", BotoMultiUploadBackend) |
262 | 36 | 32 | ||
263 | === modified file 'duplicity/backends/webdavbackend.py' | |||
264 | --- duplicity/backends/webdavbackend.py 2013-12-30 16:01:49 +0000 | |||
265 | +++ duplicity/backends/webdavbackend.py 2014-04-16 20:51:42 +0000 | |||
266 | @@ -26,13 +26,13 @@ | |||
267 | 26 | import re | 26 | import re |
268 | 27 | import urllib | 27 | import urllib |
269 | 28 | import urllib2 | 28 | import urllib2 |
270 | 29 | import urlparse | ||
271 | 29 | import xml.dom.minidom | 30 | import xml.dom.minidom |
272 | 30 | 31 | ||
273 | 31 | import duplicity.backend | 32 | import duplicity.backend |
274 | 32 | from duplicity import globals | 33 | from duplicity import globals |
275 | 33 | from duplicity import log | 34 | from duplicity import log |
276 | 34 | from duplicity.errors import * #@UnusedWildImport | 35 | from duplicity.errors import * #@UnusedWildImport |
277 | 35 | from duplicity import urlparse_2_5 as urlparser | ||
278 | 36 | from duplicity.backend import retry_fatal | 36 | from duplicity.backend import retry_fatal |
279 | 37 | 37 | ||
280 | 38 | class CustomMethodRequest(urllib2.Request): | 38 | class CustomMethodRequest(urllib2.Request): |
281 | @@ -332,7 +332,7 @@ | |||
282 | 332 | @return: A matching filename, or None if the href did not match. | 332 | @return: A matching filename, or None if the href did not match. |
283 | 333 | """ | 333 | """ |
284 | 334 | raw_filename = self._getText(href.childNodes).strip() | 334 | raw_filename = self._getText(href.childNodes).strip() |
286 | 335 | parsed_url = urlparser.urlparse(urllib.unquote(raw_filename)) | 335 | parsed_url = urlparse.urlparse(urllib.unquote(raw_filename)) |
287 | 336 | filename = parsed_url.path | 336 | filename = parsed_url.path |
288 | 337 | log.Debug("webdav path decoding and translation: " | 337 | log.Debug("webdav path decoding and translation: " |
289 | 338 | "%s -> %s" % (raw_filename, filename)) | 338 | "%s -> %s" % (raw_filename, filename)) |
290 | 339 | 339 | ||
291 | === modified file 'duplicity/commandline.py' | |||
292 | --- duplicity/commandline.py 2014-03-09 20:37:24 +0000 | |||
293 | +++ duplicity/commandline.py 2014-04-16 20:51:42 +0000 | |||
294 | @@ -507,9 +507,7 @@ | |||
295 | 507 | parser.add_option("--s3_multipart_max_timeout", type="int", metavar=_("number")) | 507 | parser.add_option("--s3_multipart_max_timeout", type="int", metavar=_("number")) |
296 | 508 | 508 | ||
297 | 509 | # Option to allow the s3/boto backend use the multiprocessing version. | 509 | # Option to allow the s3/boto backend use the multiprocessing version. |
301 | 510 | # By default it is off since it does not work for Python 2.4 or 2.5. | 510 | parser.add_option("--s3-use-multiprocessing", action = "store_true") |
299 | 511 | if sys.version_info[:2] >= (2, 6): | ||
300 | 512 | parser.add_option("--s3-use-multiprocessing", action = "store_true") | ||
302 | 513 | 511 | ||
303 | 514 | # scp command to use (ssh pexpect backend) | 512 | # scp command to use (ssh pexpect backend) |
304 | 515 | parser.add_option("--scp-command", metavar = _("command")) | 513 | parser.add_option("--scp-command", metavar = _("command")) |
305 | 516 | 514 | ||
306 | === modified file 'duplicity/log.py' | |||
307 | --- duplicity/log.py 2013-12-27 06:39:00 +0000 | |||
308 | +++ duplicity/log.py 2014-04-16 20:51:42 +0000 | |||
309 | @@ -49,7 +49,6 @@ | |||
310 | 49 | return DupToLoggerLevel(verb) | 49 | return DupToLoggerLevel(verb) |
311 | 50 | 50 | ||
312 | 51 | def LevelName(level): | 51 | def LevelName(level): |
313 | 52 | level = LoggerToDupLevel(level) | ||
314 | 53 | if level >= 9: return "DEBUG" | 52 | if level >= 9: return "DEBUG" |
315 | 54 | elif level >= 5: return "INFO" | 53 | elif level >= 5: return "INFO" |
316 | 55 | elif level >= 3: return "NOTICE" | 54 | elif level >= 3: return "NOTICE" |
317 | @@ -59,12 +58,10 @@ | |||
318 | 59 | def Log(s, verb_level, code=1, extra=None, force_print=False): | 58 | def Log(s, verb_level, code=1, extra=None, force_print=False): |
319 | 60 | """Write s to stderr if verbosity level low enough""" | 59 | """Write s to stderr if verbosity level low enough""" |
320 | 61 | global _logger | 60 | global _logger |
321 | 62 | # controlLine is a terrible hack until duplicity depends on Python 2.5 | ||
322 | 63 | # and its logging 'extra' keyword that allows a custom record dictionary. | ||
323 | 64 | if extra: | 61 | if extra: |
325 | 65 | _logger.controlLine = '%d %s' % (code, extra) | 62 | controlLine = '%d %s' % (code, extra) |
326 | 66 | else: | 63 | else: |
328 | 67 | _logger.controlLine = '%d' % (code) | 64 | controlLine = '%d' % (code) |
329 | 68 | if not s: | 65 | if not s: |
330 | 69 | s = '' # If None is passed, standard logging would render it as 'None' | 66 | s = '' # If None is passed, standard logging would render it as 'None' |
331 | 70 | 67 | ||
332 | @@ -79,8 +76,9 @@ | |||
333 | 79 | if not isinstance(s, unicode): | 76 | if not isinstance(s, unicode): |
334 | 80 | s = s.decode("utf8", "replace") | 77 | s = s.decode("utf8", "replace") |
335 | 81 | 78 | ||
338 | 82 | _logger.log(DupToLoggerLevel(verb_level), s) | 79 | _logger.log(DupToLoggerLevel(verb_level), s, |
339 | 83 | _logger.controlLine = None | 80 | extra={'levelName': LevelName(verb_level), |
340 | 81 | 'controlLine': controlLine}) | ||
341 | 84 | 82 | ||
342 | 85 | if force_print: | 83 | if force_print: |
343 | 86 | _logger.setLevel(initial_level) | 84 | _logger.setLevel(initial_level) |
344 | @@ -305,22 +303,6 @@ | |||
345 | 305 | shutdown() | 303 | shutdown() |
346 | 306 | sys.exit(code) | 304 | sys.exit(code) |
347 | 307 | 305 | ||
348 | 308 | class DupLogRecord(logging.LogRecord): | ||
349 | 309 | """Custom log record that holds a message code""" | ||
350 | 310 | def __init__(self, controlLine, *args, **kwargs): | ||
351 | 311 | global _logger | ||
352 | 312 | logging.LogRecord.__init__(self, *args, **kwargs) | ||
353 | 313 | self.controlLine = controlLine | ||
354 | 314 | self.levelName = LevelName(self.levelno) | ||
355 | 315 | |||
356 | 316 | class DupLogger(logging.Logger): | ||
357 | 317 | """Custom logger that creates special code-bearing records""" | ||
358 | 318 | # controlLine is a terrible hack until duplicity depends on Python 2.5 | ||
359 | 319 | # and its logging 'extra' keyword that allows a custom record dictionary. | ||
360 | 320 | controlLine = None | ||
361 | 321 | def makeRecord(self, name, lvl, fn, lno, msg, args, exc_info, *argv, **kwargs): | ||
362 | 322 | return DupLogRecord(self.controlLine, name, lvl, fn, lno, msg, args, exc_info) | ||
363 | 323 | |||
364 | 324 | class OutFilter(logging.Filter): | 306 | class OutFilter(logging.Filter): |
365 | 325 | """Filter that only allows warning or less important messages""" | 307 | """Filter that only allows warning or less important messages""" |
366 | 326 | def filter(self, record): | 308 | def filter(self, record): |
367 | @@ -337,7 +319,6 @@ | |||
368 | 337 | if _logger: | 319 | if _logger: |
369 | 338 | return | 320 | return |
370 | 339 | 321 | ||
371 | 340 | logging.setLoggerClass(DupLogger) | ||
372 | 341 | _logger = logging.getLogger("duplicity") | 322 | _logger = logging.getLogger("duplicity") |
373 | 342 | 323 | ||
374 | 343 | # Default verbosity allows notices and above | 324 | # Default verbosity allows notices and above |
375 | 344 | 325 | ||
376 | === modified file 'duplicity/tarfile.py' | |||
377 | --- duplicity/tarfile.py 2013-10-05 15:11:55 +0000 | |||
378 | +++ duplicity/tarfile.py 2014-04-16 20:51:42 +0000 | |||
379 | @@ -1,2594 +1,35 @@ | |||
435 | 1 | #! /usr/bin/python2.7 | 1 | # -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- |
436 | 2 | # -*- coding: iso-8859-1 -*- | 2 | # |
437 | 3 | #------------------------------------------------------------------- | 3 | # Copyright 2013 Michael Terry <mike@mterry.name> |
438 | 4 | # tarfile.py | 4 | # |
439 | 5 | #------------------------------------------------------------------- | 5 | # This file is part of duplicity. |
440 | 6 | # Copyright (C) 2002 Lars Gustäbel <lars@gustaebel.de> | 6 | # |
441 | 7 | # All rights reserved. | 7 | # Duplicity is free software; you can redistribute it and/or modify it |
442 | 8 | # | 8 | # under the terms of the GNU General Public License as published by the |
443 | 9 | # Permission is hereby granted, free of charge, to any person | 9 | # Free Software Foundation; either version 2 of the License, or (at your |
444 | 10 | # obtaining a copy of this software and associated documentation | 10 | # option) any later version. |
445 | 11 | # files (the "Software"), to deal in the Software without | 11 | # |
446 | 12 | # restriction, including without limitation the rights to use, | 12 | # Duplicity is distributed in the hope that it will be useful, but |
447 | 13 | # copy, modify, merge, publish, distribute, sublicense, and/or sell | 13 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
448 | 14 | # copies of the Software, and to permit persons to whom the | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
449 | 15 | # Software is furnished to do so, subject to the following | 15 | # General Public License for more details. |
450 | 16 | # conditions: | 16 | # |
451 | 17 | # | 17 | # You should have received a copy of the GNU General Public License |
452 | 18 | # The above copyright notice and this permission notice shall be | 18 | # along with duplicity; if not, write to the Free Software Foundation, |
453 | 19 | # included in all copies or substantial portions of the Software. | 19 | # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
454 | 20 | # | 20 | |
455 | 21 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | 21 | """Like system tarfile but with caching.""" |
456 | 22 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | 22 | |
457 | 23 | # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | 23 | from __future__ import absolute_import |
458 | 24 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | 24 | |
459 | 25 | # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | 25 | import tarfile |
460 | 26 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | 26 | |
461 | 27 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | 27 | # Grab all symbols in tarfile, to try to reproduce its API exactly. |
462 | 28 | # OTHER DEALINGS IN THE SOFTWARE. | 28 | # from <> import * wouldn't get everything we want, since tarfile defines |
463 | 29 | # | 29 | # __all__. So we do it ourselves. |
464 | 30 | """Read from and write to tar format archives. | 30 | for sym in dir(tarfile): |
465 | 31 | """ | 31 | globals()[sym] = getattr(tarfile, sym) |
466 | 32 | 32 | ||
467 | 33 | __version__ = "$Revision: 85213 $" | 33 | # Now make sure that we cache the grp/pwd ops |
413 | 34 | # $Source$ | ||
414 | 35 | |||
415 | 36 | version = "0.9.0" | ||
416 | 37 | __author__ = "Lars Gustäbel (lars@gustaebel.de)" | ||
417 | 38 | __date__ = "$Date: 2010-10-04 10:37:53 -0500 (Mon, 04 Oct 2010) $" | ||
418 | 39 | __cvsid__ = "$Id: tarfile.py 85213 2010-10-04 15:37:53Z lars.gustaebel $" | ||
419 | 40 | __credits__ = "Gustavo Niemeyer, Niels Gustäbel, Richard Townsend." | ||
420 | 41 | |||
421 | 42 | #--------- | ||
422 | 43 | # Imports | ||
423 | 44 | #--------- | ||
424 | 45 | import sys | ||
425 | 46 | import os | ||
426 | 47 | import shutil | ||
427 | 48 | import stat | ||
428 | 49 | import errno | ||
429 | 50 | import time | ||
430 | 51 | import struct | ||
431 | 52 | import copy | ||
432 | 53 | import re | ||
433 | 54 | import operator | ||
434 | 55 | |||
468 | 56 | from duplicity import cached_ops | 34 | from duplicity import cached_ops |
469 | 57 | grp = pwd = cached_ops | 35 | grp = pwd = cached_ops |
470 | 58 | |||
471 | 59 | # from tarfile import * | ||
472 | 60 | __all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError"] | ||
473 | 61 | |||
474 | 62 | #--------------------------------------------------------- | ||
475 | 63 | # tar constants | ||
476 | 64 | #--------------------------------------------------------- | ||
477 | 65 | NUL = "\0" # the null character | ||
478 | 66 | BLOCKSIZE = 512 # length of processing blocks | ||
479 | 67 | RECORDSIZE = BLOCKSIZE * 20 # length of records | ||
480 | 68 | GNU_MAGIC = "ustar \0" # magic gnu tar string | ||
481 | 69 | POSIX_MAGIC = "ustar\x0000" # magic posix tar string | ||
482 | 70 | |||
483 | 71 | LENGTH_NAME = 100 # maximum length of a filename | ||
484 | 72 | LENGTH_LINK = 100 # maximum length of a linkname | ||
485 | 73 | LENGTH_PREFIX = 155 # maximum length of the prefix field | ||
486 | 74 | |||
487 | 75 | REGTYPE = "0" # regular file | ||
488 | 76 | AREGTYPE = "\0" # regular file | ||
489 | 77 | LNKTYPE = "1" # link (inside tarfile) | ||
490 | 78 | SYMTYPE = "2" # symbolic link | ||
491 | 79 | CHRTYPE = "3" # character special device | ||
492 | 80 | BLKTYPE = "4" # block special device | ||
493 | 81 | DIRTYPE = "5" # directory | ||
494 | 82 | FIFOTYPE = "6" # fifo special device | ||
495 | 83 | CONTTYPE = "7" # contiguous file | ||
496 | 84 | |||
497 | 85 | GNUTYPE_LONGNAME = "L" # GNU tar longname | ||
498 | 86 | GNUTYPE_LONGLINK = "K" # GNU tar longlink | ||
499 | 87 | GNUTYPE_SPARSE = "S" # GNU tar sparse file | ||
500 | 88 | |||
501 | 89 | XHDTYPE = "x" # POSIX.1-2001 extended header | ||
502 | 90 | XGLTYPE = "g" # POSIX.1-2001 global header | ||
503 | 91 | SOLARIS_XHDTYPE = "X" # Solaris extended header | ||
504 | 92 | |||
505 | 93 | USTAR_FORMAT = 0 # POSIX.1-1988 (ustar) format | ||
506 | 94 | GNU_FORMAT = 1 # GNU tar format | ||
507 | 95 | PAX_FORMAT = 2 # POSIX.1-2001 (pax) format | ||
508 | 96 | DEFAULT_FORMAT = GNU_FORMAT | ||
509 | 97 | |||
510 | 98 | #--------------------------------------------------------- | ||
511 | 99 | # tarfile constants | ||
512 | 100 | #--------------------------------------------------------- | ||
513 | 101 | # File types that tarfile supports: | ||
514 | 102 | SUPPORTED_TYPES = (REGTYPE, AREGTYPE, LNKTYPE, | ||
515 | 103 | SYMTYPE, DIRTYPE, FIFOTYPE, | ||
516 | 104 | CONTTYPE, CHRTYPE, BLKTYPE, | ||
517 | 105 | GNUTYPE_LONGNAME, GNUTYPE_LONGLINK, | ||
518 | 106 | GNUTYPE_SPARSE) | ||
519 | 107 | |||
520 | 108 | # File types that will be treated as a regular file. | ||
521 | 109 | REGULAR_TYPES = (REGTYPE, AREGTYPE, | ||
522 | 110 | CONTTYPE, GNUTYPE_SPARSE) | ||
523 | 111 | |||
524 | 112 | # File types that are part of the GNU tar format. | ||
525 | 113 | GNU_TYPES = (GNUTYPE_LONGNAME, GNUTYPE_LONGLINK, | ||
526 | 114 | GNUTYPE_SPARSE) | ||
527 | 115 | |||
528 | 116 | # Fields from a pax header that override a TarInfo attribute. | ||
529 | 117 | PAX_FIELDS = ("path", "linkpath", "size", "mtime", | ||
530 | 118 | "uid", "gid", "uname", "gname") | ||
531 | 119 | |||
532 | 120 | # Fields in a pax header that are numbers, all other fields | ||
533 | 121 | # are treated as strings. | ||
534 | 122 | PAX_NUMBER_FIELDS = { | ||
535 | 123 | "atime": float, | ||
536 | 124 | "ctime": float, | ||
537 | 125 | "mtime": float, | ||
538 | 126 | "uid": int, | ||
539 | 127 | "gid": int, | ||
540 | 128 | "size": int | ||
541 | 129 | } | ||
542 | 130 | |||
543 | 131 | #--------------------------------------------------------- | ||
544 | 132 | # Bits used in the mode field, values in octal. | ||
545 | 133 | #--------------------------------------------------------- | ||
546 | 134 | S_IFLNK = 0120000 # symbolic link | ||
547 | 135 | S_IFREG = 0100000 # regular file | ||
548 | 136 | S_IFBLK = 0060000 # block device | ||
549 | 137 | S_IFDIR = 0040000 # directory | ||
550 | 138 | S_IFCHR = 0020000 # character device | ||
551 | 139 | S_IFIFO = 0010000 # fifo | ||
552 | 140 | |||
553 | 141 | TSUID = 04000 # set UID on execution | ||
554 | 142 | TSGID = 02000 # set GID on execution | ||
555 | 143 | TSVTX = 01000 # reserved | ||
556 | 144 | |||
557 | 145 | TUREAD = 0400 # read by owner | ||
558 | 146 | TUWRITE = 0200 # write by owner | ||
559 | 147 | TUEXEC = 0100 # execute/search by owner | ||
560 | 148 | TGREAD = 0040 # read by group | ||
561 | 149 | TGWRITE = 0020 # write by group | ||
562 | 150 | TGEXEC = 0010 # execute/search by group | ||
563 | 151 | TOREAD = 0004 # read by other | ||
564 | 152 | TOWRITE = 0002 # write by other | ||
565 | 153 | TOEXEC = 0001 # execute/search by other | ||
566 | 154 | |||
567 | 155 | #--------------------------------------------------------- | ||
568 | 156 | # initialization | ||
569 | 157 | #--------------------------------------------------------- | ||
570 | 158 | ENCODING = sys.getfilesystemencoding() | ||
571 | 159 | if ENCODING is None: | ||
572 | 160 | ENCODING = sys.getdefaultencoding() | ||
573 | 161 | |||
574 | 162 | #--------------------------------------------------------- | ||
575 | 163 | # Some useful functions | ||
576 | 164 | #--------------------------------------------------------- | ||
577 | 165 | |||
578 | 166 | def stn(s, length): | ||
579 | 167 | """Convert a python string to a null-terminated string buffer. | ||
580 | 168 | """ | ||
581 | 169 | return s[:length] + (length - len(s)) * NUL | ||
582 | 170 | |||
583 | 171 | def nts(s): | ||
584 | 172 | """Convert a null-terminated string field to a python string. | ||
585 | 173 | """ | ||
586 | 174 | # Use the string up to the first null char. | ||
587 | 175 | p = s.find("\0") | ||
588 | 176 | if p == -1: | ||
589 | 177 | return s | ||
590 | 178 | return s[:p] | ||
591 | 179 | |||
592 | 180 | def nti(s): | ||
593 | 181 | """Convert a number field to a python number. | ||
594 | 182 | """ | ||
595 | 183 | # There are two possible encodings for a number field, see | ||
596 | 184 | # itn() below. | ||
597 | 185 | if s[0] != chr(0200): | ||
598 | 186 | try: | ||
599 | 187 | n = int(nts(s) or "0", 8) | ||
600 | 188 | except ValueError: | ||
601 | 189 | raise InvalidHeaderError("invalid header") | ||
602 | 190 | else: | ||
603 | 191 | n = 0L | ||
604 | 192 | for i in xrange(len(s) - 1): | ||
605 | 193 | n <<= 8 | ||
606 | 194 | n += ord(s[i + 1]) | ||
607 | 195 | return n | ||
608 | 196 | |||
609 | 197 | def itn(n, digits=8, format=DEFAULT_FORMAT): | ||
610 | 198 | """Convert a python number to a number field. | ||
611 | 199 | """ | ||
612 | 200 | # POSIX 1003.1-1988 requires numbers to be encoded as a string of | ||
613 | 201 | # octal digits followed by a null-byte, this allows values up to | ||
614 | 202 | # (8**(digits-1))-1. GNU tar allows storing numbers greater than | ||
615 | 203 | # that if necessary. A leading 0200 byte indicates this particular | ||
616 | 204 | # encoding, the following digits-1 bytes are a big-endian | ||
617 | 205 | # representation. This allows values up to (256**(digits-1))-1. | ||
618 | 206 | if 0 <= n < 8 ** (digits - 1): | ||
619 | 207 | s = "%0*o" % (digits - 1, n) + NUL | ||
620 | 208 | else: | ||
621 | 209 | if format != GNU_FORMAT or n >= 256 ** (digits - 1): | ||
622 | 210 | raise ValueError("overflow in number field") | ||
623 | 211 | |||
624 | 212 | if n < 0: | ||
625 | 213 | # XXX We mimic GNU tar's behaviour with negative numbers, | ||
626 | 214 | # this could raise OverflowError. | ||
627 | 215 | n = struct.unpack("L", struct.pack("l", n))[0] | ||
628 | 216 | |||
629 | 217 | s = "" | ||
630 | 218 | for i in xrange(digits - 1): | ||
631 | 219 | s = chr(n & 0377) + s | ||
632 | 220 | n >>= 8 | ||
633 | 221 | s = chr(0200) + s | ||
634 | 222 | return s | ||
635 | 223 | |||
636 | 224 | def uts(s, encoding, errors): | ||
637 | 225 | """Convert a unicode object to a string. | ||
638 | 226 | """ | ||
639 | 227 | if errors == "utf-8": | ||
640 | 228 | # An extra error handler similar to the -o invalid=UTF-8 option | ||
641 | 229 | # in POSIX.1-2001. Replace untranslatable characters with their | ||
642 | 230 | # UTF-8 representation. | ||
643 | 231 | try: | ||
644 | 232 | return s.encode(encoding, "strict") | ||
645 | 233 | except UnicodeEncodeError: | ||
646 | 234 | x = [] | ||
647 | 235 | for c in s: | ||
648 | 236 | try: | ||
649 | 237 | x.append(c.encode(encoding, "strict")) | ||
650 | 238 | except UnicodeEncodeError: | ||
651 | 239 | x.append(c.encode("utf8")) | ||
652 | 240 | return "".join(x) | ||
653 | 241 | else: | ||
654 | 242 | return s.encode(encoding, errors) | ||
655 | 243 | |||
656 | 244 | def calc_chksums(buf): | ||
657 | 245 | """Calculate the checksum for a member's header by summing up all | ||
658 | 246 | characters except for the chksum field which is treated as if | ||
659 | 247 | it was filled with spaces. According to the GNU tar sources, | ||
660 | 248 | some tars (Sun and NeXT) calculate chksum with signed char, | ||
661 | 249 | which will be different if there are chars in the buffer with | ||
662 | 250 | the high bit set. So we calculate two checksums, unsigned and | ||
663 | 251 | signed. | ||
664 | 252 | """ | ||
665 | 253 | unsigned_chksum = 256 + sum(struct.unpack("148B", buf[:148]) + struct.unpack("356B", buf[156:512])) | ||
666 | 254 | signed_chksum = 256 + sum(struct.unpack("148b", buf[:148]) + struct.unpack("356b", buf[156:512])) | ||
667 | 255 | return unsigned_chksum, signed_chksum | ||
668 | 256 | |||
669 | 257 | def copyfileobj(src, dst, length=None): | ||
670 | 258 | """Copy length bytes from fileobj src to fileobj dst. | ||
671 | 259 | If length is None, copy the entire content. | ||
672 | 260 | """ | ||
673 | 261 | if length == 0: | ||
674 | 262 | return | ||
675 | 263 | if length is None: | ||
676 | 264 | shutil.copyfileobj(src, dst) | ||
677 | 265 | return | ||
678 | 266 | |||
679 | 267 | BUFSIZE = 16 * 1024 | ||
680 | 268 | blocks, remainder = divmod(length, BUFSIZE) | ||
681 | 269 | for b in xrange(blocks): | ||
682 | 270 | buf = src.read(BUFSIZE) | ||
683 | 271 | if len(buf) < BUFSIZE: | ||
684 | 272 | raise IOError("end of file reached") | ||
685 | 273 | dst.write(buf) | ||
686 | 274 | |||
687 | 275 | if remainder != 0: | ||
688 | 276 | buf = src.read(remainder) | ||
689 | 277 | if len(buf) < remainder: | ||
690 | 278 | raise IOError("end of file reached") | ||
691 | 279 | dst.write(buf) | ||
692 | 280 | return | ||
693 | 281 | |||
694 | 282 | filemode_table = ( | ||
695 | 283 | ((S_IFLNK, "l"), | ||
696 | 284 | (S_IFREG, "-"), | ||
697 | 285 | (S_IFBLK, "b"), | ||
698 | 286 | (S_IFDIR, "d"), | ||
699 | 287 | (S_IFCHR, "c"), | ||
700 | 288 | (S_IFIFO, "p")), | ||
701 | 289 | |||
702 | 290 | ((TUREAD, "r"),), | ||
703 | 291 | ((TUWRITE, "w"),), | ||
704 | 292 | ((TUEXEC|TSUID, "s"), | ||
705 | 293 | (TSUID, "S"), | ||
706 | 294 | (TUEXEC, "x")), | ||
707 | 295 | |||
708 | 296 | ((TGREAD, "r"),), | ||
709 | 297 | ((TGWRITE, "w"),), | ||
710 | 298 | ((TGEXEC|TSGID, "s"), | ||
711 | 299 | (TSGID, "S"), | ||
712 | 300 | (TGEXEC, "x")), | ||
713 | 301 | |||
714 | 302 | ((TOREAD, "r"),), | ||
715 | 303 | ((TOWRITE, "w"),), | ||
716 | 304 | ((TOEXEC|TSVTX, "t"), | ||
717 | 305 | (TSVTX, "T"), | ||
718 | 306 | (TOEXEC, "x")) | ||
719 | 307 | ) | ||
720 | 308 | |||
721 | 309 | def filemode(mode): | ||
722 | 310 | """Convert a file's mode to a string of the form | ||
723 | 311 | -rwxrwxrwx. | ||
724 | 312 | Used by TarFile.list() | ||
725 | 313 | """ | ||
726 | 314 | perm = [] | ||
727 | 315 | for table in filemode_table: | ||
728 | 316 | for bit, char in table: | ||
729 | 317 | if mode & bit == bit: | ||
730 | 318 | perm.append(char) | ||
731 | 319 | break | ||
732 | 320 | else: | ||
733 | 321 | perm.append("-") | ||
734 | 322 | return "".join(perm) | ||
735 | 323 | |||
736 | 324 | class TarError(Exception): | ||
737 | 325 | """Base exception.""" | ||
738 | 326 | pass | ||
739 | 327 | class ExtractError(TarError): | ||
740 | 328 | """General exception for extract errors.""" | ||
741 | 329 | pass | ||
742 | 330 | class ReadError(TarError): | ||
743 | 331 | """Exception for unreadble tar archives.""" | ||
744 | 332 | pass | ||
745 | 333 | class CompressionError(TarError): | ||
746 | 334 | """Exception for unavailable compression methods.""" | ||
747 | 335 | pass | ||
748 | 336 | class StreamError(TarError): | ||
749 | 337 | """Exception for unsupported operations on stream-like TarFiles.""" | ||
750 | 338 | pass | ||
751 | 339 | class HeaderError(TarError): | ||
752 | 340 | """Base exception for header errors.""" | ||
753 | 341 | pass | ||
754 | 342 | class EmptyHeaderError(HeaderError): | ||
755 | 343 | """Exception for empty headers.""" | ||
756 | 344 | pass | ||
757 | 345 | class TruncatedHeaderError(HeaderError): | ||
758 | 346 | """Exception for truncated headers.""" | ||
759 | 347 | pass | ||
760 | 348 | class EOFHeaderError(HeaderError): | ||
761 | 349 | """Exception for end of file headers.""" | ||
762 | 350 | pass | ||
763 | 351 | class InvalidHeaderError(HeaderError): | ||
764 | 352 | """Exception for invalid headers.""" | ||
765 | 353 | pass | ||
766 | 354 | class SubsequentHeaderError(HeaderError): | ||
767 | 355 | """Exception for missing and invalid extended headers.""" | ||
768 | 356 | pass | ||
769 | 357 | |||
770 | 358 | #--------------------------- | ||
771 | 359 | # internal stream interface | ||
772 | 360 | #--------------------------- | ||
773 | 361 | class _LowLevelFile: | ||
774 | 362 | """Low-level file object. Supports reading and writing. | ||
775 | 363 | It is used instead of a regular file object for streaming | ||
776 | 364 | access. | ||
777 | 365 | """ | ||
778 | 366 | |||
779 | 367 | def __init__(self, name, mode): | ||
780 | 368 | mode = { | ||
781 | 369 | "r": os.O_RDONLY, | ||
782 | 370 | "w": os.O_WRONLY | os.O_CREAT | os.O_TRUNC, | ||
783 | 371 | }[mode] | ||
784 | 372 | if hasattr(os, "O_BINARY"): | ||
785 | 373 | mode |= os.O_BINARY | ||
786 | 374 | self.fd = os.open(name, mode, 0666) | ||
787 | 375 | |||
788 | 376 | def close(self): | ||
789 | 377 | os.close(self.fd) | ||
790 | 378 | |||
791 | 379 | def read(self, size): | ||
792 | 380 | return os.read(self.fd, size) | ||
793 | 381 | |||
794 | 382 | def write(self, s): | ||
795 | 383 | os.write(self.fd, s) | ||
796 | 384 | |||
797 | 385 | class _Stream: | ||
798 | 386 | """Class that serves as an adapter between TarFile and | ||
799 | 387 | a stream-like object. The stream-like object only | ||
800 | 388 | needs to have a read() or write() method and is accessed | ||
801 | 389 | blockwise. Use of gzip or bzip2 compression is possible. | ||
802 | 390 | A stream-like object could be for example: sys.stdin, | ||
803 | 391 | sys.stdout, a socket, a tape device etc. | ||
804 | 392 | |||
805 | 393 | _Stream is intended to be used only internally. | ||
806 | 394 | """ | ||
807 | 395 | |||
808 | 396 | def __init__(self, name, mode, comptype, fileobj, bufsize): | ||
809 | 397 | """Construct a _Stream object. | ||
810 | 398 | """ | ||
811 | 399 | self._extfileobj = True | ||
812 | 400 | if fileobj is None: | ||
813 | 401 | fileobj = _LowLevelFile(name, mode) | ||
814 | 402 | self._extfileobj = False | ||
815 | 403 | |||
816 | 404 | if comptype == '*': | ||
817 | 405 | # Enable transparent compression detection for the | ||
818 | 406 | # stream interface | ||
819 | 407 | fileobj = _StreamProxy(fileobj) | ||
820 | 408 | comptype = fileobj.getcomptype() | ||
821 | 409 | |||
822 | 410 | self.name = name or "" | ||
823 | 411 | self.mode = mode | ||
824 | 412 | self.comptype = comptype | ||
825 | 413 | self.fileobj = fileobj | ||
826 | 414 | self.bufsize = bufsize | ||
827 | 415 | self.buf = "" | ||
828 | 416 | self.pos = 0L | ||
829 | 417 | self.closed = False | ||
830 | 418 | |||
831 | 419 | if comptype == "gz": | ||
832 | 420 | try: | ||
833 | 421 | import zlib | ||
834 | 422 | except ImportError: | ||
835 | 423 | raise CompressionError("zlib module is not available") | ||
836 | 424 | self.zlib = zlib | ||
837 | 425 | self.crc = zlib.crc32("") & 0xffffffffL | ||
838 | 426 | if mode == "r": | ||
839 | 427 | self._init_read_gz() | ||
840 | 428 | else: | ||
841 | 429 | self._init_write_gz() | ||
842 | 430 | |||
843 | 431 | if comptype == "bz2": | ||
844 | 432 | try: | ||
845 | 433 | import bz2 | ||
846 | 434 | except ImportError: | ||
847 | 435 | raise CompressionError("bz2 module is not available") | ||
848 | 436 | if mode == "r": | ||
849 | 437 | self.dbuf = "" | ||
850 | 438 | self.cmp = bz2.BZ2Decompressor() | ||
851 | 439 | else: | ||
852 | 440 | self.cmp = bz2.BZ2Compressor() | ||
853 | 441 | |||
854 | 442 | def __del__(self): | ||
855 | 443 | if hasattr(self, "closed") and not self.closed: | ||
856 | 444 | self.close() | ||
857 | 445 | |||
858 | 446 | def _init_write_gz(self): | ||
859 | 447 | """Initialize for writing with gzip compression. | ||
860 | 448 | """ | ||
861 | 449 | self.cmp = self.zlib.compressobj(9, self.zlib.DEFLATED, | ||
862 | 450 | -self.zlib.MAX_WBITS, | ||
863 | 451 | self.zlib.DEF_MEM_LEVEL, | ||
864 | 452 | 0) | ||
865 | 453 | timestamp = struct.pack("<L", long(time.time())) | ||
866 | 454 | self.__write("\037\213\010\010%s\002\377" % timestamp) | ||
867 | 455 | if self.name.endswith(".gz"): | ||
868 | 456 | self.name = self.name[:-3] | ||
869 | 457 | self.__write(self.name + NUL) | ||
870 | 458 | |||
871 | 459 | def write(self, s): | ||
872 | 460 | """Write string s to the stream. | ||
873 | 461 | """ | ||
874 | 462 | if self.comptype == "gz": | ||
875 | 463 | self.crc = self.zlib.crc32(s, self.crc) & 0xffffffffL | ||
876 | 464 | self.pos += len(s) | ||
877 | 465 | if self.comptype != "tar": | ||
878 | 466 | s = self.cmp.compress(s) | ||
879 | 467 | self.__write(s) | ||
880 | 468 | |||
881 | 469 | def __write(self, s): | ||
882 | 470 | """Write string s to the stream if a whole new block | ||
883 | 471 | is ready to be written. | ||
884 | 472 | """ | ||
885 | 473 | self.buf += s | ||
886 | 474 | while len(self.buf) > self.bufsize: | ||
887 | 475 | self.fileobj.write(self.buf[:self.bufsize]) | ||
888 | 476 | self.buf = self.buf[self.bufsize:] | ||
889 | 477 | |||
890 | 478 | def close(self): | ||
891 | 479 | """Close the _Stream object. No operation should be | ||
892 | 480 | done on it afterwards. | ||
893 | 481 | """ | ||
894 | 482 | if self.closed: | ||
895 | 483 | return | ||
896 | 484 | |||
897 | 485 | if self.mode == "w" and self.comptype != "tar": | ||
898 | 486 | self.buf += self.cmp.flush() | ||
899 | 487 | |||
900 | 488 | if self.mode == "w" and self.buf: | ||
901 | 489 | self.fileobj.write(self.buf) | ||
902 | 490 | self.buf = "" | ||
903 | 491 | if self.comptype == "gz": | ||
904 | 492 | # The native zlib crc is an unsigned 32-bit integer, but | ||
905 | 493 | # the Python wrapper implicitly casts that to a signed C | ||
906 | 494 | # long. So, on a 32-bit box self.crc may "look negative", | ||
907 | 495 | # while the same crc on a 64-bit box may "look positive". | ||
908 | 496 | # To avoid irksome warnings from the `struct` module, force | ||
909 | 497 | # it to look positive on all boxes. | ||
910 | 498 | self.fileobj.write(struct.pack("<L", self.crc & 0xffffffffL)) | ||
911 | 499 | self.fileobj.write(struct.pack("<L", self.pos & 0xffffFFFFL)) | ||
912 | 500 | |||
913 | 501 | if not self._extfileobj: | ||
914 | 502 | self.fileobj.close() | ||
915 | 503 | |||
916 | 504 | self.closed = True | ||
917 | 505 | |||
918 | 506 | def _init_read_gz(self): | ||
919 | 507 | """Initialize for reading a gzip compressed fileobj. | ||
920 | 508 | """ | ||
921 | 509 | self.cmp = self.zlib.decompressobj(-self.zlib.MAX_WBITS) | ||
922 | 510 | self.dbuf = "" | ||
923 | 511 | |||
924 | 512 | # taken from gzip.GzipFile with some alterations | ||
925 | 513 | if self.__read(2) != "\037\213": | ||
926 | 514 | raise ReadError("not a gzip file") | ||
927 | 515 | if self.__read(1) != "\010": | ||
928 | 516 | raise CompressionError("unsupported compression method") | ||
929 | 517 | |||
930 | 518 | flag = ord(self.__read(1)) | ||
931 | 519 | self.__read(6) | ||
932 | 520 | |||
933 | 521 | if flag & 4: | ||
934 | 522 | xlen = ord(self.__read(1)) + 256 * ord(self.__read(1)) | ||
935 | 523 | self.read(xlen) | ||
936 | 524 | if flag & 8: | ||
937 | 525 | while True: | ||
938 | 526 | s = self.__read(1) | ||
939 | 527 | if not s or s == NUL: | ||
940 | 528 | break | ||
941 | 529 | if flag & 16: | ||
942 | 530 | while True: | ||
943 | 531 | s = self.__read(1) | ||
944 | 532 | if not s or s == NUL: | ||
945 | 533 | break | ||
946 | 534 | if flag & 2: | ||
947 | 535 | self.__read(2) | ||
948 | 536 | |||
949 | 537 | def tell(self): | ||
950 | 538 | """Return the stream's file pointer position. | ||
951 | 539 | """ | ||
952 | 540 | return self.pos | ||
953 | 541 | |||
954 | 542 | def seek(self, pos=0): | ||
955 | 543 | """Set the stream's file pointer to pos. Negative seeking | ||
956 | 544 | is forbidden. | ||
957 | 545 | """ | ||
958 | 546 | if pos - self.pos >= 0: | ||
959 | 547 | blocks, remainder = divmod(pos - self.pos, self.bufsize) | ||
960 | 548 | for i in xrange(blocks): | ||
961 | 549 | self.read(self.bufsize) | ||
962 | 550 | self.read(remainder) | ||
963 | 551 | else: | ||
964 | 552 | raise StreamError("seeking backwards is not allowed") | ||
965 | 553 | return self.pos | ||
966 | 554 | |||
967 | 555 | def read(self, size=None): | ||
968 | 556 | """Return the next size number of bytes from the stream. | ||
969 | 557 | If size is not defined, return all bytes of the stream | ||
970 | 558 | up to EOF. | ||
971 | 559 | """ | ||
972 | 560 | if size is None: | ||
973 | 561 | t = [] | ||
974 | 562 | while True: | ||
975 | 563 | buf = self._read(self.bufsize) | ||
976 | 564 | if not buf: | ||
977 | 565 | break | ||
978 | 566 | t.append(buf) | ||
979 | 567 | buf = "".join(t) | ||
980 | 568 | else: | ||
981 | 569 | buf = self._read(size) | ||
982 | 570 | self.pos += len(buf) | ||
983 | 571 | return buf | ||
984 | 572 | |||
985 | 573 | def _read(self, size): | ||
986 | 574 | """Return size bytes from the stream. | ||
987 | 575 | """ | ||
988 | 576 | if self.comptype == "tar": | ||
989 | 577 | return self.__read(size) | ||
990 | 578 | |||
991 | 579 | c = len(self.dbuf) | ||
992 | 580 | t = [self.dbuf] | ||
993 | 581 | while c < size: | ||
994 | 582 | buf = self.__read(self.bufsize) | ||
995 | 583 | if not buf: | ||
996 | 584 | break | ||
997 | 585 | try: | ||
998 | 586 | buf = self.cmp.decompress(buf) | ||
999 | 587 | except IOError: | ||
1000 | 588 | raise ReadError("invalid compressed data") | ||
1001 | 589 | t.append(buf) | ||
1002 | 590 | c += len(buf) | ||
1003 | 591 | t = "".join(t) | ||
1004 | 592 | self.dbuf = t[size:] | ||
1005 | 593 | return t[:size] | ||
1006 | 594 | |||
1007 | 595 | def __read(self, size): | ||
1008 | 596 | """Return size bytes from stream. If internal buffer is empty, | ||
1009 | 597 | read another block from the stream. | ||
1010 | 598 | """ | ||
1011 | 599 | c = len(self.buf) | ||
1012 | 600 | t = [self.buf] | ||
1013 | 601 | while c < size: | ||
1014 | 602 | buf = self.fileobj.read(self.bufsize) | ||
1015 | 603 | if not buf: | ||
1016 | 604 | break | ||
1017 | 605 | t.append(buf) | ||
1018 | 606 | c += len(buf) | ||
1019 | 607 | t = "".join(t) | ||
1020 | 608 | self.buf = t[size:] | ||
1021 | 609 | return t[:size] | ||
1022 | 610 | # class _Stream | ||
1023 | 611 | |||
1024 | 612 | class _StreamProxy(object): | ||
1025 | 613 | """Small proxy class that enables transparent compression | ||
1026 | 614 | detection for the Stream interface (mode 'r|*'). | ||
1027 | 615 | """ | ||
1028 | 616 | |||
1029 | 617 | def __init__(self, fileobj): | ||
1030 | 618 | self.fileobj = fileobj | ||
1031 | 619 | self.buf = self.fileobj.read(BLOCKSIZE) | ||
1032 | 620 | |||
1033 | 621 | def read(self, size): | ||
1034 | 622 | self.read = self.fileobj.read | ||
1035 | 623 | return self.buf | ||
1036 | 624 | |||
1037 | 625 | def getcomptype(self): | ||
1038 | 626 | if self.buf.startswith("\037\213\010"): | ||
1039 | 627 | return "gz" | ||
1040 | 628 | if self.buf.startswith("BZh91"): | ||
1041 | 629 | return "bz2" | ||
1042 | 630 | return "tar" | ||
1043 | 631 | |||
1044 | 632 | def close(self): | ||
1045 | 633 | self.fileobj.close() | ||
1046 | 634 | # class StreamProxy | ||
1047 | 635 | |||
1048 | 636 | class _BZ2Proxy(object): | ||
1049 | 637 | """Small proxy class that enables external file object | ||
1050 | 638 | support for "r:bz2" and "w:bz2" modes. This is actually | ||
1051 | 639 | a workaround for a limitation in bz2 module's BZ2File | ||
1052 | 640 | class which (unlike gzip.GzipFile) has no support for | ||
1053 | 641 | a file object argument. | ||
1054 | 642 | """ | ||
1055 | 643 | |||
1056 | 644 | blocksize = 16 * 1024 | ||
1057 | 645 | |||
1058 | 646 | def __init__(self, fileobj, mode): | ||
1059 | 647 | self.fileobj = fileobj | ||
1060 | 648 | self.mode = mode | ||
1061 | 649 | self.name = getattr(self.fileobj, "name", None) | ||
1062 | 650 | self.init() | ||
1063 | 651 | |||
1064 | 652 | def init(self): | ||
1065 | 653 | import bz2 | ||
1066 | 654 | self.pos = 0 | ||
1067 | 655 | if self.mode == "r": | ||
1068 | 656 | self.bz2obj = bz2.BZ2Decompressor() | ||
1069 | 657 | self.fileobj.seek(0) | ||
1070 | 658 | self.buf = "" | ||
1071 | 659 | else: | ||
1072 | 660 | self.bz2obj = bz2.BZ2Compressor() | ||
1073 | 661 | |||
1074 | 662 | def read(self, size): | ||
1075 | 663 | b = [self.buf] | ||
1076 | 664 | x = len(self.buf) | ||
1077 | 665 | while x < size: | ||
1078 | 666 | raw = self.fileobj.read(self.blocksize) | ||
1079 | 667 | if not raw: | ||
1080 | 668 | break | ||
1081 | 669 | data = self.bz2obj.decompress(raw) | ||
1082 | 670 | b.append(data) | ||
1083 | 671 | x += len(data) | ||
1084 | 672 | self.buf = "".join(b) | ||
1085 | 673 | |||
1086 | 674 | buf = self.buf[:size] | ||
1087 | 675 | self.buf = self.buf[size:] | ||
1088 | 676 | self.pos += len(buf) | ||
1089 | 677 | return buf | ||
1090 | 678 | |||
1091 | 679 | def seek(self, pos): | ||
1092 | 680 | if pos < self.pos: | ||
1093 | 681 | self.init() | ||
1094 | 682 | self.read(pos - self.pos) | ||
1095 | 683 | |||
1096 | 684 | def tell(self): | ||
1097 | 685 | return self.pos | ||
1098 | 686 | |||
1099 | 687 | def write(self, data): | ||
1100 | 688 | self.pos += len(data) | ||
1101 | 689 | raw = self.bz2obj.compress(data) | ||
1102 | 690 | self.fileobj.write(raw) | ||
1103 | 691 | |||
1104 | 692 | def close(self): | ||
1105 | 693 | if self.mode == "w": | ||
1106 | 694 | raw = self.bz2obj.flush() | ||
1107 | 695 | self.fileobj.write(raw) | ||
1108 | 696 | # class _BZ2Proxy | ||
1109 | 697 | |||
1110 | 698 | #------------------------ | ||
1111 | 699 | # Extraction file object | ||
1112 | 700 | #------------------------ | ||
1113 | 701 | class _FileInFile(object): | ||
1114 | 702 | """A thin wrapper around an existing file object that | ||
1115 | 703 | provides a part of its data as an individual file | ||
1116 | 704 | object. | ||
1117 | 705 | """ | ||
1118 | 706 | |||
1119 | 707 | def __init__(self, fileobj, offset, size, sparse=None): | ||
1120 | 708 | self.fileobj = fileobj | ||
1121 | 709 | self.offset = offset | ||
1122 | 710 | self.size = size | ||
1123 | 711 | self.sparse = sparse | ||
1124 | 712 | self.position = 0 | ||
1125 | 713 | |||
1126 | 714 | def tell(self): | ||
1127 | 715 | """Return the current file position. | ||
1128 | 716 | """ | ||
1129 | 717 | return self.position | ||
1130 | 718 | |||
1131 | 719 | def seek(self, position): | ||
1132 | 720 | """Seek to a position in the file. | ||
1133 | 721 | """ | ||
1134 | 722 | self.position = position | ||
1135 | 723 | |||
1136 | 724 | def read(self, size=None): | ||
1137 | 725 | """Read data from the file. | ||
1138 | 726 | """ | ||
1139 | 727 | if size is None: | ||
1140 | 728 | size = self.size - self.position | ||
1141 | 729 | else: | ||
1142 | 730 | size = min(size, self.size - self.position) | ||
1143 | 731 | |||
1144 | 732 | if self.sparse is None: | ||
1145 | 733 | return self.readnormal(size) | ||
1146 | 734 | else: | ||
1147 | 735 | return self.readsparse(size) | ||
1148 | 736 | |||
1149 | 737 | def readnormal(self, size): | ||
1150 | 738 | """Read operation for regular files. | ||
1151 | 739 | """ | ||
1152 | 740 | self.fileobj.seek(self.offset + self.position) | ||
1153 | 741 | self.position += size | ||
1154 | 742 | return self.fileobj.read(size) | ||
1155 | 743 | |||
1156 | 744 | def readsparse(self, size): | ||
1157 | 745 | """Read operation for sparse files. | ||
1158 | 746 | """ | ||
1159 | 747 | data = [] | ||
1160 | 748 | while size > 0: | ||
1161 | 749 | buf = self.readsparsesection(size) | ||
1162 | 750 | if not buf: | ||
1163 | 751 | break | ||
1164 | 752 | size -= len(buf) | ||
1165 | 753 | data.append(buf) | ||
1166 | 754 | return "".join(data) | ||
1167 | 755 | |||
1168 | 756 | def readsparsesection(self, size): | ||
1169 | 757 | """Read a single section of a sparse file. | ||
1170 | 758 | """ | ||
1171 | 759 | section = self.sparse.find(self.position) | ||
1172 | 760 | |||
1173 | 761 | if section is None: | ||
1174 | 762 | return "" | ||
1175 | 763 | |||
1176 | 764 | size = min(size, section.offset + section.size - self.position) | ||
1177 | 765 | |||
1178 | 766 | if isinstance(section, _data): | ||
1179 | 767 | realpos = section.realpos + self.position - section.offset | ||
1180 | 768 | self.fileobj.seek(self.offset + realpos) | ||
1181 | 769 | self.position += size | ||
1182 | 770 | return self.fileobj.read(size) | ||
1183 | 771 | else: | ||
1184 | 772 | self.position += size | ||
1185 | 773 | return NUL * size | ||
1186 | 774 | #class _FileInFile | ||
1187 | 775 | |||
1188 | 776 | |||
1189 | 777 | class ExFileObject(object): | ||
1190 | 778 | """File-like object for reading an archive member. | ||
1191 | 779 | Is returned by TarFile.extractfile(). | ||
1192 | 780 | """ | ||
1193 | 781 | blocksize = 1024 | ||
1194 | 782 | |||
1195 | 783 | def __init__(self, tarfile, tarinfo): | ||
1196 | 784 | self.fileobj = _FileInFile(tarfile.fileobj, | ||
1197 | 785 | tarinfo.offset_data, | ||
1198 | 786 | tarinfo.size, | ||
1199 | 787 | getattr(tarinfo, "sparse", None)) | ||
1200 | 788 | self.name = tarinfo.name | ||
1201 | 789 | self.mode = "r" | ||
1202 | 790 | self.closed = False | ||
1203 | 791 | self.size = tarinfo.size | ||
1204 | 792 | |||
1205 | 793 | self.position = 0 | ||
1206 | 794 | self.buffer = "" | ||
1207 | 795 | |||
1208 | 796 | def read(self, size=None): | ||
1209 | 797 | """Read at most size bytes from the file. If size is not | ||
1210 | 798 | present or None, read all data until EOF is reached. | ||
1211 | 799 | """ | ||
1212 | 800 | if self.closed: | ||
1213 | 801 | raise ValueError("I/O operation on closed file") | ||
1214 | 802 | |||
1215 | 803 | buf = "" | ||
1216 | 804 | if self.buffer: | ||
1217 | 805 | if size is None: | ||
1218 | 806 | buf = self.buffer | ||
1219 | 807 | self.buffer = "" | ||
1220 | 808 | else: | ||
1221 | 809 | buf = self.buffer[:size] | ||
1222 | 810 | self.buffer = self.buffer[size:] | ||
1223 | 811 | |||
1224 | 812 | if size is None: | ||
1225 | 813 | buf += self.fileobj.read() | ||
1226 | 814 | else: | ||
1227 | 815 | buf += self.fileobj.read(size - len(buf)) | ||
1228 | 816 | |||
1229 | 817 | self.position += len(buf) | ||
1230 | 818 | return buf | ||
1231 | 819 | |||
1232 | 820 | def readline(self, size=-1): | ||
1233 | 821 | """Read one entire line from the file. If size is present | ||
1234 | 822 | and non-negative, return a string with at most that | ||
1235 | 823 | size, which may be an incomplete line. | ||
1236 | 824 | """ | ||
1237 | 825 | if self.closed: | ||
1238 | 826 | raise ValueError("I/O operation on closed file") | ||
1239 | 827 | |||
1240 | 828 | if "\n" in self.buffer: | ||
1241 | 829 | pos = self.buffer.find("\n") + 1 | ||
1242 | 830 | else: | ||
1243 | 831 | buffers = [self.buffer] | ||
1244 | 832 | while True: | ||
1245 | 833 | buf = self.fileobj.read(self.blocksize) | ||
1246 | 834 | buffers.append(buf) | ||
1247 | 835 | if not buf or "\n" in buf: | ||
1248 | 836 | self.buffer = "".join(buffers) | ||
1249 | 837 | pos = self.buffer.find("\n") + 1 | ||
1250 | 838 | if pos == 0: | ||
1251 | 839 | # no newline found. | ||
1252 | 840 | pos = len(self.buffer) | ||
1253 | 841 | break | ||
1254 | 842 | |||
1255 | 843 | if size != -1: | ||
1256 | 844 | pos = min(size, pos) | ||
1257 | 845 | |||
1258 | 846 | buf = self.buffer[:pos] | ||
1259 | 847 | self.buffer = self.buffer[pos:] | ||
1260 | 848 | self.position += len(buf) | ||
1261 | 849 | return buf | ||
1262 | 850 | |||
1263 | 851 | def readlines(self): | ||
1264 | 852 | """Return a list with all remaining lines. | ||
1265 | 853 | """ | ||
1266 | 854 | result = [] | ||
1267 | 855 | while True: | ||
1268 | 856 | line = self.readline() | ||
1269 | 857 | if not line: break | ||
1270 | 858 | result.append(line) | ||
1271 | 859 | return result | ||
1272 | 860 | |||
1273 | 861 | def tell(self): | ||
1274 | 862 | """Return the current file position. | ||
1275 | 863 | """ | ||
1276 | 864 | if self.closed: | ||
1277 | 865 | raise ValueError("I/O operation on closed file") | ||
1278 | 866 | |||
1279 | 867 | return self.position | ||
1280 | 868 | |||
1281 | 869 | def seek(self, pos, whence=0): | ||
1282 | 870 | """Seek to a position in the file. | ||
1283 | 871 | """ | ||
1284 | 872 | if self.closed: | ||
1285 | 873 | raise ValueError("I/O operation on closed file") | ||
1286 | 874 | |||
1287 | 875 | if whence == 0: | ||
1288 | 876 | self.position = min(max(pos, 0), self.size) | ||
1289 | 877 | elif whence == 1: | ||
1290 | 878 | if pos < 0: | ||
1291 | 879 | self.position = max(self.position + pos, 0) | ||
1292 | 880 | else: | ||
1293 | 881 | self.position = min(self.position + pos, self.size) | ||
1294 | 882 | elif whence == 2: | ||
1295 | 883 | self.position = max(min(self.size + pos, self.size), 0) | ||
1296 | 884 | else: | ||
1297 | 885 | raise ValueError("Invalid argument") | ||
1298 | 886 | |||
1299 | 887 | self.buffer = "" | ||
1300 | 888 | self.fileobj.seek(self.position) | ||
1301 | 889 | |||
1302 | 890 | def close(self): | ||
1303 | 891 | """Close the file object. | ||
1304 | 892 | """ | ||
1305 | 893 | self.closed = True | ||
1306 | 894 | |||
1307 | 895 | def __iter__(self): | ||
1308 | 896 | """Get an iterator over the file's lines. | ||
1309 | 897 | """ | ||
1310 | 898 | while True: | ||
1311 | 899 | line = self.readline() | ||
1312 | 900 | if not line: | ||
1313 | 901 | break | ||
1314 | 902 | yield line | ||
1315 | 903 | #class ExFileObject | ||
1316 | 904 | |||
1317 | 905 | #------------------ | ||
1318 | 906 | # Exported Classes | ||
1319 | 907 | #------------------ | ||
1320 | 908 | class TarInfo(object): | ||
1321 | 909 | """Informational class which holds the details about an | ||
1322 | 910 | archive member given by a tar header block. | ||
1323 | 911 | TarInfo objects are returned by TarFile.getmember(), | ||
1324 | 912 | TarFile.getmembers() and TarFile.gettarinfo() and are | ||
1325 | 913 | usually created internally. | ||
1326 | 914 | """ | ||
1327 | 915 | |||
1328 | 916 | def __init__(self, name=""): | ||
1329 | 917 | """Construct a TarInfo object. name is the optional name | ||
1330 | 918 | of the member. | ||
1331 | 919 | """ | ||
1332 | 920 | self.name = name # member name | ||
1333 | 921 | self.mode = 0644 # file permissions | ||
1334 | 922 | self.uid = 0 # user id | ||
1335 | 923 | self.gid = 0 # group id | ||
1336 | 924 | self.size = 0 # file size | ||
1337 | 925 | self.mtime = 0 # modification time | ||
1338 | 926 | self.chksum = 0 # header checksum | ||
1339 | 927 | self.type = REGTYPE # member type | ||
1340 | 928 | self.linkname = "" # link name | ||
1341 | 929 | self.uname = "" # user name | ||
1342 | 930 | self.gname = "" # group name | ||
1343 | 931 | self.devmajor = 0 # device major number | ||
1344 | 932 | self.devminor = 0 # device minor number | ||
1345 | 933 | |||
1346 | 934 | self.offset = 0 # the tar header starts here | ||
1347 | 935 | self.offset_data = 0 # the file's data starts here | ||
1348 | 936 | |||
1349 | 937 | self.pax_headers = {} # pax header information | ||
1350 | 938 | |||
1351 | 939 | # In pax headers the "name" and "linkname" field are called | ||
1352 | 940 | # "path" and "linkpath". | ||
1353 | 941 | def _getpath(self): | ||
1354 | 942 | return self.name | ||
1355 | 943 | def _setpath(self, name): | ||
1356 | 944 | self.name = name | ||
1357 | 945 | path = property(_getpath, _setpath) | ||
1358 | 946 | |||
1359 | 947 | def _getlinkpath(self): | ||
1360 | 948 | return self.linkname | ||
1361 | 949 | def _setlinkpath(self, linkname): | ||
1362 | 950 | self.linkname = linkname | ||
1363 | 951 | linkpath = property(_getlinkpath, _setlinkpath) | ||
1364 | 952 | |||
1365 | 953 | def __repr__(self): | ||
1366 | 954 | return "<%s %r at %#x>" % (self.__class__.__name__,self.name,id(self)) | ||
1367 | 955 | |||
1368 | 956 | def get_info(self, encoding, errors): | ||
1369 | 957 | """Return the TarInfo's attributes as a dictionary. | ||
1370 | 958 | """ | ||
1371 | 959 | info = { | ||
1372 | 960 | "name": self.name, | ||
1373 | 961 | "mode": self.mode & 07777, | ||
1374 | 962 | "uid": self.uid, | ||
1375 | 963 | "gid": self.gid, | ||
1376 | 964 | "size": self.size, | ||
1377 | 965 | "mtime": self.mtime, | ||
1378 | 966 | "chksum": self.chksum, | ||
1379 | 967 | "type": self.type, | ||
1380 | 968 | "linkname": self.linkname, | ||
1381 | 969 | "uname": self.uname, | ||
1382 | 970 | "gname": self.gname, | ||
1383 | 971 | "devmajor": self.devmajor, | ||
1384 | 972 | "devminor": self.devminor | ||
1385 | 973 | } | ||
1386 | 974 | |||
1387 | 975 | if info["type"] == DIRTYPE and not info["name"].endswith("/"): | ||
1388 | 976 | info["name"] += "/" | ||
1389 | 977 | |||
1390 | 978 | for key in ("name", "linkname", "uname", "gname"): | ||
1391 | 979 | if type(info[key]) is unicode: | ||
1392 | 980 | info[key] = info[key].encode(encoding, errors) | ||
1393 | 981 | |||
1394 | 982 | return info | ||
1395 | 983 | |||
1396 | 984 | def tobuf(self, format=DEFAULT_FORMAT, encoding=ENCODING, errors="strict"): | ||
1397 | 985 | """Return a tar header as a string of 512 byte blocks. | ||
1398 | 986 | """ | ||
1399 | 987 | info = self.get_info(encoding, errors) | ||
1400 | 988 | |||
1401 | 989 | if format == USTAR_FORMAT: | ||
1402 | 990 | return self.create_ustar_header(info) | ||
1403 | 991 | elif format == GNU_FORMAT: | ||
1404 | 992 | return self.create_gnu_header(info) | ||
1405 | 993 | elif format == PAX_FORMAT: | ||
1406 | 994 | return self.create_pax_header(info, encoding, errors) | ||
1407 | 995 | else: | ||
1408 | 996 | raise ValueError("invalid format") | ||
1409 | 997 | |||
1410 | 998 | def create_ustar_header(self, info): | ||
1411 | 999 | """Return the object as a ustar header block. | ||
1412 | 1000 | """ | ||
1413 | 1001 | info["magic"] = POSIX_MAGIC | ||
1414 | 1002 | |||
1415 | 1003 | if len(info["linkname"]) > LENGTH_LINK: | ||
1416 | 1004 | raise ValueError("linkname is too long") | ||
1417 | 1005 | |||
1418 | 1006 | if len(info["name"]) > LENGTH_NAME: | ||
1419 | 1007 | info["prefix"], info["name"] = self._posix_split_name(info["name"]) | ||
1420 | 1008 | |||
1421 | 1009 | return self._create_header(info, USTAR_FORMAT) | ||
1422 | 1010 | |||
1423 | 1011 | def create_gnu_header(self, info): | ||
1424 | 1012 | """Return the object as a GNU header block sequence. | ||
1425 | 1013 | """ | ||
1426 | 1014 | info["magic"] = GNU_MAGIC | ||
1427 | 1015 | |||
1428 | 1016 | buf = "" | ||
1429 | 1017 | if len(info["linkname"]) > LENGTH_LINK: | ||
1430 | 1018 | buf += self._create_gnu_long_header(info["linkname"], GNUTYPE_LONGLINK) | ||
1431 | 1019 | |||
1432 | 1020 | if len(info["name"]) > LENGTH_NAME: | ||
1433 | 1021 | buf += self._create_gnu_long_header(info["name"], GNUTYPE_LONGNAME) | ||
1434 | 1022 | |||
1435 | 1023 | return buf + self._create_header(info, GNU_FORMAT) | ||
1436 | 1024 | |||
1437 | 1025 | def create_pax_header(self, info, encoding, errors): | ||
1438 | 1026 | """Return the object as a ustar header block. If it cannot be | ||
1439 | 1027 | represented this way, prepend a pax extended header sequence | ||
1440 | 1028 | with supplement information. | ||
1441 | 1029 | """ | ||
1442 | 1030 | info["magic"] = POSIX_MAGIC | ||
1443 | 1031 | pax_headers = self.pax_headers.copy() | ||
1444 | 1032 | |||
1445 | 1033 | # Test string fields for values that exceed the field length or cannot | ||
1446 | 1034 | # be represented in ASCII encoding. | ||
1447 | 1035 | for name, hname, length in ( | ||
1448 | 1036 | ("name", "path", LENGTH_NAME), ("linkname", "linkpath", LENGTH_LINK), | ||
1449 | 1037 | ("uname", "uname", 32), ("gname", "gname", 32)): | ||
1450 | 1038 | |||
1451 | 1039 | if hname in pax_headers: | ||
1452 | 1040 | # The pax header has priority. | ||
1453 | 1041 | continue | ||
1454 | 1042 | |||
1455 | 1043 | val = info[name].decode(encoding, errors) | ||
1456 | 1044 | |||
1457 | 1045 | # Try to encode the string as ASCII. | ||
1458 | 1046 | try: | ||
1459 | 1047 | val.encode("ascii") | ||
1460 | 1048 | except UnicodeEncodeError: | ||
1461 | 1049 | pax_headers[hname] = val | ||
1462 | 1050 | continue | ||
1463 | 1051 | |||
1464 | 1052 | if len(info[name]) > length: | ||
1465 | 1053 | pax_headers[hname] = val | ||
1466 | 1054 | |||
1467 | 1055 | # Test number fields for values that exceed the field limit or values | ||
1468 | 1056 | # that like to be stored as float. | ||
1469 | 1057 | for name, digits in (("uid", 8), ("gid", 8), ("size", 12), ("mtime", 12)): | ||
1470 | 1058 | if name in pax_headers: | ||
1471 | 1059 | # The pax header has priority. Avoid overflow. | ||
1472 | 1060 | info[name] = 0 | ||
1473 | 1061 | continue | ||
1474 | 1062 | |||
1475 | 1063 | val = info[name] | ||
1476 | 1064 | if not 0 <= val < 8 ** (digits - 1) or isinstance(val, float): | ||
1477 | 1065 | pax_headers[name] = unicode(val) | ||
1478 | 1066 | info[name] = 0 | ||
1479 | 1067 | |||
1480 | 1068 | # Create a pax extended header if necessary. | ||
1481 | 1069 | if pax_headers: | ||
1482 | 1070 | buf = self._create_pax_generic_header(pax_headers) | ||
1483 | 1071 | else: | ||
1484 | 1072 | buf = "" | ||
1485 | 1073 | |||
1486 | 1074 | return buf + self._create_header(info, USTAR_FORMAT) | ||
1487 | 1075 | |||
1488 | 1076 | @classmethod | ||
1489 | 1077 | def create_pax_global_header(cls, pax_headers): | ||
1490 | 1078 | """Return the object as a pax global header block sequence. | ||
1491 | 1079 | """ | ||
1492 | 1080 | return cls._create_pax_generic_header(pax_headers, type=XGLTYPE) | ||
1493 | 1081 | |||
1494 | 1082 | def _posix_split_name(self, name): | ||
1495 | 1083 | """Split a name longer than 100 chars into a prefix | ||
1496 | 1084 | and a name part. | ||
1497 | 1085 | """ | ||
1498 | 1086 | prefix = name[:LENGTH_PREFIX + 1] | ||
1499 | 1087 | while prefix and prefix[-1] != "/": | ||
1500 | 1088 | prefix = prefix[:-1] | ||
1501 | 1089 | |||
1502 | 1090 | name = name[len(prefix):] | ||
1503 | 1091 | prefix = prefix[:-1] | ||
1504 | 1092 | |||
1505 | 1093 | if not prefix or len(name) > LENGTH_NAME: | ||
1506 | 1094 | raise ValueError("name is too long") | ||
1507 | 1095 | return prefix, name | ||
1508 | 1096 | |||
1509 | 1097 | @staticmethod | ||
1510 | 1098 | def _create_header(info, format): | ||
1511 | 1099 | """Return a header block. info is a dictionary with file | ||
1512 | 1100 | information, format must be one of the *_FORMAT constants. | ||
1513 | 1101 | """ | ||
1514 | 1102 | parts = [ | ||
1515 | 1103 | stn(info.get("name", ""), 100), | ||
1516 | 1104 | itn(info.get("mode", 0) & 07777, 8, format), | ||
1517 | 1105 | itn(info.get("uid", 0), 8, format), | ||
1518 | 1106 | itn(info.get("gid", 0), 8, format), | ||
1519 | 1107 | itn(info.get("size", 0), 12, format), | ||
1520 | 1108 | itn(info.get("mtime", 0), 12, format), | ||
1521 | 1109 | " ", # checksum field | ||
1522 | 1110 | info.get("type", REGTYPE), | ||
1523 | 1111 | stn(info.get("linkname", ""), 100), | ||
1524 | 1112 | stn(info.get("magic", POSIX_MAGIC), 8), | ||
1525 | 1113 | stn(info.get("uname", ""), 32), | ||
1526 | 1114 | stn(info.get("gname", ""), 32), | ||
1527 | 1115 | itn(info.get("devmajor", 0), 8, format), | ||
1528 | 1116 | itn(info.get("devminor", 0), 8, format), | ||
1529 | 1117 | stn(info.get("prefix", ""), 155) | ||
1530 | 1118 | ] | ||
1531 | 1119 | |||
1532 | 1120 | buf = struct.pack("%ds" % BLOCKSIZE, "".join(parts)) | ||
1533 | 1121 | chksum = calc_chksums(buf[-BLOCKSIZE:])[0] | ||
1534 | 1122 | buf = buf[:-364] + "%06o\0" % chksum + buf[-357:] | ||
1535 | 1123 | return buf | ||
1536 | 1124 | |||
1537 | 1125 | @staticmethod | ||
1538 | 1126 | def _create_payload(payload): | ||
1539 | 1127 | """Return the string payload filled with zero bytes | ||
1540 | 1128 | up to the next 512 byte border. | ||
1541 | 1129 | """ | ||
1542 | 1130 | blocks, remainder = divmod(len(payload), BLOCKSIZE) | ||
1543 | 1131 | if remainder > 0: | ||
1544 | 1132 | payload += (BLOCKSIZE - remainder) * NUL | ||
1545 | 1133 | return payload | ||
1546 | 1134 | |||
1547 | 1135 | @classmethod | ||
1548 | 1136 | def _create_gnu_long_header(cls, name, type): | ||
1549 | 1137 | """Return a GNUTYPE_LONGNAME or GNUTYPE_LONGLINK sequence | ||
1550 | 1138 | for name. | ||
1551 | 1139 | """ | ||
1552 | 1140 | name += NUL | ||
1553 | 1141 | |||
1554 | 1142 | info = {} | ||
1555 | 1143 | info["name"] = "././@LongLink" | ||
1556 | 1144 | info["type"] = type | ||
1557 | 1145 | info["size"] = len(name) | ||
1558 | 1146 | info["magic"] = GNU_MAGIC | ||
1559 | 1147 | |||
1560 | 1148 | # create extended header + name blocks. | ||
1561 | 1149 | return cls._create_header(info, USTAR_FORMAT) + \ | ||
1562 | 1150 | cls._create_payload(name) | ||
1563 | 1151 | |||
1564 | 1152 | @classmethod | ||
1565 | 1153 | def _create_pax_generic_header(cls, pax_headers, type=XHDTYPE): | ||
1566 | 1154 | """Return a POSIX.1-2001 extended or global header sequence | ||
1567 | 1155 | that contains a list of keyword, value pairs. The values | ||
1568 | 1156 | must be unicode objects. | ||
1569 | 1157 | """ | ||
1570 | 1158 | records = [] | ||
1571 | 1159 | for keyword, value in pax_headers.iteritems(): | ||
1572 | 1160 | keyword = keyword.encode("utf8") | ||
1573 | 1161 | value = value.encode("utf8") | ||
1574 | 1162 | l = len(keyword) + len(value) + 3 # ' ' + '=' + '\n' | ||
1575 | 1163 | n = p = 0 | ||
1576 | 1164 | while True: | ||
1577 | 1165 | n = l + len(str(p)) | ||
1578 | 1166 | if n == p: | ||
1579 | 1167 | break | ||
1580 | 1168 | p = n | ||
1581 | 1169 | records.append("%d %s=%s\n" % (p, keyword, value)) | ||
1582 | 1170 | records = "".join(records) | ||
1583 | 1171 | |||
1584 | 1172 | # We use a hardcoded "././@PaxHeader" name like star does | ||
1585 | 1173 | # instead of the one that POSIX recommends. | ||
1586 | 1174 | info = {} | ||
1587 | 1175 | info["name"] = "././@PaxHeader" | ||
1588 | 1176 | info["type"] = type | ||
1589 | 1177 | info["size"] = len(records) | ||
1590 | 1178 | info["magic"] = POSIX_MAGIC | ||
1591 | 1179 | |||
1592 | 1180 | # Create pax header + record blocks. | ||
1593 | 1181 | return cls._create_header(info, USTAR_FORMAT) + \ | ||
1594 | 1182 | cls._create_payload(records) | ||
1595 | 1183 | |||
1596 | 1184 | @classmethod | ||
1597 | 1185 | def frombuf(cls, buf): | ||
1598 | 1186 | """Construct a TarInfo object from a 512 byte string buffer. | ||
1599 | 1187 | """ | ||
1600 | 1188 | if len(buf) == 0: | ||
1601 | 1189 | raise EmptyHeaderError("empty header") | ||
1602 | 1190 | if len(buf) != BLOCKSIZE: | ||
1603 | 1191 | raise TruncatedHeaderError("truncated header") | ||
1604 | 1192 | if buf.count(NUL) == BLOCKSIZE: | ||
1605 | 1193 | raise EOFHeaderError("end of file header") | ||
1606 | 1194 | |||
1607 | 1195 | chksum = nti(buf[148:156]) | ||
1608 | 1196 | if chksum not in calc_chksums(buf): | ||
1609 | 1197 | raise InvalidHeaderError("bad checksum") | ||
1610 | 1198 | |||
1611 | 1199 | obj = cls() | ||
1612 | 1200 | obj.buf = buf | ||
1613 | 1201 | obj.name = nts(buf[0:100]) | ||
1614 | 1202 | obj.mode = nti(buf[100:108]) | ||
1615 | 1203 | obj.uid = nti(buf[108:116]) | ||
1616 | 1204 | obj.gid = nti(buf[116:124]) | ||
1617 | 1205 | obj.size = nti(buf[124:136]) | ||
1618 | 1206 | obj.mtime = nti(buf[136:148]) | ||
1619 | 1207 | obj.chksum = chksum | ||
1620 | 1208 | obj.type = buf[156:157] | ||
1621 | 1209 | obj.linkname = nts(buf[157:257]) | ||
1622 | 1210 | obj.uname = nts(buf[265:297]) | ||
1623 | 1211 | obj.gname = nts(buf[297:329]) | ||
1624 | 1212 | obj.devmajor = nti(buf[329:337]) | ||
1625 | 1213 | obj.devminor = nti(buf[337:345]) | ||
1626 | 1214 | prefix = nts(buf[345:500]) | ||
1627 | 1215 | |||
1628 | 1216 | # Old V7 tar format represents a directory as a regular | ||
1629 | 1217 | # file with a trailing slash. | ||
1630 | 1218 | if obj.type == AREGTYPE and obj.name.endswith("/"): | ||
1631 | 1219 | obj.type = DIRTYPE | ||
1632 | 1220 | |||
1633 | 1221 | # Remove redundant slashes from directories. | ||
1634 | 1222 | if obj.isdir(): | ||
1635 | 1223 | obj.name = obj.name.rstrip("/") | ||
1636 | 1224 | |||
1637 | 1225 | # Reconstruct a ustar longname. | ||
1638 | 1226 | if prefix and obj.type not in GNU_TYPES: | ||
1639 | 1227 | obj.name = prefix + "/" + obj.name | ||
1640 | 1228 | return obj | ||
1641 | 1229 | |||
1642 | 1230 | @classmethod | ||
1643 | 1231 | def fromtarfile(cls, tarfile): | ||
1644 | 1232 | """Return the next TarInfo object from TarFile object | ||
1645 | 1233 | tarfile. | ||
1646 | 1234 | """ | ||
1647 | 1235 | buf = tarfile.fileobj.read(BLOCKSIZE) | ||
1648 | 1236 | obj = cls.frombuf(buf) | ||
1649 | 1237 | obj.offset = tarfile.fileobj.tell() - BLOCKSIZE | ||
1650 | 1238 | return obj._proc_member(tarfile) | ||
1651 | 1239 | |||
1652 | 1240 | #-------------------------------------------------------------------------- | ||
1653 | 1241 | # The following are methods that are called depending on the type of a | ||
1654 | 1242 | # member. The entry point is _proc_member() which can be overridden in a | ||
1655 | 1243 | # subclass to add custom _proc_*() methods. A _proc_*() method MUST | ||
1656 | 1244 | # implement the following | ||
1657 | 1245 | # operations: | ||
1658 | 1246 | # 1. Set self.offset_data to the position where the data blocks begin, | ||
1659 | 1247 | # if there is data that follows. | ||
1660 | 1248 | # 2. Set tarfile.offset to the position where the next member's header will | ||
1661 | 1249 | # begin. | ||
1662 | 1250 | # 3. Return self or another valid TarInfo object. | ||
1663 | 1251 | def _proc_member(self, tarfile): | ||
1664 | 1252 | """Choose the right processing method depending on | ||
1665 | 1253 | the type and call it. | ||
1666 | 1254 | """ | ||
1667 | 1255 | if self.type in (GNUTYPE_LONGNAME, GNUTYPE_LONGLINK): | ||
1668 | 1256 | return self._proc_gnulong(tarfile) | ||
1669 | 1257 | elif self.type == GNUTYPE_SPARSE: | ||
1670 | 1258 | return self._proc_sparse(tarfile) | ||
1671 | 1259 | elif self.type in (XHDTYPE, XGLTYPE, SOLARIS_XHDTYPE): | ||
1672 | 1260 | return self._proc_pax(tarfile) | ||
1673 | 1261 | else: | ||
1674 | 1262 | return self._proc_builtin(tarfile) | ||
1675 | 1263 | |||
1676 | 1264 | def _proc_builtin(self, tarfile): | ||
1677 | 1265 | """Process a builtin type or an unknown type which | ||
1678 | 1266 | will be treated as a regular file. | ||
1679 | 1267 | """ | ||
1680 | 1268 | self.offset_data = tarfile.fileobj.tell() | ||
1681 | 1269 | offset = self.offset_data | ||
1682 | 1270 | if self.isreg() or self.type not in SUPPORTED_TYPES: | ||
1683 | 1271 | # Skip the following data blocks. | ||
1684 | 1272 | offset += self._block(self.size) | ||
1685 | 1273 | tarfile.offset = offset | ||
1686 | 1274 | |||
1687 | 1275 | # Patch the TarInfo object with saved global | ||
1688 | 1276 | # header information. | ||
1689 | 1277 | self._apply_pax_info(tarfile.pax_headers, tarfile.encoding, tarfile.errors) | ||
1690 | 1278 | |||
1691 | 1279 | return self | ||
1692 | 1280 | |||
1693 | 1281 | def _proc_gnulong(self, tarfile): | ||
1694 | 1282 | """Process the blocks that hold a GNU longname | ||
1695 | 1283 | or longlink member. | ||
1696 | 1284 | """ | ||
1697 | 1285 | buf = tarfile.fileobj.read(self._block(self.size)) | ||
1698 | 1286 | |||
1699 | 1287 | # Fetch the next header and process it. | ||
1700 | 1288 | try: | ||
1701 | 1289 | next = self.fromtarfile(tarfile) | ||
1702 | 1290 | except HeaderError: | ||
1703 | 1291 | raise SubsequentHeaderError("missing or bad subsequent header") | ||
1704 | 1292 | |||
1705 | 1293 | # Patch the TarInfo object from the next header with | ||
1706 | 1294 | # the longname information. | ||
1707 | 1295 | next.offset = self.offset | ||
1708 | 1296 | if self.type == GNUTYPE_LONGNAME: | ||
1709 | 1297 | next.name = nts(buf) | ||
1710 | 1298 | elif self.type == GNUTYPE_LONGLINK: | ||
1711 | 1299 | next.linkname = nts(buf) | ||
1712 | 1300 | |||
1713 | 1301 | return next | ||
1714 | 1302 | |||
1715 | 1303 | def _proc_sparse(self, tarfile): | ||
1716 | 1304 | """Process a GNU sparse header plus extra headers. | ||
1717 | 1305 | """ | ||
1718 | 1306 | buf = self.buf | ||
1719 | 1307 | sp = _ringbuffer() | ||
1720 | 1308 | pos = 386 | ||
1721 | 1309 | lastpos = 0L | ||
1722 | 1310 | realpos = 0L | ||
1723 | 1311 | # There are 4 possible sparse structs in the | ||
1724 | 1312 | # first header. | ||
1725 | 1313 | for i in xrange(4): | ||
1726 | 1314 | try: | ||
1727 | 1315 | offset = nti(buf[pos:pos + 12]) | ||
1728 | 1316 | numbytes = nti(buf[pos + 12:pos + 24]) | ||
1729 | 1317 | except ValueError: | ||
1730 | 1318 | break | ||
1731 | 1319 | if offset > lastpos: | ||
1732 | 1320 | sp.append(_hole(lastpos, offset - lastpos)) | ||
1733 | 1321 | sp.append(_data(offset, numbytes, realpos)) | ||
1734 | 1322 | realpos += numbytes | ||
1735 | 1323 | lastpos = offset + numbytes | ||
1736 | 1324 | pos += 24 | ||
1737 | 1325 | |||
1738 | 1326 | isextended = ord(buf[482]) | ||
1739 | 1327 | origsize = nti(buf[483:495]) | ||
1740 | 1328 | |||
1741 | 1329 | # If the isextended flag is given, | ||
1742 | 1330 | # there are extra headers to process. | ||
1743 | 1331 | while isextended == 1: | ||
1744 | 1332 | buf = tarfile.fileobj.read(BLOCKSIZE) | ||
1745 | 1333 | pos = 0 | ||
1746 | 1334 | for i in xrange(21): | ||
1747 | 1335 | try: | ||
1748 | 1336 | offset = nti(buf[pos:pos + 12]) | ||
1749 | 1337 | numbytes = nti(buf[pos + 12:pos + 24]) | ||
1750 | 1338 | except ValueError: | ||
1751 | 1339 | break | ||
1752 | 1340 | if offset > lastpos: | ||
1753 | 1341 | sp.append(_hole(lastpos, offset - lastpos)) | ||
1754 | 1342 | sp.append(_data(offset, numbytes, realpos)) | ||
1755 | 1343 | realpos += numbytes | ||
1756 | 1344 | lastpos = offset + numbytes | ||
1757 | 1345 | pos += 24 | ||
1758 | 1346 | isextended = ord(buf[504]) | ||
1759 | 1347 | |||
1760 | 1348 | if lastpos < origsize: | ||
1761 | 1349 | sp.append(_hole(lastpos, origsize - lastpos)) | ||
1762 | 1350 | |||
1763 | 1351 | self.sparse = sp | ||
1764 | 1352 | |||
1765 | 1353 | self.offset_data = tarfile.fileobj.tell() | ||
1766 | 1354 | tarfile.offset = self.offset_data + self._block(self.size) | ||
1767 | 1355 | self.size = origsize | ||
1768 | 1356 | |||
1769 | 1357 | return self | ||
1770 | 1358 | |||
1771 | 1359 | def _proc_pax(self, tarfile): | ||
1772 | 1360 | """Process an extended or global header as described in | ||
1773 | 1361 | POSIX.1-2001. | ||
1774 | 1362 | """ | ||
1775 | 1363 | # Read the header information. | ||
1776 | 1364 | buf = tarfile.fileobj.read(self._block(self.size)) | ||
1777 | 1365 | |||
1778 | 1366 | # A pax header stores supplemental information for either | ||
1779 | 1367 | # the following file (extended) or all following files | ||
1780 | 1368 | # (global). | ||
1781 | 1369 | if self.type == XGLTYPE: | ||
1782 | 1370 | pax_headers = tarfile.pax_headers | ||
1783 | 1371 | else: | ||
1784 | 1372 | pax_headers = tarfile.pax_headers.copy() | ||
1785 | 1373 | |||
1786 | 1374 | # Parse pax header information. A record looks like that: | ||
1787 | 1375 | # "%d %s=%s\n" % (length, keyword, value). length is the size | ||
1788 | 1376 | # of the complete record including the length field itself and | ||
1789 | 1377 | # the newline. keyword and value are both UTF-8 encoded strings. | ||
1790 | 1378 | regex = re.compile(r"(\d+) ([^=]+)=", re.U) | ||
1791 | 1379 | pos = 0 | ||
1792 | 1380 | while True: | ||
1793 | 1381 | match = regex.match(buf, pos) | ||
1794 | 1382 | if not match: | ||
1795 | 1383 | break | ||
1796 | 1384 | |||
1797 | 1385 | length, keyword = match.groups() | ||
1798 | 1386 | length = int(length) | ||
1799 | 1387 | value = buf[match.end(2) + 1:match.start(1) + length - 1] | ||
1800 | 1388 | |||
1801 | 1389 | keyword = keyword.decode("utf8") | ||
1802 | 1390 | value = value.decode("utf8") | ||
1803 | 1391 | |||
1804 | 1392 | pax_headers[keyword] = value | ||
1805 | 1393 | pos += length | ||
1806 | 1394 | |||
1807 | 1395 | # Fetch the next header. | ||
1808 | 1396 | try: | ||
1809 | 1397 | next = self.fromtarfile(tarfile) | ||
1810 | 1398 | except HeaderError: | ||
1811 | 1399 | raise SubsequentHeaderError("missing or bad subsequent header") | ||
1812 | 1400 | |||
1813 | 1401 | if self.type in (XHDTYPE, SOLARIS_XHDTYPE): | ||
1814 | 1402 | # Patch the TarInfo object with the extended header info. | ||
1815 | 1403 | next._apply_pax_info(pax_headers, tarfile.encoding, tarfile.errors) | ||
1816 | 1404 | next.offset = self.offset | ||
1817 | 1405 | |||
1818 | 1406 | if "size" in pax_headers: | ||
1819 | 1407 | # If the extended header replaces the size field, | ||
1820 | 1408 | # we need to recalculate the offset where the next | ||
1821 | 1409 | # header starts. | ||
1822 | 1410 | offset = next.offset_data | ||
1823 | 1411 | if next.isreg() or next.type not in SUPPORTED_TYPES: | ||
1824 | 1412 | offset += next._block(next.size) | ||
1825 | 1413 | tarfile.offset = offset | ||
1826 | 1414 | |||
1827 | 1415 | return next | ||
1828 | 1416 | |||
1829 | 1417 | def _apply_pax_info(self, pax_headers, encoding, errors): | ||
1830 | 1418 | """Replace fields with supplemental information from a previous | ||
1831 | 1419 | pax extended or global header. | ||
1832 | 1420 | """ | ||
1833 | 1421 | for keyword, value in pax_headers.iteritems(): | ||
1834 | 1422 | if keyword not in PAX_FIELDS: | ||
1835 | 1423 | continue | ||
1836 | 1424 | |||
1837 | 1425 | if keyword == "path": | ||
1838 | 1426 | value = value.rstrip("/") | ||
1839 | 1427 | |||
1840 | 1428 | if keyword in PAX_NUMBER_FIELDS: | ||
1841 | 1429 | try: | ||
1842 | 1430 | value = PAX_NUMBER_FIELDS[keyword](value) | ||
1843 | 1431 | except ValueError: | ||
1844 | 1432 | value = 0 | ||
1845 | 1433 | else: | ||
1846 | 1434 | value = uts(value, encoding, errors) | ||
1847 | 1435 | |||
1848 | 1436 | setattr(self, keyword, value) | ||
1849 | 1437 | |||
1850 | 1438 | self.pax_headers = pax_headers.copy() | ||
1851 | 1439 | |||
1852 | 1440 | def _block(self, count): | ||
1853 | 1441 | """Round up a byte count by BLOCKSIZE and return it, | ||
1854 | 1442 | e.g. _block(834) => 1024. | ||
1855 | 1443 | """ | ||
1856 | 1444 | blocks, remainder = divmod(count, BLOCKSIZE) | ||
1857 | 1445 | if remainder: | ||
1858 | 1446 | blocks += 1 | ||
1859 | 1447 | return blocks * BLOCKSIZE | ||
1860 | 1448 | |||
1861 | 1449 | def isreg(self): | ||
1862 | 1450 | return self.type in REGULAR_TYPES | ||
1863 | 1451 | def isfile(self): | ||
1864 | 1452 | return self.isreg() | ||
1865 | 1453 | def isdir(self): | ||
1866 | 1454 | return self.type == DIRTYPE | ||
1867 | 1455 | def issym(self): | ||
1868 | 1456 | return self.type == SYMTYPE | ||
1869 | 1457 | def islnk(self): | ||
1870 | 1458 | return self.type == LNKTYPE | ||
1871 | 1459 | def ischr(self): | ||
1872 | 1460 | return self.type == CHRTYPE | ||
1873 | 1461 | def isblk(self): | ||
1874 | 1462 | return self.type == BLKTYPE | ||
1875 | 1463 | def isfifo(self): | ||
1876 | 1464 | return self.type == FIFOTYPE | ||
1877 | 1465 | def issparse(self): | ||
1878 | 1466 | return self.type == GNUTYPE_SPARSE | ||
1879 | 1467 | def isdev(self): | ||
1880 | 1468 | return self.type in (CHRTYPE, BLKTYPE, FIFOTYPE) | ||
1881 | 1469 | # class TarInfo | ||
1882 | 1470 | |||
1883 | 1471 | class TarFile(object): | ||
1884 | 1472 | """The TarFile Class provides an interface to tar archives. | ||
1885 | 1473 | """ | ||
1886 | 1474 | |||
1887 | 1475 | debug = 0 # May be set from 0 (no msgs) to 3 (all msgs) | ||
1888 | 1476 | |||
1889 | 1477 | dereference = False # If true, add content of linked file to the | ||
1890 | 1478 | # tar file, else the link. | ||
1891 | 1479 | |||
1892 | 1480 | ignore_zeros = False # If true, skips empty or invalid blocks and | ||
1893 | 1481 | # continues processing. | ||
1894 | 1482 | |||
1895 | 1483 | errorlevel = 1 # If 0, fatal errors only appear in debug | ||
1896 | 1484 | # messages (if debug >= 0). If > 0, errors | ||
1897 | 1485 | # are passed to the caller as exceptions. | ||
1898 | 1486 | |||
1899 | 1487 | format = DEFAULT_FORMAT # The format to use when creating an archive. | ||
1900 | 1488 | |||
1901 | 1489 | encoding = ENCODING # Encoding for 8-bit character strings. | ||
1902 | 1490 | |||
1903 | 1491 | errors = None # Error handler for unicode conversion. | ||
1904 | 1492 | |||
1905 | 1493 | tarinfo = TarInfo # The default TarInfo class to use. | ||
1906 | 1494 | |||
1907 | 1495 | fileobject = ExFileObject # The default ExFileObject class to use. | ||
1908 | 1496 | |||
1909 | 1497 | def __init__(self, name=None, mode="r", fileobj=None, format=None, | ||
1910 | 1498 | tarinfo=None, dereference=None, ignore_zeros=None, encoding=None, | ||
1911 | 1499 | errors=None, pax_headers=None, debug=None, errorlevel=None): | ||
1912 | 1500 | """Open an (uncompressed) tar archive `name'. `mode' is either 'r' to | ||
1913 | 1501 | read from an existing archive, 'a' to append data to an existing | ||
1914 | 1502 | file or 'w' to create a new file overwriting an existing one. `mode' | ||
1915 | 1503 | defaults to 'r'. | ||
1916 | 1504 | If `fileobj' is given, it is used for reading or writing data. If it | ||
1917 | 1505 | can be determined, `mode' is overridden by `fileobj's mode. | ||
1918 | 1506 | `fileobj' is not closed, when TarFile is closed. | ||
1919 | 1507 | """ | ||
1920 | 1508 | if len(mode) > 1 or mode not in "raw": | ||
1921 | 1509 | raise ValueError("mode must be 'r', 'a' or 'w'") | ||
1922 | 1510 | self.mode = mode | ||
1923 | 1511 | self._mode = {"r": "rb", "a": "r+b", "w": "wb"}[mode] | ||
1924 | 1512 | |||
1925 | 1513 | if not fileobj: | ||
1926 | 1514 | if self.mode == "a" and not os.path.exists(name): | ||
1927 | 1515 | # Create nonexistent files in append mode. | ||
1928 | 1516 | self.mode = "w" | ||
1929 | 1517 | self._mode = "wb" | ||
1930 | 1518 | fileobj = bltn_open(name, self._mode) | ||
1931 | 1519 | self._extfileobj = False | ||
1932 | 1520 | else: | ||
1933 | 1521 | if name is None and hasattr(fileobj, "name"): | ||
1934 | 1522 | name = fileobj.name | ||
1935 | 1523 | if hasattr(fileobj, "mode"): | ||
1936 | 1524 | self._mode = fileobj.mode | ||
1937 | 1525 | self._extfileobj = True | ||
1938 | 1526 | if name: | ||
1939 | 1527 | self.name = os.path.abspath(name) | ||
1940 | 1528 | else: | ||
1941 | 1529 | self.name = None | ||
1942 | 1530 | self.fileobj = fileobj | ||
1943 | 1531 | |||
1944 | 1532 | # Init attributes. | ||
1945 | 1533 | if format is not None: | ||
1946 | 1534 | self.format = format | ||
1947 | 1535 | if tarinfo is not None: | ||
1948 | 1536 | self.tarinfo = tarinfo | ||
1949 | 1537 | if dereference is not None: | ||
1950 | 1538 | self.dereference = dereference | ||
1951 | 1539 | if ignore_zeros is not None: | ||
1952 | 1540 | self.ignore_zeros = ignore_zeros | ||
1953 | 1541 | if encoding is not None: | ||
1954 | 1542 | self.encoding = encoding | ||
1955 | 1543 | |||
1956 | 1544 | if errors is not None: | ||
1957 | 1545 | self.errors = errors | ||
1958 | 1546 | elif mode == "r": | ||
1959 | 1547 | self.errors = "utf-8" | ||
1960 | 1548 | else: | ||
1961 | 1549 | self.errors = "strict" | ||
1962 | 1550 | |||
1963 | 1551 | if pax_headers is not None and self.format == PAX_FORMAT: | ||
1964 | 1552 | self.pax_headers = pax_headers | ||
1965 | 1553 | else: | ||
1966 | 1554 | self.pax_headers = {} | ||
1967 | 1555 | |||
1968 | 1556 | if debug is not None: | ||
1969 | 1557 | self.debug = debug | ||
1970 | 1558 | if errorlevel is not None: | ||
1971 | 1559 | self.errorlevel = errorlevel | ||
1972 | 1560 | |||
1973 | 1561 | # Init datastructures. | ||
1974 | 1562 | self.closed = False | ||
1975 | 1563 | self.members = [] # list of members as TarInfo objects | ||
1976 | 1564 | self._loaded = False # flag if all members have been read | ||
1977 | 1565 | self.offset = self.fileobj.tell() | ||
1978 | 1566 | # current position in the archive file | ||
1979 | 1567 | self.inodes = {} # dictionary caching the inodes of | ||
1980 | 1568 | # archive members already added | ||
1981 | 1569 | |||
1982 | 1570 | try: | ||
1983 | 1571 | if self.mode == "r": | ||
1984 | 1572 | self.firstmember = None | ||
1985 | 1573 | self.firstmember = self.next() | ||
1986 | 1574 | |||
1987 | 1575 | if self.mode == "a": | ||
1988 | 1576 | # Move to the end of the archive, | ||
1989 | 1577 | # before the first empty block. | ||
1990 | 1578 | while True: | ||
1991 | 1579 | self.fileobj.seek(self.offset) | ||
1992 | 1580 | try: | ||
1993 | 1581 | tarinfo = self.tarinfo.fromtarfile(self) | ||
1994 | 1582 | self.members.append(tarinfo) | ||
1995 | 1583 | except EOFHeaderError: | ||
1996 | 1584 | self.fileobj.seek(self.offset) | ||
1997 | 1585 | break | ||
1998 | 1586 | except HeaderError, e: | ||
1999 | 1587 | raise ReadError(str(e)) | ||
2000 | 1588 | |||
2001 | 1589 | if self.mode in "aw": | ||
2002 | 1590 | self._loaded = True | ||
2003 | 1591 | |||
2004 | 1592 | if self.pax_headers: | ||
2005 | 1593 | buf = self.tarinfo.create_pax_global_header(self.pax_headers.copy()) | ||
2006 | 1594 | self.fileobj.write(buf) | ||
2007 | 1595 | self.offset += len(buf) | ||
2008 | 1596 | except: | ||
2009 | 1597 | if not self._extfileobj: | ||
2010 | 1598 | self.fileobj.close() | ||
2011 | 1599 | self.closed = True | ||
2012 | 1600 | raise | ||
2013 | 1601 | |||
2014 | 1602 | def _getposix(self): | ||
2015 | 1603 | return self.format == USTAR_FORMAT | ||
2016 | 1604 | def _setposix(self, value): | ||
2017 | 1605 | import warnings | ||
2018 | 1606 | warnings.warn("use the format attribute instead", DeprecationWarning, | ||
2019 | 1607 | 2) | ||
2020 | 1608 | if value: | ||
2021 | 1609 | self.format = USTAR_FORMAT | ||
2022 | 1610 | else: | ||
2023 | 1611 | self.format = GNU_FORMAT | ||
2024 | 1612 | posix = property(_getposix, _setposix) | ||
2025 | 1613 | |||
2026 | 1614 | #-------------------------------------------------------------------------- | ||
2027 | 1615 | # Below are the classmethods which act as alternate constructors to the | ||
2028 | 1616 | # TarFile class. The open() method is the only one that is needed for | ||
2029 | 1617 | # public use; it is the "super"-constructor and is able to select an | ||
2030 | 1618 | # adequate "sub"-constructor for a particular compression using the mapping | ||
2031 | 1619 | # from OPEN_METH. | ||
2032 | 1620 | # | ||
2033 | 1621 | # This concept allows one to subclass TarFile without losing the comfort of | ||
2034 | 1622 | # the super-constructor. A sub-constructor is registered and made available | ||
2035 | 1623 | # by adding it to the mapping in OPEN_METH. | ||
2036 | 1624 | |||
2037 | 1625 | @classmethod | ||
2038 | 1626 | def open(cls, name=None, mode="r", fileobj=None, bufsize=RECORDSIZE, **kwargs): | ||
2039 | 1627 | """Open a tar archive for reading, writing or appending. Return | ||
2040 | 1628 | an appropriate TarFile class. | ||
2041 | 1629 | |||
2042 | 1630 | mode: | ||
2043 | 1631 | 'r' or 'r:*' open for reading with transparent compression | ||
2044 | 1632 | 'r:' open for reading exclusively uncompressed | ||
2045 | 1633 | 'r:gz' open for reading with gzip compression | ||
2046 | 1634 | 'r:bz2' open for reading with bzip2 compression | ||
2047 | 1635 | 'a' or 'a:' open for appending, creating the file if necessary | ||
2048 | 1636 | 'w' or 'w:' open for writing without compression | ||
2049 | 1637 | 'w:gz' open for writing with gzip compression | ||
2050 | 1638 | 'w:bz2' open for writing with bzip2 compression | ||
2051 | 1639 | |||
2052 | 1640 | 'r|*' open a stream of tar blocks with transparent compression | ||
2053 | 1641 | 'r|' open an uncompressed stream of tar blocks for reading | ||
2054 | 1642 | 'r|gz' open a gzip compressed stream of tar blocks | ||
2055 | 1643 | 'r|bz2' open a bzip2 compressed stream of tar blocks | ||
2056 | 1644 | 'w|' open an uncompressed stream for writing | ||
2057 | 1645 | 'w|gz' open a gzip compressed stream for writing | ||
2058 | 1646 | 'w|bz2' open a bzip2 compressed stream for writing | ||
2059 | 1647 | """ | ||
2060 | 1648 | |||
2061 | 1649 | if not name and not fileobj: | ||
2062 | 1650 | raise ValueError("nothing to open") | ||
2063 | 1651 | |||
2064 | 1652 | if mode in ("r", "r:*"): | ||
2065 | 1653 | # Find out which *open() is appropriate for opening the file. | ||
2066 | 1654 | for comptype in cls.OPEN_METH: | ||
2067 | 1655 | func = getattr(cls, cls.OPEN_METH[comptype]) | ||
2068 | 1656 | if fileobj is not None: | ||
2069 | 1657 | saved_pos = fileobj.tell() | ||
2070 | 1658 | try: | ||
2071 | 1659 | return func(name, "r", fileobj, **kwargs) | ||
2072 | 1660 | except (ReadError, CompressionError), e: | ||
2073 | 1661 | if fileobj is not None: | ||
2074 | 1662 | fileobj.seek(saved_pos) | ||
2075 | 1663 | continue | ||
2076 | 1664 | raise ReadError("file could not be opened successfully") | ||
2077 | 1665 | |||
2078 | 1666 | elif ":" in mode: | ||
2079 | 1667 | filemode, comptype = mode.split(":", 1) | ||
2080 | 1668 | filemode = filemode or "r" | ||
2081 | 1669 | comptype = comptype or "tar" | ||
2082 | 1670 | |||
2083 | 1671 | # Select the *open() function according to | ||
2084 | 1672 | # given compression. | ||
2085 | 1673 | if comptype in cls.OPEN_METH: | ||
2086 | 1674 | func = getattr(cls, cls.OPEN_METH[comptype]) | ||
2087 | 1675 | else: | ||
2088 | 1676 | raise CompressionError("unknown compression type %r" % comptype) | ||
2089 | 1677 | return func(name, filemode, fileobj, **kwargs) | ||
2090 | 1678 | |||
2091 | 1679 | elif "|" in mode: | ||
2092 | 1680 | filemode, comptype = mode.split("|", 1) | ||
2093 | 1681 | filemode = filemode or "r" | ||
2094 | 1682 | comptype = comptype or "tar" | ||
2095 | 1683 | |||
2096 | 1684 | if filemode not in "rw": | ||
2097 | 1685 | raise ValueError("mode must be 'r' or 'w'") | ||
2098 | 1686 | |||
2099 | 1687 | t = cls(name, filemode, | ||
2100 | 1688 | _Stream(name, filemode, comptype, fileobj, bufsize), | ||
2101 | 1689 | **kwargs) | ||
2102 | 1690 | t._extfileobj = False | ||
2103 | 1691 | return t | ||
2104 | 1692 | |||
2105 | 1693 | elif mode in "aw": | ||
2106 | 1694 | return cls.taropen(name, mode, fileobj, **kwargs) | ||
2107 | 1695 | |||
2108 | 1696 | raise ValueError("undiscernible mode") | ||
2109 | 1697 | |||
2110 | 1698 | @classmethod | ||
2111 | 1699 | def taropen(cls, name, mode="r", fileobj=None, **kwargs): | ||
2112 | 1700 | """Open uncompressed tar archive name for reading or writing. | ||
2113 | 1701 | """ | ||
2114 | 1702 | if len(mode) > 1 or mode not in "raw": | ||
2115 | 1703 | raise ValueError("mode must be 'r', 'a' or 'w'") | ||
2116 | 1704 | return cls(name, mode, fileobj, **kwargs) | ||
2117 | 1705 | |||
2118 | 1706 | @classmethod | ||
2119 | 1707 | def gzopen(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs): | ||
2120 | 1708 | """Open gzip compressed tar archive name for reading or writing. | ||
2121 | 1709 | Appending is not allowed. | ||
2122 | 1710 | """ | ||
2123 | 1711 | if len(mode) > 1 or mode not in "rw": | ||
2124 | 1712 | raise ValueError("mode must be 'r' or 'w'") | ||
2125 | 1713 | |||
2126 | 1714 | try: | ||
2127 | 1715 | import gzip | ||
2128 | 1716 | gzip.GzipFile | ||
2129 | 1717 | except (ImportError, AttributeError): | ||
2130 | 1718 | raise CompressionError("gzip module is not available") | ||
2131 | 1719 | |||
2132 | 1720 | if fileobj is None: | ||
2133 | 1721 | fileobj = bltn_open(name, mode + "b") | ||
2134 | 1722 | |||
2135 | 1723 | try: | ||
2136 | 1724 | t = cls.taropen(name, mode, | ||
2137 | 1725 | gzip.GzipFile(name, mode, compresslevel, fileobj), | ||
2138 | 1726 | **kwargs) | ||
2139 | 1727 | except IOError: | ||
2140 | 1728 | raise ReadError("not a gzip file") | ||
2141 | 1729 | t._extfileobj = False | ||
2142 | 1730 | return t | ||
2143 | 1731 | |||
2144 | 1732 | @classmethod | ||
2145 | 1733 | def bz2open(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs): | ||
2146 | 1734 | """Open bzip2 compressed tar archive name for reading or writing. | ||
2147 | 1735 | Appending is not allowed. | ||
2148 | 1736 | """ | ||
2149 | 1737 | if len(mode) > 1 or mode not in "rw": | ||
2150 | 1738 | raise ValueError("mode must be 'r' or 'w'.") | ||
2151 | 1739 | |||
2152 | 1740 | try: | ||
2153 | 1741 | import bz2 | ||
2154 | 1742 | except ImportError: | ||
2155 | 1743 | raise CompressionError("bz2 module is not available") | ||
2156 | 1744 | |||
2157 | 1745 | if fileobj is not None: | ||
2158 | 1746 | fileobj = _BZ2Proxy(fileobj, mode) | ||
2159 | 1747 | else: | ||
2160 | 1748 | fileobj = bz2.BZ2File(name, mode, compresslevel=compresslevel) | ||
2161 | 1749 | |||
2162 | 1750 | try: | ||
2163 | 1751 | t = cls.taropen(name, mode, fileobj, **kwargs) | ||
2164 | 1752 | except (IOError, EOFError): | ||
2165 | 1753 | raise ReadError("not a bzip2 file") | ||
2166 | 1754 | t._extfileobj = False | ||
2167 | 1755 | return t | ||
2168 | 1756 | |||
2169 | 1757 | # All *open() methods are registered here. | ||
2170 | 1758 | OPEN_METH = { | ||
2171 | 1759 | "tar": "taropen", # uncompressed tar | ||
2172 | 1760 | "gz": "gzopen", # gzip compressed tar | ||
2173 | 1761 | "bz2": "bz2open" # bzip2 compressed tar | ||
2174 | 1762 | } | ||
2175 | 1763 | |||
2176 | 1764 | #-------------------------------------------------------------------------- | ||
2177 | 1765 | # The public methods which TarFile provides: | ||
2178 | 1766 | |||
2179 | 1767 | def close(self): | ||
2180 | 1768 | """Close the TarFile. In write-mode, two finishing zero blocks are | ||
2181 | 1769 | appended to the archive. | ||
2182 | 1770 | """ | ||
2183 | 1771 | if self.closed: | ||
2184 | 1772 | return | ||
2185 | 1773 | |||
2186 | 1774 | if self.mode in "aw": | ||
2187 | 1775 | self.fileobj.write(NUL * (BLOCKSIZE * 2)) | ||
2188 | 1776 | self.offset += (BLOCKSIZE * 2) | ||
2189 | 1777 | # fill up the end with zero-blocks | ||
2190 | 1778 | # (like option -b20 for tar does) | ||
2191 | 1779 | blocks, remainder = divmod(self.offset, RECORDSIZE) | ||
2192 | 1780 | if remainder > 0: | ||
2193 | 1781 | self.fileobj.write(NUL * (RECORDSIZE - remainder)) | ||
2194 | 1782 | |||
2195 | 1783 | if not self._extfileobj: | ||
2196 | 1784 | self.fileobj.close() | ||
2197 | 1785 | self.closed = True | ||
2198 | 1786 | |||
2199 | 1787 | def getmember(self, name): | ||
2200 | 1788 | """Return a TarInfo object for member `name'. If `name' can not be | ||
2201 | 1789 | found in the archive, KeyError is raised. If a member occurs more | ||
2202 | 1790 | than once in the archive, its last occurrence is assumed to be the | ||
2203 | 1791 | most up-to-date version. | ||
2204 | 1792 | """ | ||
2205 | 1793 | tarinfo = self._getmember(name) | ||
2206 | 1794 | if tarinfo is None: | ||
2207 | 1795 | raise KeyError("filename %r not found" % name) | ||
2208 | 1796 | return tarinfo | ||
2209 | 1797 | |||
2210 | 1798 | def getmembers(self): | ||
2211 | 1799 | """Return the members of the archive as a list of TarInfo objects. The | ||
2212 | 1800 | list has the same order as the members in the archive. | ||
2213 | 1801 | """ | ||
2214 | 1802 | self._check() | ||
2215 | 1803 | if not self._loaded: # if we want to obtain a list of | ||
2216 | 1804 | self._load() # all members, we first have to | ||
2217 | 1805 | # scan the whole archive. | ||
2218 | 1806 | return self.members | ||
2219 | 1807 | |||
2220 | 1808 | def getnames(self): | ||
2221 | 1809 | """Return the members of the archive as a list of their names. It has | ||
2222 | 1810 | the same order as the list returned by getmembers(). | ||
2223 | 1811 | """ | ||
2224 | 1812 | return [tarinfo.name for tarinfo in self.getmembers()] | ||
2225 | 1813 | |||
2226 | 1814 | def gettarinfo(self, name=None, arcname=None, fileobj=None): | ||
2227 | 1815 | """Create a TarInfo object for either the file `name' or the file | ||
2228 | 1816 | object `fileobj' (using os.fstat on its file descriptor). You can | ||
2229 | 1817 | modify some of the TarInfo's attributes before you add it using | ||
2230 | 1818 | addfile(). If given, `arcname' specifies an alternative name for the | ||
2231 | 1819 | file in the archive. | ||
2232 | 1820 | """ | ||
2233 | 1821 | self._check("aw") | ||
2234 | 1822 | |||
2235 | 1823 | # When fileobj is given, replace name by | ||
2236 | 1824 | # fileobj's real name. | ||
2237 | 1825 | if fileobj is not None: | ||
2238 | 1826 | name = fileobj.name | ||
2239 | 1827 | |||
2240 | 1828 | # Building the name of the member in the archive. | ||
2241 | 1829 | # Backward slashes are converted to forward slashes, | ||
2242 | 1830 | # Absolute paths are turned to relative paths. | ||
2243 | 1831 | if arcname is None: | ||
2244 | 1832 | arcname = name | ||
2245 | 1833 | drv, arcname = os.path.splitdrive(arcname) | ||
2246 | 1834 | arcname = arcname.replace(os.sep, "/") | ||
2247 | 1835 | arcname = arcname.lstrip("/") | ||
2248 | 1836 | |||
2249 | 1837 | # Now, fill the TarInfo object with | ||
2250 | 1838 | # information specific for the file. | ||
2251 | 1839 | tarinfo = self.tarinfo() | ||
2252 | 1840 | tarinfo.tarfile = self | ||
2253 | 1841 | |||
2254 | 1842 | # Use os.stat or os.lstat, depending on platform | ||
2255 | 1843 | # and if symlinks shall be resolved. | ||
2256 | 1844 | if fileobj is None: | ||
2257 | 1845 | if hasattr(os, "lstat") and not self.dereference: | ||
2258 | 1846 | statres = os.lstat(name) | ||
2259 | 1847 | else: | ||
2260 | 1848 | statres = os.stat(name) | ||
2261 | 1849 | else: | ||
2262 | 1850 | statres = os.fstat(fileobj.fileno()) | ||
2263 | 1851 | linkname = "" | ||
2264 | 1852 | |||
2265 | 1853 | stmd = statres.st_mode | ||
2266 | 1854 | if stat.S_ISREG(stmd): | ||
2267 | 1855 | inode = (statres.st_ino, statres.st_dev) | ||
2268 | 1856 | if not self.dereference and statres.st_nlink > 1 and \ | ||
2269 | 1857 | inode in self.inodes and arcname != self.inodes[inode]: | ||
2270 | 1858 | # Is it a hardlink to an already | ||
2271 | 1859 | # archived file? | ||
2272 | 1860 | type = LNKTYPE | ||
2273 | 1861 | linkname = self.inodes[inode] | ||
2274 | 1862 | else: | ||
2275 | 1863 | # The inode is added only if its valid. | ||
2276 | 1864 | # For win32 it is always 0. | ||
2277 | 1865 | type = REGTYPE | ||
2278 | 1866 | if inode[0]: | ||
2279 | 1867 | self.inodes[inode] = arcname | ||
2280 | 1868 | elif stat.S_ISDIR(stmd): | ||
2281 | 1869 | type = DIRTYPE | ||
2282 | 1870 | elif stat.S_ISFIFO(stmd): | ||
2283 | 1871 | type = FIFOTYPE | ||
2284 | 1872 | elif stat.S_ISLNK(stmd): | ||
2285 | 1873 | type = SYMTYPE | ||
2286 | 1874 | linkname = os.readlink(name) | ||
2287 | 1875 | elif stat.S_ISCHR(stmd): | ||
2288 | 1876 | type = CHRTYPE | ||
2289 | 1877 | elif stat.S_ISBLK(stmd): | ||
2290 | 1878 | type = BLKTYPE | ||
2291 | 1879 | else: | ||
2292 | 1880 | return None | ||
2293 | 1881 | |||
2294 | 1882 | # Fill the TarInfo object with all | ||
2295 | 1883 | # information we can get. | ||
2296 | 1884 | tarinfo.name = arcname | ||
2297 | 1885 | tarinfo.mode = stmd | ||
2298 | 1886 | tarinfo.uid = statres.st_uid | ||
2299 | 1887 | tarinfo.gid = statres.st_gid | ||
2300 | 1888 | if type == REGTYPE: | ||
2301 | 1889 | tarinfo.size = statres.st_size | ||
2302 | 1890 | else: | ||
2303 | 1891 | tarinfo.size = 0L | ||
2304 | 1892 | tarinfo.mtime = statres.st_mtime | ||
2305 | 1893 | tarinfo.type = type | ||
2306 | 1894 | tarinfo.linkname = linkname | ||
2307 | 1895 | if pwd: | ||
2308 | 1896 | try: | ||
2309 | 1897 | tarinfo.uname = pwd.getpwuid(tarinfo.uid)[0] | ||
2310 | 1898 | except KeyError: | ||
2311 | 1899 | pass | ||
2312 | 1900 | if grp: | ||
2313 | 1901 | try: | ||
2314 | 1902 | tarinfo.gname = grp.getgrgid(tarinfo.gid)[0] | ||
2315 | 1903 | except KeyError: | ||
2316 | 1904 | pass | ||
2317 | 1905 | |||
2318 | 1906 | if type in (CHRTYPE, BLKTYPE): | ||
2319 | 1907 | if hasattr(os, "major") and hasattr(os, "minor"): | ||
2320 | 1908 | tarinfo.devmajor = os.major(statres.st_rdev) | ||
2321 | 1909 | tarinfo.devminor = os.minor(statres.st_rdev) | ||
2322 | 1910 | return tarinfo | ||
2323 | 1911 | |||
2324 | 1912 | def list(self, verbose=True): | ||
2325 | 1913 | """Print a table of contents to sys.stdout. If `verbose' is False, only | ||
2326 | 1914 | the names of the members are printed. If it is True, an `ls -l'-like | ||
2327 | 1915 | output is produced. | ||
2328 | 1916 | """ | ||
2329 | 1917 | self._check() | ||
2330 | 1918 | |||
2331 | 1919 | for tarinfo in self: | ||
2332 | 1920 | if verbose: | ||
2333 | 1921 | print filemode(tarinfo.mode), | ||
2334 | 1922 | print "%s/%s" % (tarinfo.uname or tarinfo.uid, | ||
2335 | 1923 | tarinfo.gname or tarinfo.gid), | ||
2336 | 1924 | if tarinfo.ischr() or tarinfo.isblk(): | ||
2337 | 1925 | print "%10s" % ("%d,%d" \ | ||
2338 | 1926 | % (tarinfo.devmajor, tarinfo.devminor)), | ||
2339 | 1927 | else: | ||
2340 | 1928 | print "%10d" % tarinfo.size, | ||
2341 | 1929 | print "%d-%02d-%02d %02d:%02d:%02d" \ | ||
2342 | 1930 | % time.localtime(tarinfo.mtime)[:6], | ||
2343 | 1931 | |||
2344 | 1932 | if tarinfo.isdir(): | ||
2345 | 1933 | print tarinfo.name + "/", | ||
2346 | 1934 | else: | ||
2347 | 1935 | print tarinfo.name, | ||
2348 | 1936 | |||
2349 | 1937 | if verbose: | ||
2350 | 1938 | if tarinfo.issym(): | ||
2351 | 1939 | print "->", tarinfo.linkname, | ||
2352 | 1940 | if tarinfo.islnk(): | ||
2353 | 1941 | print "link to", tarinfo.linkname, | ||
2354 | 1942 | |||
2355 | 1943 | |||
2356 | 1944 | def add(self, name, arcname=None, recursive=True, exclude=None, filter=None): | ||
2357 | 1945 | """Add the file `name' to the archive. `name' may be any type of file | ||
2358 | 1946 | (directory, fifo, symbolic link, etc.). If given, `arcname' | ||
2359 | 1947 | specifies an alternative name for the file in the archive. | ||
2360 | 1948 | Directories are added recursively by default. This can be avoided by | ||
2361 | 1949 | setting `recursive' to False. `exclude' is a function that should | ||
2362 | 1950 | return True for each filename to be excluded. `filter' is a function | ||
2363 | 1951 | that expects a TarInfo object argument and returns the changed | ||
2364 | 1952 | TarInfo object, if it returns None the TarInfo object will be | ||
2365 | 1953 | excluded from the archive. | ||
2366 | 1954 | """ | ||
2367 | 1955 | self._check("aw") | ||
2368 | 1956 | |||
2369 | 1957 | if arcname is None: | ||
2370 | 1958 | arcname = name | ||
2371 | 1959 | |||
2372 | 1960 | # Exclude pathnames. | ||
2373 | 1961 | if exclude is not None: | ||
2374 | 1962 | import warnings | ||
2375 | 1963 | warnings.warn("use the filter argument instead", | ||
2376 | 1964 | DeprecationWarning, 2) | ||
2377 | 1965 | if exclude(name): | ||
2378 | 1966 | self._dbg(2, "tarfile: Excluded %r" % name) | ||
2379 | 1967 | return | ||
2380 | 1968 | |||
2381 | 1969 | # Skip if somebody tries to archive the archive... | ||
2382 | 1970 | if self.name is not None and os.path.abspath(name) == self.name: | ||
2383 | 1971 | self._dbg(2, "tarfile: Skipped %r" % name) | ||
2384 | 1972 | return | ||
2385 | 1973 | |||
2386 | 1974 | self._dbg(1, name) | ||
2387 | 1975 | |||
2388 | 1976 | # Create a TarInfo object from the file. | ||
2389 | 1977 | tarinfo = self.gettarinfo(name, arcname) | ||
2390 | 1978 | |||
2391 | 1979 | if tarinfo is None: | ||
2392 | 1980 | self._dbg(1, "tarfile: Unsupported type %r" % name) | ||
2393 | 1981 | return | ||
2394 | 1982 | |||
2395 | 1983 | # Change or exclude the TarInfo object. | ||
2396 | 1984 | if filter is not None: | ||
2397 | 1985 | tarinfo = filter(tarinfo) | ||
2398 | 1986 | if tarinfo is None: | ||
2399 | 1987 | self._dbg(2, "tarfile: Excluded %r" % name) | ||
2400 | 1988 | return | ||
2401 | 1989 | |||
2402 | 1990 | # Append the tar header and data to the archive. | ||
2403 | 1991 | if tarinfo.isreg(): | ||
2404 | 1992 | f = bltn_open(name, "rb") | ||
2405 | 1993 | self.addfile(tarinfo, f) | ||
2406 | 1994 | f.close() | ||
2407 | 1995 | |||
2408 | 1996 | elif tarinfo.isdir(): | ||
2409 | 1997 | self.addfile(tarinfo) | ||
2410 | 1998 | if recursive: | ||
2411 | 1999 | for f in os.listdir(name): | ||
2412 | 2000 | self.add(os.path.join(name, f), os.path.join(arcname, f), | ||
2413 | 2001 | recursive, exclude, filter) | ||
2414 | 2002 | |||
2415 | 2003 | else: | ||
2416 | 2004 | self.addfile(tarinfo) | ||
2417 | 2005 | |||
2418 | 2006 | def addfile(self, tarinfo, fileobj=None): | ||
2419 | 2007 | """Add the TarInfo object `tarinfo' to the archive. If `fileobj' is | ||
2420 | 2008 | given, tarinfo.size bytes are read from it and added to the archive. | ||
2421 | 2009 | You can create TarInfo objects using gettarinfo(). | ||
2422 | 2010 | On Windows platforms, `fileobj' should always be opened with mode | ||
2423 | 2011 | 'rb' to avoid irritation about the file size. | ||
2424 | 2012 | """ | ||
2425 | 2013 | self._check("aw") | ||
2426 | 2014 | |||
2427 | 2015 | tarinfo = copy.copy(tarinfo) | ||
2428 | 2016 | |||
2429 | 2017 | buf = tarinfo.tobuf(self.format, self.encoding, self.errors) | ||
2430 | 2018 | self.fileobj.write(buf) | ||
2431 | 2019 | self.offset += len(buf) | ||
2432 | 2020 | |||
2433 | 2021 | # If there's data to follow, append it. | ||
2434 | 2022 | if fileobj is not None: | ||
2435 | 2023 | copyfileobj(fileobj, self.fileobj, tarinfo.size) | ||
2436 | 2024 | blocks, remainder = divmod(tarinfo.size, BLOCKSIZE) | ||
2437 | 2025 | if remainder > 0: | ||
2438 | 2026 | self.fileobj.write(NUL * (BLOCKSIZE - remainder)) | ||
2439 | 2027 | blocks += 1 | ||
2440 | 2028 | self.offset += blocks * BLOCKSIZE | ||
2441 | 2029 | |||
2442 | 2030 | self.members.append(tarinfo) | ||
2443 | 2031 | |||
2444 | 2032 | def extractall(self, path=".", members=None): | ||
2445 | 2033 | """Extract all members from the archive to the current working | ||
2446 | 2034 | directory and set owner, modification time and permissions on | ||
2447 | 2035 | directories afterwards. `path' specifies a different directory | ||
2448 | 2036 | to extract to. `members' is optional and must be a subset of the | ||
2449 | 2037 | list returned by getmembers(). | ||
2450 | 2038 | """ | ||
2451 | 2039 | directories = [] | ||
2452 | 2040 | |||
2453 | 2041 | if members is None: | ||
2454 | 2042 | members = self | ||
2455 | 2043 | |||
2456 | 2044 | for tarinfo in members: | ||
2457 | 2045 | if tarinfo.isdir(): | ||
2458 | 2046 | # Extract directories with a safe mode. | ||
2459 | 2047 | directories.append(tarinfo) | ||
2460 | 2048 | tarinfo = copy.copy(tarinfo) | ||
2461 | 2049 | tarinfo.mode = 0700 | ||
2462 | 2050 | self.extract(tarinfo, path) | ||
2463 | 2051 | |||
2464 | 2052 | # Reverse sort directories. | ||
2465 | 2053 | directories.sort(key=operator.attrgetter('name')) | ||
2466 | 2054 | directories.reverse() | ||
2467 | 2055 | |||
2468 | 2056 | # Set correct owner, mtime and filemode on directories. | ||
2469 | 2057 | for tarinfo in directories: | ||
2470 | 2058 | dirpath = os.path.join(path, tarinfo.name) | ||
2471 | 2059 | try: | ||
2472 | 2060 | self.chown(tarinfo, dirpath) | ||
2473 | 2061 | self.utime(tarinfo, dirpath) | ||
2474 | 2062 | self.chmod(tarinfo, dirpath) | ||
2475 | 2063 | except ExtractError, e: | ||
2476 | 2064 | if self.errorlevel > 1: | ||
2477 | 2065 | raise | ||
2478 | 2066 | else: | ||
2479 | 2067 | self._dbg(1, "tarfile: %s" % e) | ||
2480 | 2068 | |||
2481 | 2069 | def extract(self, member, path=""): | ||
2482 | 2070 | """Extract a member from the archive to the current working directory, | ||
2483 | 2071 | using its full name. Its file information is extracted as accurately | ||
2484 | 2072 | as possible. `member' may be a filename or a TarInfo object. You can | ||
2485 | 2073 | specify a different directory using `path'. | ||
2486 | 2074 | """ | ||
2487 | 2075 | self._check("r") | ||
2488 | 2076 | |||
2489 | 2077 | if isinstance(member, basestring): | ||
2490 | 2078 | tarinfo = self.getmember(member) | ||
2491 | 2079 | else: | ||
2492 | 2080 | tarinfo = member | ||
2493 | 2081 | |||
2494 | 2082 | # Prepare the link target for makelink(). | ||
2495 | 2083 | if tarinfo.islnk(): | ||
2496 | 2084 | tarinfo._link_target = os.path.join(path, tarinfo.linkname) | ||
2497 | 2085 | |||
2498 | 2086 | try: | ||
2499 | 2087 | self._extract_member(tarinfo, os.path.join(path, tarinfo.name)) | ||
2500 | 2088 | except EnvironmentError, e: | ||
2501 | 2089 | if self.errorlevel > 0: | ||
2502 | 2090 | raise | ||
2503 | 2091 | else: | ||
2504 | 2092 | if e.filename is None: | ||
2505 | 2093 | self._dbg(1, "tarfile: %s" % e.strerror) | ||
2506 | 2094 | else: | ||
2507 | 2095 | self._dbg(1, "tarfile: %s %r" % (e.strerror, e.filename)) | ||
2508 | 2096 | except ExtractError, e: | ||
2509 | 2097 | if self.errorlevel > 1: | ||
2510 | 2098 | raise | ||
2511 | 2099 | else: | ||
2512 | 2100 | self._dbg(1, "tarfile: %s" % e) | ||
2513 | 2101 | |||
2514 | 2102 | def extractfile(self, member): | ||
2515 | 2103 | """Extract a member from the archive as a file object. `member' may be | ||
2516 | 2104 | a filename or a TarInfo object. If `member' is a regular file, a | ||
2517 | 2105 | file-like object is returned. If `member' is a link, a file-like | ||
2518 | 2106 | object is constructed from the link's target. If `member' is none of | ||
2519 | 2107 | the above, None is returned. | ||
2520 | 2108 | The file-like object is read-only and provides the following | ||
2521 | 2109 | methods: read(), readline(), readlines(), seek() and tell() | ||
2522 | 2110 | """ | ||
2523 | 2111 | self._check("r") | ||
2524 | 2112 | |||
2525 | 2113 | if isinstance(member, basestring): | ||
2526 | 2114 | tarinfo = self.getmember(member) | ||
2527 | 2115 | else: | ||
2528 | 2116 | tarinfo = member | ||
2529 | 2117 | |||
2530 | 2118 | if tarinfo.isreg(): | ||
2531 | 2119 | return self.fileobject(self, tarinfo) | ||
2532 | 2120 | |||
2533 | 2121 | elif tarinfo.type not in SUPPORTED_TYPES: | ||
2534 | 2122 | # If a member's type is unknown, it is treated as a | ||
2535 | 2123 | # regular file. | ||
2536 | 2124 | return self.fileobject(self, tarinfo) | ||
2537 | 2125 | |||
2538 | 2126 | elif tarinfo.islnk() or tarinfo.issym(): | ||
2539 | 2127 | if isinstance(self.fileobj, _Stream): | ||
2540 | 2128 | # A small but ugly workaround for the case that someone tries | ||
2541 | 2129 | # to extract a (sym)link as a file-object from a non-seekable | ||
2542 | 2130 | # stream of tar blocks. | ||
2543 | 2131 | raise StreamError("cannot extract (sym)link as file object") | ||
2544 | 2132 | else: | ||
2545 | 2133 | # A (sym)link's file object is its target's file object. | ||
2546 | 2134 | return self.extractfile(self._find_link_target(tarinfo)) | ||
2547 | 2135 | else: | ||
2548 | 2136 | # If there's no data associated with the member (directory, chrdev, | ||
2549 | 2137 | # blkdev, etc.), return None instead of a file object. | ||
2550 | 2138 | return None | ||
2551 | 2139 | |||
2552 | 2140 | def _extract_member(self, tarinfo, targetpath): | ||
2553 | 2141 | """Extract the TarInfo object tarinfo to a physical | ||
2554 | 2142 | file called targetpath. | ||
2555 | 2143 | """ | ||
2556 | 2144 | # Fetch the TarInfo object for the given name | ||
2557 | 2145 | # and build the destination pathname, replacing | ||
2558 | 2146 | # forward slashes to platform specific separators. | ||
2559 | 2147 | targetpath = targetpath.rstrip("/") | ||
2560 | 2148 | targetpath = targetpath.replace("/", os.sep) | ||
2561 | 2149 | |||
2562 | 2150 | # Create all upper directories. | ||
2563 | 2151 | upperdirs = os.path.dirname(targetpath) | ||
2564 | 2152 | if upperdirs and not os.path.exists(upperdirs): | ||
2565 | 2153 | # Create directories that are not part of the archive with | ||
2566 | 2154 | # default permissions. | ||
2567 | 2155 | os.makedirs(upperdirs) | ||
2568 | 2156 | |||
2569 | 2157 | if tarinfo.islnk() or tarinfo.issym(): | ||
2570 | 2158 | self._dbg(1, "%s -> %s" % (tarinfo.name, tarinfo.linkname)) | ||
2571 | 2159 | else: | ||
2572 | 2160 | self._dbg(1, tarinfo.name) | ||
2573 | 2161 | |||
2574 | 2162 | if tarinfo.isreg(): | ||
2575 | 2163 | self.makefile(tarinfo, targetpath) | ||
2576 | 2164 | elif tarinfo.isdir(): | ||
2577 | 2165 | self.makedir(tarinfo, targetpath) | ||
2578 | 2166 | elif tarinfo.isfifo(): | ||
2579 | 2167 | self.makefifo(tarinfo, targetpath) | ||
2580 | 2168 | elif tarinfo.ischr() or tarinfo.isblk(): | ||
2581 | 2169 | self.makedev(tarinfo, targetpath) | ||
2582 | 2170 | elif tarinfo.islnk() or tarinfo.issym(): | ||
2583 | 2171 | self.makelink(tarinfo, targetpath) | ||
2584 | 2172 | elif tarinfo.type not in SUPPORTED_TYPES: | ||
2585 | 2173 | self.makeunknown(tarinfo, targetpath) | ||
2586 | 2174 | else: | ||
2587 | 2175 | self.makefile(tarinfo, targetpath) | ||
2588 | 2176 | |||
2589 | 2177 | self.chown(tarinfo, targetpath) | ||
2590 | 2178 | if not tarinfo.issym(): | ||
2591 | 2179 | self.chmod(tarinfo, targetpath) | ||
2592 | 2180 | self.utime(tarinfo, targetpath) | ||
2593 | 2181 | |||
2594 | 2182 | #-------------------------------------------------------------------------- | ||
2595 | 2183 | # Below are the different file methods. They are called via | ||
2596 | 2184 | # _extract_member() when extract() is called. They can be replaced in a | ||
2597 | 2185 | # subclass to implement other functionality. | ||
2598 | 2186 | |||
2599 | 2187 | def makedir(self, tarinfo, targetpath): | ||
2600 | 2188 | """Make a directory called targetpath. | ||
2601 | 2189 | """ | ||
2602 | 2190 | try: | ||
2603 | 2191 | # Use a safe mode for the directory, the real mode is set | ||
2604 | 2192 | # later in _extract_member(). | ||
2605 | 2193 | os.mkdir(targetpath, 0700) | ||
2606 | 2194 | except EnvironmentError, e: | ||
2607 | 2195 | if e.errno != errno.EEXIST: | ||
2608 | 2196 | raise | ||
2609 | 2197 | |||
2610 | 2198 | def makefile(self, tarinfo, targetpath): | ||
2611 | 2199 | """Make a file called targetpath. | ||
2612 | 2200 | """ | ||
2613 | 2201 | source = self.extractfile(tarinfo) | ||
2614 | 2202 | target = bltn_open(targetpath, "wb") | ||
2615 | 2203 | copyfileobj(source, target) | ||
2616 | 2204 | source.close() | ||
2617 | 2205 | target.close() | ||
2618 | 2206 | |||
2619 | 2207 | def makeunknown(self, tarinfo, targetpath): | ||
2620 | 2208 | """Make a file from a TarInfo object with an unknown type | ||
2621 | 2209 | at targetpath. | ||
2622 | 2210 | """ | ||
2623 | 2211 | self.makefile(tarinfo, targetpath) | ||
2624 | 2212 | self._dbg(1, "tarfile: Unknown file type %r, " \ | ||
2625 | 2213 | "extracted as regular file." % tarinfo.type) | ||
2626 | 2214 | |||
2627 | 2215 | def makefifo(self, tarinfo, targetpath): | ||
2628 | 2216 | """Make a fifo called targetpath. | ||
2629 | 2217 | """ | ||
2630 | 2218 | if hasattr(os, "mkfifo"): | ||
2631 | 2219 | os.mkfifo(targetpath) | ||
2632 | 2220 | else: | ||
2633 | 2221 | raise ExtractError("fifo not supported by system") | ||
2634 | 2222 | |||
2635 | 2223 | def makedev(self, tarinfo, targetpath): | ||
2636 | 2224 | """Make a character or block device called targetpath. | ||
2637 | 2225 | """ | ||
2638 | 2226 | if not hasattr(os, "mknod") or not hasattr(os, "makedev"): | ||
2639 | 2227 | raise ExtractError("special devices not supported by system") | ||
2640 | 2228 | |||
2641 | 2229 | mode = tarinfo.mode | ||
2642 | 2230 | if tarinfo.isblk(): | ||
2643 | 2231 | mode |= stat.S_IFBLK | ||
2644 | 2232 | else: | ||
2645 | 2233 | mode |= stat.S_IFCHR | ||
2646 | 2234 | |||
2647 | 2235 | os.mknod(targetpath, mode, | ||
2648 | 2236 | os.makedev(tarinfo.devmajor, tarinfo.devminor)) | ||
2649 | 2237 | |||
2650 | 2238 | def makelink(self, tarinfo, targetpath): | ||
2651 | 2239 | """Make a (symbolic) link called targetpath. If it cannot be created | ||
2652 | 2240 | (platform limitation), we try to make a copy of the referenced file | ||
2653 | 2241 | instead of a link. | ||
2654 | 2242 | """ | ||
2655 | 2243 | if hasattr(os, "symlink") and hasattr(os, "link"): | ||
2656 | 2244 | # For systems that support symbolic and hard links. | ||
2657 | 2245 | if tarinfo.issym(): | ||
2658 | 2246 | os.symlink(tarinfo.linkname, targetpath) | ||
2659 | 2247 | else: | ||
2660 | 2248 | # See extract(). | ||
2661 | 2249 | if os.path.exists(tarinfo._link_target): | ||
2662 | 2250 | os.link(tarinfo._link_target, targetpath) | ||
2663 | 2251 | else: | ||
2664 | 2252 | self._extract_member(self._find_link_target(tarinfo), targetpath) | ||
2665 | 2253 | else: | ||
2666 | 2254 | try: | ||
2667 | 2255 | self._extract_member(self._find_link_target(tarinfo), targetpath) | ||
2668 | 2256 | except KeyError: | ||
2669 | 2257 | raise ExtractError("unable to resolve link inside archive") | ||
2670 | 2258 | |||
2671 | 2259 | def chown(self, tarinfo, targetpath): | ||
2672 | 2260 | """Set owner of targetpath according to tarinfo. | ||
2673 | 2261 | """ | ||
2674 | 2262 | if pwd and hasattr(os, "geteuid") and os.geteuid() == 0: | ||
2675 | 2263 | # We have to be root to do so. | ||
2676 | 2264 | try: | ||
2677 | 2265 | g = grp.getgrnam(tarinfo.gname)[2] | ||
2678 | 2266 | except KeyError: | ||
2679 | 2267 | try: | ||
2680 | 2268 | g = grp.getgrgid(tarinfo.gid)[2] | ||
2681 | 2269 | except KeyError: | ||
2682 | 2270 | g = os.getgid() | ||
2683 | 2271 | try: | ||
2684 | 2272 | u = pwd.getpwnam(tarinfo.uname)[2] | ||
2685 | 2273 | except KeyError: | ||
2686 | 2274 | try: | ||
2687 | 2275 | u = pwd.getpwuid(tarinfo.uid)[2] | ||
2688 | 2276 | except KeyError: | ||
2689 | 2277 | u = os.getuid() | ||
2690 | 2278 | try: | ||
2691 | 2279 | if tarinfo.issym() and hasattr(os, "lchown"): | ||
2692 | 2280 | os.lchown(targetpath, u, g) | ||
2693 | 2281 | else: | ||
2694 | 2282 | if sys.platform != "os2emx": | ||
2695 | 2283 | os.chown(targetpath, u, g) | ||
2696 | 2284 | except EnvironmentError, e: | ||
2697 | 2285 | raise ExtractError("could not change owner to %d:%d" % (u, g)) | ||
2698 | 2286 | |||
2699 | 2287 | def chmod(self, tarinfo, targetpath): | ||
2700 | 2288 | """Set file permissions of targetpath according to tarinfo. | ||
2701 | 2289 | """ | ||
2702 | 2290 | if hasattr(os, 'chmod'): | ||
2703 | 2291 | try: | ||
2704 | 2292 | os.chmod(targetpath, tarinfo.mode) | ||
2705 | 2293 | except EnvironmentError, e: | ||
2706 | 2294 | raise ExtractError("could not change mode") | ||
2707 | 2295 | |||
2708 | 2296 | def utime(self, tarinfo, targetpath): | ||
2709 | 2297 | """Set modification time of targetpath according to tarinfo. | ||
2710 | 2298 | """ | ||
2711 | 2299 | if not hasattr(os, 'utime'): | ||
2712 | 2300 | return | ||
2713 | 2301 | try: | ||
2714 | 2302 | os.utime(targetpath, (tarinfo.mtime, tarinfo.mtime)) | ||
2715 | 2303 | except EnvironmentError, e: | ||
2716 | 2304 | raise ExtractError("could not change modification time") | ||
2717 | 2305 | |||
2718 | 2306 | #-------------------------------------------------------------------------- | ||
2719 | 2307 | def next(self): | ||
2720 | 2308 | """Return the next member of the archive as a TarInfo object, when | ||
2721 | 2309 | TarFile is opened for reading. Return None if there is no more | ||
2722 | 2310 | available. | ||
2723 | 2311 | """ | ||
2724 | 2312 | self._check("ra") | ||
2725 | 2313 | if self.firstmember is not None: | ||
2726 | 2314 | m = self.firstmember | ||
2727 | 2315 | self.firstmember = None | ||
2728 | 2316 | return m | ||
2729 | 2317 | |||
2730 | 2318 | # Read the next block. | ||
2731 | 2319 | self.fileobj.seek(self.offset) | ||
2732 | 2320 | tarinfo = None | ||
2733 | 2321 | while True: | ||
2734 | 2322 | try: | ||
2735 | 2323 | tarinfo = self.tarinfo.fromtarfile(self) | ||
2736 | 2324 | except EOFHeaderError, e: | ||
2737 | 2325 | if self.ignore_zeros: | ||
2738 | 2326 | self._dbg(2, "0x%X: %s" % (self.offset, e)) | ||
2739 | 2327 | self.offset += BLOCKSIZE | ||
2740 | 2328 | continue | ||
2741 | 2329 | except InvalidHeaderError, e: | ||
2742 | 2330 | if self.ignore_zeros: | ||
2743 | 2331 | self._dbg(2, "0x%X: %s" % (self.offset, e)) | ||
2744 | 2332 | self.offset += BLOCKSIZE | ||
2745 | 2333 | continue | ||
2746 | 2334 | elif self.offset == 0: | ||
2747 | 2335 | raise ReadError(str(e)) | ||
2748 | 2336 | except EmptyHeaderError: | ||
2749 | 2337 | if self.offset == 0: | ||
2750 | 2338 | raise ReadError("empty file") | ||
2751 | 2339 | except TruncatedHeaderError, e: | ||
2752 | 2340 | if self.offset == 0: | ||
2753 | 2341 | raise ReadError(str(e)) | ||
2754 | 2342 | except SubsequentHeaderError, e: | ||
2755 | 2343 | raise ReadError(str(e)) | ||
2756 | 2344 | break | ||
2757 | 2345 | |||
2758 | 2346 | if tarinfo is not None: | ||
2759 | 2347 | self.members.append(tarinfo) | ||
2760 | 2348 | else: | ||
2761 | 2349 | self._loaded = True | ||
2762 | 2350 | |||
2763 | 2351 | return tarinfo | ||
2764 | 2352 | |||
2765 | 2353 | #-------------------------------------------------------------------------- | ||
2766 | 2354 | # Little helper methods: | ||
2767 | 2355 | |||
2768 | 2356 | def _getmember(self, name, tarinfo=None, normalize=False): | ||
2769 | 2357 | """Find an archive member by name from bottom to top. | ||
2770 | 2358 | If tarinfo is given, it is used as the starting point. | ||
2771 | 2359 | """ | ||
2772 | 2360 | # Ensure that all members have been loaded. | ||
2773 | 2361 | members = self.getmembers() | ||
2774 | 2362 | |||
2775 | 2363 | # Limit the member search list up to tarinfo. | ||
2776 | 2364 | if tarinfo is not None: | ||
2777 | 2365 | members = members[:members.index(tarinfo)] | ||
2778 | 2366 | |||
2779 | 2367 | if normalize: | ||
2780 | 2368 | name = os.path.normpath(name) | ||
2781 | 2369 | |||
2782 | 2370 | for member in reversed(members): | ||
2783 | 2371 | if normalize: | ||
2784 | 2372 | member_name = os.path.normpath(member.name) | ||
2785 | 2373 | else: | ||
2786 | 2374 | member_name = member.name | ||
2787 | 2375 | |||
2788 | 2376 | if name == member_name: | ||
2789 | 2377 | return member | ||
2790 | 2378 | |||
2791 | 2379 | def _load(self): | ||
2792 | 2380 | """Read through the entire archive file and look for readable | ||
2793 | 2381 | members. | ||
2794 | 2382 | """ | ||
2795 | 2383 | while True: | ||
2796 | 2384 | tarinfo = self.next() | ||
2797 | 2385 | if tarinfo is None: | ||
2798 | 2386 | break | ||
2799 | 2387 | self._loaded = True | ||
2800 | 2388 | |||
2801 | 2389 | def _check(self, mode=None): | ||
2802 | 2390 | """Check if TarFile is still open, and if the operation's mode | ||
2803 | 2391 | corresponds to TarFile's mode. | ||
2804 | 2392 | """ | ||
2805 | 2393 | if self.closed: | ||
2806 | 2394 | raise IOError("%s is closed" % self.__class__.__name__) | ||
2807 | 2395 | if mode is not None and self.mode not in mode: | ||
2808 | 2396 | raise IOError("bad operation for mode %r" % self.mode) | ||
2809 | 2397 | |||
2810 | 2398 | def _find_link_target(self, tarinfo): | ||
2811 | 2399 | """Find the target member of a symlink or hardlink member in the | ||
2812 | 2400 | archive. | ||
2813 | 2401 | """ | ||
2814 | 2402 | if tarinfo.issym(): | ||
2815 | 2403 | # Always search the entire archive. | ||
2816 | 2404 | linkname = os.path.dirname(tarinfo.name) + "/" + tarinfo.linkname | ||
2817 | 2405 | limit = None | ||
2818 | 2406 | else: | ||
2819 | 2407 | # Search the archive before the link, because a hard link is | ||
2820 | 2408 | # just a reference to an already archived file. | ||
2821 | 2409 | linkname = tarinfo.linkname | ||
2822 | 2410 | limit = tarinfo | ||
2823 | 2411 | |||
2824 | 2412 | member = self._getmember(linkname, tarinfo=limit, normalize=True) | ||
2825 | 2413 | if member is None: | ||
2826 | 2414 | raise KeyError("linkname %r not found" % linkname) | ||
2827 | 2415 | return member | ||
2828 | 2416 | |||
2829 | 2417 | def __iter__(self): | ||
2830 | 2418 | """Provide an iterator object. | ||
2831 | 2419 | """ | ||
2832 | 2420 | if self._loaded: | ||
2833 | 2421 | return iter(self.members) | ||
2834 | 2422 | else: | ||
2835 | 2423 | return TarIter(self) | ||
2836 | 2424 | |||
2837 | 2425 | def _dbg(self, level, msg): | ||
2838 | 2426 | """Write debugging output to sys.stderr. | ||
2839 | 2427 | """ | ||
2840 | 2428 | if level <= self.debug: | ||
2841 | 2429 | print >> sys.stderr, msg | ||
2842 | 2430 | |||
2843 | 2431 | def __enter__(self): | ||
2844 | 2432 | self._check() | ||
2845 | 2433 | return self | ||
2846 | 2434 | |||
2847 | 2435 | def __exit__(self, type, value, traceback): | ||
2848 | 2436 | if type is None: | ||
2849 | 2437 | self.close() | ||
2850 | 2438 | else: | ||
2851 | 2439 | # An exception occurred. We must not call close() because | ||
2852 | 2440 | # it would try to write end-of-archive blocks and padding. | ||
2853 | 2441 | if not self._extfileobj: | ||
2854 | 2442 | self.fileobj.close() | ||
2855 | 2443 | self.closed = True | ||
2856 | 2444 | # class TarFile | ||
2857 | 2445 | |||
2858 | 2446 | class TarIter: | ||
2859 | 2447 | """Iterator Class. | ||
2860 | 2448 | |||
2861 | 2449 | for tarinfo in TarFile(...): | ||
2862 | 2450 | suite... | ||
2863 | 2451 | """ | ||
2864 | 2452 | |||
2865 | 2453 | def __init__(self, tarfile): | ||
2866 | 2454 | """Construct a TarIter object. | ||
2867 | 2455 | """ | ||
2868 | 2456 | self.tarfile = tarfile | ||
2869 | 2457 | self.index = 0 | ||
2870 | 2458 | def __iter__(self): | ||
2871 | 2459 | """Return iterator object. | ||
2872 | 2460 | """ | ||
2873 | 2461 | return self | ||
2874 | 2462 | def next(self): | ||
2875 | 2463 | """Return the next item using TarFile's next() method. | ||
2876 | 2464 | When all members have been read, set TarFile as _loaded. | ||
2877 | 2465 | """ | ||
2878 | 2466 | # Fix for SF #1100429: Under rare circumstances it can | ||
2879 | 2467 | # happen that getmembers() is called during iteration, | ||
2880 | 2468 | # which will cause TarIter to stop prematurely. | ||
2881 | 2469 | if not self.tarfile._loaded: | ||
2882 | 2470 | tarinfo = self.tarfile.next() | ||
2883 | 2471 | if not tarinfo: | ||
2884 | 2472 | self.tarfile._loaded = True | ||
2885 | 2473 | raise StopIteration | ||
2886 | 2474 | else: | ||
2887 | 2475 | try: | ||
2888 | 2476 | tarinfo = self.tarfile.members[self.index] | ||
2889 | 2477 | except IndexError: | ||
2890 | 2478 | raise StopIteration | ||
2891 | 2479 | self.index += 1 | ||
2892 | 2480 | return tarinfo | ||
2893 | 2481 | |||
2894 | 2482 | # Helper classes for sparse file support | ||
2895 | 2483 | class _section: | ||
2896 | 2484 | """Base class for _data and _hole. | ||
2897 | 2485 | """ | ||
2898 | 2486 | def __init__(self, offset, size): | ||
2899 | 2487 | self.offset = offset | ||
2900 | 2488 | self.size = size | ||
2901 | 2489 | def __contains__(self, offset): | ||
2902 | 2490 | return self.offset <= offset < self.offset + self.size | ||
2903 | 2491 | |||
2904 | 2492 | class _data(_section): | ||
2905 | 2493 | """Represent a data section in a sparse file. | ||
2906 | 2494 | """ | ||
2907 | 2495 | def __init__(self, offset, size, realpos): | ||
2908 | 2496 | _section.__init__(self, offset, size) | ||
2909 | 2497 | self.realpos = realpos | ||
2910 | 2498 | |||
2911 | 2499 | class _hole(_section): | ||
2912 | 2500 | """Represent a hole section in a sparse file. | ||
2913 | 2501 | """ | ||
2914 | 2502 | pass | ||
2915 | 2503 | |||
2916 | 2504 | class _ringbuffer(list): | ||
2917 | 2505 | """Ringbuffer class which increases performance | ||
2918 | 2506 | over a regular list. | ||
2919 | 2507 | """ | ||
2920 | 2508 | def __init__(self): | ||
2921 | 2509 | self.idx = 0 | ||
2922 | 2510 | def find(self, offset): | ||
2923 | 2511 | idx = self.idx | ||
2924 | 2512 | while True: | ||
2925 | 2513 | item = self[idx] | ||
2926 | 2514 | if offset in item: | ||
2927 | 2515 | break | ||
2928 | 2516 | idx += 1 | ||
2929 | 2517 | if idx == len(self): | ||
2930 | 2518 | idx = 0 | ||
2931 | 2519 | if idx == self.idx: | ||
2932 | 2520 | # End of File | ||
2933 | 2521 | return None | ||
2934 | 2522 | self.idx = idx | ||
2935 | 2523 | return item | ||
2936 | 2524 | |||
2937 | 2525 | #--------------------------------------------- | ||
2938 | 2526 | # zipfile compatible TarFile class | ||
2939 | 2527 | #--------------------------------------------- | ||
2940 | 2528 | TAR_PLAIN = 0 # zipfile.ZIP_STORED | ||
2941 | 2529 | TAR_GZIPPED = 8 # zipfile.ZIP_DEFLATED | ||
2942 | 2530 | class TarFileCompat: | ||
2943 | 2531 | """TarFile class compatible with standard module zipfile's | ||
2944 | 2532 | ZipFile class. | ||
2945 | 2533 | """ | ||
2946 | 2534 | def __init__(self, file, mode="r", compression=TAR_PLAIN): | ||
2947 | 2535 | from warnings import warnpy3k | ||
2948 | 2536 | warnpy3k("the TarFileCompat class has been removed in Python 3.0", | ||
2949 | 2537 | stacklevel=2) | ||
2950 | 2538 | if compression == TAR_PLAIN: | ||
2951 | 2539 | self.tarfile = TarFile.taropen(file, mode) | ||
2952 | 2540 | elif compression == TAR_GZIPPED: | ||
2953 | 2541 | self.tarfile = TarFile.gzopen(file, mode) | ||
2954 | 2542 | else: | ||
2955 | 2543 | raise ValueError("unknown compression constant") | ||
2956 | 2544 | if mode[0:1] == "r": | ||
2957 | 2545 | members = self.tarfile.getmembers() | ||
2958 | 2546 | for m in members: | ||
2959 | 2547 | m.filename = m.name | ||
2960 | 2548 | m.file_size = m.size | ||
2961 | 2549 | m.date_time = time.gmtime(m.mtime)[:6] | ||
2962 | 2550 | def namelist(self): | ||
2963 | 2551 | return map(lambda m: m.name, self.infolist()) | ||
2964 | 2552 | def infolist(self): | ||
2965 | 2553 | return filter(lambda m: m.type in REGULAR_TYPES, | ||
2966 | 2554 | self.tarfile.getmembers()) | ||
2967 | 2555 | def printdir(self): | ||
2968 | 2556 | self.tarfile.list() | ||
2969 | 2557 | def testzip(self): | ||
2970 | 2558 | return | ||
2971 | 2559 | def getinfo(self, name): | ||
2972 | 2560 | return self.tarfile.getmember(name) | ||
2973 | 2561 | def read(self, name): | ||
2974 | 2562 | return self.tarfile.extractfile(self.tarfile.getmember(name)).read() | ||
2975 | 2563 | def write(self, filename, arcname=None, compress_type=None): | ||
2976 | 2564 | self.tarfile.add(filename, arcname) | ||
2977 | 2565 | def writestr(self, zinfo, bytes): | ||
2978 | 2566 | try: | ||
2979 | 2567 | from cStringIO import StringIO | ||
2980 | 2568 | except ImportError: | ||
2981 | 2569 | from StringIO import StringIO | ||
2982 | 2570 | import calendar | ||
2983 | 2571 | tinfo = TarInfo(zinfo.filename) | ||
2984 | 2572 | tinfo.size = len(bytes) | ||
2985 | 2573 | tinfo.mtime = calendar.timegm(zinfo.date_time) | ||
2986 | 2574 | self.tarfile.addfile(tinfo, StringIO(bytes)) | ||
2987 | 2575 | def close(self): | ||
2988 | 2576 | self.tarfile.close() | ||
2989 | 2577 | #class TarFileCompat | ||
2990 | 2578 | |||
2991 | 2579 | #-------------------- | ||
2992 | 2580 | # exported functions | ||
2993 | 2581 | #-------------------- | ||
2994 | 2582 | def is_tarfile(name): | ||
2995 | 2583 | """Return True if name points to a tar archive that we | ||
2996 | 2584 | are able to handle, else return False. | ||
2997 | 2585 | """ | ||
2998 | 2586 | try: | ||
2999 | 2587 | t = open(name) | ||
3000 | 2588 | t.close() | ||
3001 | 2589 | return True | ||
3002 | 2590 | except TarError: | ||
3003 | 2591 | return False | ||
3004 | 2592 | |||
3005 | 2593 | bltn_open = open | ||
3006 | 2594 | open = TarFile.open | ||
3007 | 2595 | 36 | ||
3008 | === removed file 'duplicity/urlparse_2_5.py' | |||
3009 | --- duplicity/urlparse_2_5.py 2011-10-08 16:22:30 +0000 | |||
3010 | +++ duplicity/urlparse_2_5.py 1970-01-01 00:00:00 +0000 | |||
3011 | @@ -1,385 +0,0 @@ | |||
3012 | 1 | # -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- | ||
3013 | 2 | |||
3014 | 3 | """Parse (absolute and relative) URLs. | ||
3015 | 4 | |||
3016 | 5 | See RFC 1808: "Relative Uniform Resource Locators", by R. Fielding, | ||
3017 | 6 | UC Irvine, June 1995. | ||
3018 | 7 | """ | ||
3019 | 8 | |||
3020 | 9 | __all__ = ["urlparse", "urlunparse", "urljoin", "urldefrag", | ||
3021 | 10 | "urlsplit", "urlunsplit"] | ||
3022 | 11 | |||
3023 | 12 | # A classification of schemes ('' means apply by default) | ||
3024 | 13 | uses_relative = ['ftp', 'ftps', 'http', 'gopher', 'nntp', | ||
3025 | 14 | 'wais', 'file', 'https', 'shttp', 'mms', | ||
3026 | 15 | 'prospero', 'rtsp', 'rtspu', '', 'sftp', 'imap', 'imaps'] | ||
3027 | 16 | uses_netloc = ['ftp', 'ftps', 'http', 'gopher', 'nntp', 'telnet', | ||
3028 | 17 | 'wais', 'file', 'mms', 'https', 'shttp', | ||
3029 | 18 | 'snews', 'prospero', 'rtsp', 'rtspu', 'rsync', '', | ||
3030 | 19 | 'svn', 'svn+ssh', 'sftp', 'imap', 'imaps'] | ||
3031 | 20 | non_hierarchical = ['gopher', 'hdl', 'mailto', 'news', | ||
3032 | 21 | 'telnet', 'wais', 'snews', 'sip', 'sips', 'imap', 'imaps'] | ||
3033 | 22 | uses_params = ['ftp', 'ftps', 'hdl', 'prospero', 'http', | ||
3034 | 23 | 'https', 'shttp', 'rtsp', 'rtspu', 'sip', 'sips', | ||
3035 | 24 | 'mms', '', 'sftp', 'imap', 'imaps'] | ||
3036 | 25 | uses_query = ['http', 'wais', 'https', 'shttp', 'mms', | ||
3037 | 26 | 'gopher', 'rtsp', 'rtspu', 'sip', 'sips', 'imap', 'imaps', ''] | ||
3038 | 27 | uses_fragment = ['ftp', 'ftps', 'hdl', 'http', 'gopher', 'news', | ||
3039 | 28 | 'nntp', 'wais', 'https', 'shttp', 'snews', | ||
3040 | 29 | 'file', 'prospero', ''] | ||
3041 | 30 | |||
3042 | 31 | # Characters valid in scheme names | ||
3043 | 32 | scheme_chars = ('abcdefghijklmnopqrstuvwxyz' | ||
3044 | 33 | 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | ||
3045 | 34 | '0123456789' | ||
3046 | 35 | '+-.') | ||
3047 | 36 | |||
3048 | 37 | MAX_CACHE_SIZE = 20 | ||
3049 | 38 | _parse_cache = {} | ||
3050 | 39 | |||
3051 | 40 | def clear_cache(): | ||
3052 | 41 | """Clear the parse cache.""" | ||
3053 | 42 | global _parse_cache | ||
3054 | 43 | _parse_cache = {} | ||
3055 | 44 | |||
3056 | 45 | import string | ||
3057 | 46 | def _rsplit(str, delim, numsplit): | ||
3058 | 47 | parts = string.split(str, delim) | ||
3059 | 48 | if len(parts) <= numsplit + 1: | ||
3060 | 49 | return parts | ||
3061 | 50 | else: | ||
3062 | 51 | left = string.join(parts[0:-numsplit], delim) | ||
3063 | 52 | right = string.join(parts[len(parts)-numsplit:], delim) | ||
3064 | 53 | return [left, right] | ||
3065 | 54 | |||
3066 | 55 | class BaseResult(tuple): | ||
3067 | 56 | """Base class for the parsed result objects. | ||
3068 | 57 | |||
3069 | 58 | This provides the attributes shared by the two derived result | ||
3070 | 59 | objects as read-only properties. The derived classes are | ||
3071 | 60 | responsible for checking the right number of arguments were | ||
3072 | 61 | supplied to the constructor. | ||
3073 | 62 | |||
3074 | 63 | """ | ||
3075 | 64 | |||
3076 | 65 | __slots__ = () | ||
3077 | 66 | |||
3078 | 67 | # Attributes that access the basic components of the URL: | ||
3079 | 68 | |||
3080 | 69 | def get_scheme(self): | ||
3081 | 70 | return self[0] | ||
3082 | 71 | scheme = property(get_scheme) | ||
3083 | 72 | |||
3084 | 73 | def get_netloc(self): | ||
3085 | 74 | return self[1] | ||
3086 | 75 | netloc = property(get_netloc) | ||
3087 | 76 | |||
3088 | 77 | def get_path(self): | ||
3089 | 78 | return self[2] | ||
3090 | 79 | path = property(get_path) | ||
3091 | 80 | |||
3092 | 81 | def get_query(self): | ||
3093 | 82 | return self[-2] | ||
3094 | 83 | query = property(get_query) | ||
3095 | 84 | |||
3096 | 85 | def get_fragment(self): | ||
3097 | 86 | return self[-1] | ||
3098 | 87 | fragment = property(get_fragment) | ||
3099 | 88 | |||
3100 | 89 | # Additional attributes that provide access to parsed-out portions | ||
3101 | 90 | # of the netloc: | ||
3102 | 91 | |||
3103 | 92 | def get_username(self): | ||
3104 | 93 | netloc = self.netloc | ||
3105 | 94 | if "@" in netloc: | ||
3106 | 95 | userinfo = _rsplit(netloc, "@", 1)[0] | ||
3107 | 96 | if ":" in userinfo: | ||
3108 | 97 | userinfo = userinfo.split(":", 1)[0] | ||
3109 | 98 | return userinfo | ||
3110 | 99 | return None | ||
3111 | 100 | username = property(get_username) | ||
3112 | 101 | |||
3113 | 102 | def get_password(self): | ||
3114 | 103 | netloc = self.netloc | ||
3115 | 104 | if "@" in netloc: | ||
3116 | 105 | userinfo = _rsplit(netloc, "@", 1)[0] | ||
3117 | 106 | if ":" in userinfo: | ||
3118 | 107 | return userinfo.split(":", 1)[1] | ||
3119 | 108 | return None | ||
3120 | 109 | password = property(get_password) | ||
3121 | 110 | |||
3122 | 111 | def get_hostname(self): | ||
3123 | 112 | netloc = self.netloc.split('@')[-1] | ||
3124 | 113 | if '[' in netloc and ']' in netloc: | ||
3125 | 114 | return netloc.split(']')[0][1:].lower() | ||
3126 | 115 | elif ':' in netloc: | ||
3127 | 116 | return netloc.split(':')[0].lower() | ||
3128 | 117 | elif netloc == '': | ||
3129 | 118 | return None | ||
3130 | 119 | else: | ||
3131 | 120 | return netloc.lower() | ||
3132 | 121 | hostname = property(get_hostname) | ||
3133 | 122 | |||
3134 | 123 | def get_port(self): | ||
3135 | 124 | netloc = self.netloc.split('@')[-1].split(']')[-1] | ||
3136 | 125 | if ":" in netloc: | ||
3137 | 126 | port = netloc.split(":", 1)[1] | ||
3138 | 127 | return int(port, 10) | ||
3139 | 128 | return None | ||
3140 | 129 | port = property(get_port) | ||
3141 | 130 | |||
3142 | 131 | |||
3143 | 132 | class SplitResult(BaseResult): | ||
3144 | 133 | |||
3145 | 134 | __slots__ = () | ||
3146 | 135 | |||
3147 | 136 | def __new__(cls, scheme, netloc, path, query, fragment): | ||
3148 | 137 | return BaseResult.__new__( | ||
3149 | 138 | cls, (scheme, netloc, path, query, fragment)) | ||
3150 | 139 | |||
3151 | 140 | def geturl(self): | ||
3152 | 141 | return urlunsplit(self) | ||
3153 | 142 | |||
3154 | 143 | |||
3155 | 144 | class ParseResult(BaseResult): | ||
3156 | 145 | |||
3157 | 146 | __slots__ = () | ||
3158 | 147 | |||
3159 | 148 | def __new__(cls, scheme, netloc, path, params, query, fragment): | ||
3160 | 149 | return BaseResult.__new__( | ||
3161 | 150 | cls, (scheme, netloc, path, params, query, fragment)) | ||
3162 | 151 | |||
3163 | 152 | def get_params(self): | ||
3164 | 153 | return self[3] | ||
3165 | 154 | params = property(get_params) | ||
3166 | 155 | |||
3167 | 156 | def geturl(self): | ||
3168 | 157 | return urlunparse(self) | ||
3169 | 158 | |||
3170 | 159 | |||
3171 | 160 | def urlparse(url, scheme='', allow_fragments=True): | ||
3172 | 161 | """Parse a URL into 6 components: | ||
3173 | 162 | <scheme>://<netloc>/<path>;<params>?<query>#<fragment> | ||
3174 | 163 | Return a 6-tuple: (scheme, netloc, path, params, query, fragment). | ||
3175 | 164 | Note that we don't break the components up in smaller bits | ||
3176 | 165 | (e.g. netloc is a single string) and we don't expand % escapes.""" | ||
3177 | 166 | tuple = urlsplit(url, scheme, allow_fragments) | ||
3178 | 167 | scheme, netloc, url, query, fragment = tuple | ||
3179 | 168 | if scheme in uses_params and ';' in url: | ||
3180 | 169 | url, params = _splitparams(url) | ||
3181 | 170 | else: | ||
3182 | 171 | params = '' | ||
3183 | 172 | return ParseResult(scheme, netloc, url, params, query, fragment) | ||
3184 | 173 | |||
3185 | 174 | def _splitparams(url): | ||
3186 | 175 | if '/' in url: | ||
3187 | 176 | i = url.find(';', url.rfind('/')) | ||
3188 | 177 | if i < 0: | ||
3189 | 178 | return url, '' | ||
3190 | 179 | else: | ||
3191 | 180 | i = url.find(';') | ||
3192 | 181 | return url[:i], url[i+1:] | ||
3193 | 182 | |||
3194 | 183 | def _splitnetloc(url, start=0): | ||
3195 | 184 | for c in '/?#': # the order is important! | ||
3196 | 185 | delim = url.find(c, start) | ||
3197 | 186 | if delim >= 0: | ||
3198 | 187 | break | ||
3199 | 188 | else: | ||
3200 | 189 | delim = len(url) | ||
3201 | 190 | return url[start:delim], url[delim:] | ||
3202 | 191 | |||
3203 | 192 | def urlsplit(url, scheme='', allow_fragments=True): | ||
3204 | 193 | """Parse a URL into 5 components: | ||
3205 | 194 | <scheme>://<netloc>/<path>?<query>#<fragment> | ||
3206 | 195 | Return a 5-tuple: (scheme, netloc, path, query, fragment). | ||
3207 | 196 | Note that we don't break the components up in smaller bits | ||
3208 | 197 | (e.g. netloc is a single string) and we don't expand % escapes.""" | ||
3209 | 198 | allow_fragments = bool(allow_fragments) | ||
3210 | 199 | key = url, scheme, allow_fragments | ||
3211 | 200 | cached = _parse_cache.get(key, None) | ||
3212 | 201 | if cached: | ||
3213 | 202 | return cached | ||
3214 | 203 | if len(_parse_cache) >= MAX_CACHE_SIZE: # avoid runaway growth | ||
3215 | 204 | clear_cache() | ||
3216 | 205 | netloc = query = fragment = '' | ||
3217 | 206 | i = url.find(':') | ||
3218 | 207 | if i > 0: | ||
3219 | 208 | if url[:i] == 'http': # optimize the common case | ||
3220 | 209 | scheme = url[:i].lower() | ||
3221 | 210 | url = url[i+1:] | ||
3222 | 211 | if url[:2] == '//': | ||
3223 | 212 | netloc, url = _splitnetloc(url, 2) | ||
3224 | 213 | if allow_fragments and '#' in url: | ||
3225 | 214 | url, fragment = url.split('#', 1) | ||
3226 | 215 | if '?' in url: | ||
3227 | 216 | url, query = url.split('?', 1) | ||
3228 | 217 | v = SplitResult(scheme, netloc, url, query, fragment) | ||
3229 | 218 | _parse_cache[key] = v | ||
3230 | 219 | return v | ||
3231 | 220 | for c in url[:i]: | ||
3232 | 221 | if c not in scheme_chars: | ||
3233 | 222 | break | ||
3234 | 223 | else: | ||
3235 | 224 | scheme, url = url[:i].lower(), url[i+1:] | ||
3236 | 225 | if scheme in uses_netloc and url[:2] == '//': | ||
3237 | 226 | netloc, url = _splitnetloc(url, 2) | ||
3238 | 227 | if allow_fragments and scheme in uses_fragment and '#' in url: | ||
3239 | 228 | url, fragment = url.split('#', 1) | ||
3240 | 229 | if scheme in uses_query and '?' in url: | ||
3241 | 230 | url, query = url.split('?', 1) | ||
3242 | 231 | v = SplitResult(scheme, netloc, url, query, fragment) | ||
3243 | 232 | _parse_cache[key] = v | ||
3244 | 233 | return v | ||
3245 | 234 | |||
3246 | 235 | def urlunparse((scheme, netloc, url, params, query, fragment)): | ||
3247 | 236 | """Put a parsed URL back together again. This may result in a | ||
3248 | 237 | slightly different, but equivalent URL, if the URL that was parsed | ||
3249 | 238 | originally had redundant delimiters, e.g. a ? with an empty query | ||
3250 | 239 | (the draft states that these are equivalent).""" | ||
3251 | 240 | if params: | ||
3252 | 241 | url = "%s;%s" % (url, params) | ||
3253 | 242 | return urlunsplit((scheme, netloc, url, query, fragment)) | ||
3254 | 243 | |||
3255 | 244 | def urlunsplit((scheme, netloc, url, query, fragment)): | ||
3256 | 245 | if netloc or (scheme and scheme in uses_netloc and url[:2] != '//'): | ||
3257 | 246 | if url and url[:1] != '/': url = '/' + url | ||
3258 | 247 | url = '//' + (netloc or '') + url | ||
3259 | 248 | if scheme: | ||
3260 | 249 | url = scheme + ':' + url | ||
3261 | 250 | if query: | ||
3262 | 251 | url = url + '?' + query | ||
3263 | 252 | if fragment: | ||
3264 | 253 | url = url + '#' + fragment | ||
3265 | 254 | return url | ||
3266 | 255 | |||
3267 | 256 | def urljoin(base, url, allow_fragments=True): | ||
3268 | 257 | """Join a base URL and a possibly relative URL to form an absolute | ||
3269 | 258 | interpretation of the latter.""" | ||
3270 | 259 | if not base: | ||
3271 | 260 | return url | ||
3272 | 261 | if not url: | ||
3273 | 262 | return base | ||
3274 | 263 | bscheme, bnetloc, bpath, bparams, bquery, bfragment = urlparse(base, '', allow_fragments) #@UnusedVariable | ||
3275 | 264 | scheme, netloc, path, params, query, fragment = urlparse(url, bscheme, allow_fragments) | ||
3276 | 265 | if scheme != bscheme or scheme not in uses_relative: | ||
3277 | 266 | return url | ||
3278 | 267 | if scheme in uses_netloc: | ||
3279 | 268 | if netloc: | ||
3280 | 269 | return urlunparse((scheme, netloc, path, | ||
3281 | 270 | params, query, fragment)) | ||
3282 | 271 | netloc = bnetloc | ||
3283 | 272 | if path[:1] == '/': | ||
3284 | 273 | return urlunparse((scheme, netloc, path, | ||
3285 | 274 | params, query, fragment)) | ||
3286 | 275 | if not (path or params or query): | ||
3287 | 276 | return urlunparse((scheme, netloc, bpath, | ||
3288 | 277 | bparams, bquery, fragment)) | ||
3289 | 278 | segments = bpath.split('/')[:-1] + path.split('/') | ||
3290 | 279 | # XXX The stuff below is bogus in various ways... | ||
3291 | 280 | if segments[-1] == '.': | ||
3292 | 281 | segments[-1] = '' | ||
3293 | 282 | while '.' in segments: | ||
3294 | 283 | segments.remove('.') | ||
3295 | 284 | while 1: | ||
3296 | 285 | i = 1 | ||
3297 | 286 | n = len(segments) - 1 | ||
3298 | 287 | while i < n: | ||
3299 | 288 | if (segments[i] == '..' | ||
3300 | 289 | and segments[i-1] not in ('', '..')): | ||
3301 | 290 | del segments[i-1:i+1] | ||
3302 | 291 | break | ||
3303 | 292 | i = i+1 | ||
3304 | 293 | else: | ||
3305 | 294 | break | ||
3306 | 295 | if segments == ['', '..']: | ||
3307 | 296 | segments[-1] = '' | ||
3308 | 297 | elif len(segments) >= 2 and segments[-1] == '..': | ||
3309 | 298 | segments[-2:] = [''] | ||
3310 | 299 | return urlunparse((scheme, netloc, '/'.join(segments), | ||
3311 | 300 | params, query, fragment)) | ||
3312 | 301 | |||
3313 | 302 | def urldefrag(url): | ||
3314 | 303 | """Removes any existing fragment from URL. | ||
3315 | 304 | |||
3316 | 305 | Returns a tuple of the defragmented URL and the fragment. If | ||
3317 | 306 | the URL contained no fragments, the second element is the | ||
3318 | 307 | empty string. | ||
3319 | 308 | """ | ||
3320 | 309 | if '#' in url: | ||
3321 | 310 | s, n, p, a, q, frag = urlparse(url) | ||
3322 | 311 | defrag = urlunparse((s, n, p, a, q, '')) | ||
3323 | 312 | return defrag, frag | ||
3324 | 313 | else: | ||
3325 | 314 | return url, '' | ||
3326 | 315 | |||
3327 | 316 | |||
3328 | 317 | test_input = """ | ||
3329 | 318 | http://a/b/c/d | ||
3330 | 319 | |||
3331 | 320 | g:h = <URL:g:h> | ||
3332 | 321 | http:g = <URL:http://a/b/c/g> | ||
3333 | 322 | http: = <URL:http://a/b/c/d> | ||
3334 | 323 | g = <URL:http://a/b/c/g> | ||
3335 | 324 | ./g = <URL:http://a/b/c/g> | ||
3336 | 325 | g/ = <URL:http://a/b/c/g/> | ||
3337 | 326 | /g = <URL:http://a/g> | ||
3338 | 327 | //g = <URL:http://g> | ||
3339 | 328 | ?y = <URL:http://a/b/c/d?y> | ||
3340 | 329 | g?y = <URL:http://a/b/c/g?y> | ||
3341 | 330 | g?y/./x = <URL:http://a/b/c/g?y/./x> | ||
3342 | 331 | . = <URL:http://a/b/c/> | ||
3343 | 332 | ./ = <URL:http://a/b/c/> | ||
3344 | 333 | .. = <URL:http://a/b/> | ||
3345 | 334 | ../ = <URL:http://a/b/> | ||
3346 | 335 | ../g = <URL:http://a/b/g> | ||
3347 | 336 | ../.. = <URL:http://a/> | ||
3348 | 337 | ../../g = <URL:http://a/g> | ||
3349 | 338 | ../../../g = <URL:http://a/../g> | ||
3350 | 339 | ./../g = <URL:http://a/b/g> | ||
3351 | 340 | ./g/. = <URL:http://a/b/c/g/> | ||
3352 | 341 | /./g = <URL:http://a/./g> | ||
3353 | 342 | g/./h = <URL:http://a/b/c/g/h> | ||
3354 | 343 | g/../h = <URL:http://a/b/c/h> | ||
3355 | 344 | http:g = <URL:http://a/b/c/g> | ||
3356 | 345 | http: = <URL:http://a/b/c/d> | ||
3357 | 346 | http:?y = <URL:http://a/b/c/d?y> | ||
3358 | 347 | http:g?y = <URL:http://a/b/c/g?y> | ||
3359 | 348 | http:g?y/./x = <URL:http://a/b/c/g?y/./x> | ||
3360 | 349 | """ | ||
3361 | 350 | |||
3362 | 351 | def test(): | ||
3363 | 352 | import sys | ||
3364 | 353 | base = '' | ||
3365 | 354 | if sys.argv[1:]: | ||
3366 | 355 | fn = sys.argv[1] | ||
3367 | 356 | if fn == '-': | ||
3368 | 357 | fp = sys.stdin | ||
3369 | 358 | else: | ||
3370 | 359 | fp = open(fn) | ||
3371 | 360 | else: | ||
3372 | 361 | try: | ||
3373 | 362 | from cStringIO import StringIO | ||
3374 | 363 | except ImportError: | ||
3375 | 364 | from StringIO import StringIO | ||
3376 | 365 | fp = StringIO(test_input) | ||
3377 | 366 | while 1: | ||
3378 | 367 | line = fp.readline() | ||
3379 | 368 | if not line: break | ||
3380 | 369 | words = line.split() | ||
3381 | 370 | if not words: | ||
3382 | 371 | continue | ||
3383 | 372 | url = words[0] | ||
3384 | 373 | parts = urlparse(url) | ||
3385 | 374 | print '%-10s : %s' % (url, parts) | ||
3386 | 375 | abs = urljoin(base, url) | ||
3387 | 376 | if not base: | ||
3388 | 377 | base = abs | ||
3389 | 378 | wrapped = '<URL:%s>' % abs | ||
3390 | 379 | print '%-10s = %s' % (url, wrapped) | ||
3391 | 380 | if len(words) == 3 and words[1] == '=': | ||
3392 | 381 | if wrapped != words[2]: | ||
3393 | 382 | print 'EXPECTED', words[2], '!!!!!!!!!!' | ||
3394 | 383 | |||
3395 | 384 | if __name__ == '__main__': | ||
3396 | 385 | test() | ||
3397 | 386 | 0 | ||
3398 | === modified file 'po/POTFILES.in' | |||
3399 | --- po/POTFILES.in 2014-01-24 14:44:45 +0000 | |||
3400 | +++ po/POTFILES.in 2014-04-16 20:51:42 +0000 | |||
3401 | @@ -7,7 +7,6 @@ | |||
3402 | 7 | duplicity/selection.py | 7 | duplicity/selection.py |
3403 | 8 | duplicity/globals.py | 8 | duplicity/globals.py |
3404 | 9 | duplicity/commandline.py | 9 | duplicity/commandline.py |
3405 | 10 | duplicity/urlparse_2_5.py | ||
3406 | 11 | duplicity/dup_temp.py | 10 | duplicity/dup_temp.py |
3407 | 12 | duplicity/backend.py | 11 | duplicity/backend.py |
3408 | 13 | duplicity/asyncscheduler.py | 12 | duplicity/asyncscheduler.py |
3409 | 14 | 13 | ||
3410 | === modified file 'po/duplicity.pot' | |||
3411 | --- po/duplicity.pot 2014-01-24 14:44:45 +0000 | |||
3412 | +++ po/duplicity.pot 2014-04-16 20:51:42 +0000 | |||
3413 | @@ -8,7 +8,7 @@ | |||
3414 | 8 | msgstr "" | 8 | msgstr "" |
3415 | 9 | "Project-Id-Version: PACKAGE VERSION\n" | 9 | "Project-Id-Version: PACKAGE VERSION\n" |
3416 | 10 | "Report-Msgid-Bugs-To: Kenneth Loafman <kenneth@loafman.com>\n" | 10 | "Report-Msgid-Bugs-To: Kenneth Loafman <kenneth@loafman.com>\n" |
3418 | 11 | "POT-Creation-Date: 2014-01-24 06:47-0600\n" | 11 | "POT-Creation-Date: 2014-04-16 16:34-0400\n" |
3419 | 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
3420 | 13 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | 13 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
3421 | 14 | "Language-Team: LANGUAGE <LL@li.org>\n" | 14 | "Language-Team: LANGUAGE <LL@li.org>\n" |
3422 | @@ -118,194 +118,194 @@ | |||
3423 | 118 | msgid "Processed volume %d of %d" | 118 | msgid "Processed volume %d of %d" |
3424 | 119 | msgstr "" | 119 | msgstr "" |
3425 | 120 | 120 | ||
3427 | 121 | #: ../bin/duplicity:756 | 121 | #: ../bin/duplicity:765 |
3428 | 122 | #, python-format | 122 | #, python-format |
3429 | 123 | msgid "Invalid data - %s hash mismatch for file:" | 123 | msgid "Invalid data - %s hash mismatch for file:" |
3430 | 124 | msgstr "" | 124 | msgstr "" |
3431 | 125 | 125 | ||
3433 | 126 | #: ../bin/duplicity:758 | 126 | #: ../bin/duplicity:767 |
3434 | 127 | #, python-format | 127 | #, python-format |
3435 | 128 | msgid "Calculated hash: %s" | 128 | msgid "Calculated hash: %s" |
3436 | 129 | msgstr "" | 129 | msgstr "" |
3437 | 130 | 130 | ||
3439 | 131 | #: ../bin/duplicity:759 | 131 | #: ../bin/duplicity:768 |
3440 | 132 | #, python-format | 132 | #, python-format |
3441 | 133 | msgid "Manifest hash: %s" | 133 | msgid "Manifest hash: %s" |
3442 | 134 | msgstr "" | 134 | msgstr "" |
3443 | 135 | 135 | ||
3445 | 136 | #: ../bin/duplicity:797 | 136 | #: ../bin/duplicity:806 |
3446 | 137 | #, python-format | 137 | #, python-format |
3447 | 138 | msgid "Volume was signed by key %s, not %s" | 138 | msgid "Volume was signed by key %s, not %s" |
3448 | 139 | msgstr "" | 139 | msgstr "" |
3449 | 140 | 140 | ||
3451 | 141 | #: ../bin/duplicity:827 | 141 | #: ../bin/duplicity:836 |
3452 | 142 | #, python-format | 142 | #, python-format |
3453 | 143 | msgid "Verify complete: %s, %s." | 143 | msgid "Verify complete: %s, %s." |
3454 | 144 | msgstr "" | 144 | msgstr "" |
3455 | 145 | 145 | ||
3457 | 146 | #: ../bin/duplicity:828 | 146 | #: ../bin/duplicity:837 |
3458 | 147 | #, python-format | 147 | #, python-format |
3459 | 148 | msgid "%d file compared" | 148 | msgid "%d file compared" |
3460 | 149 | msgid_plural "%d files compared" | 149 | msgid_plural "%d files compared" |
3461 | 150 | msgstr[0] "" | 150 | msgstr[0] "" |
3462 | 151 | msgstr[1] "" | 151 | msgstr[1] "" |
3463 | 152 | 152 | ||
3465 | 153 | #: ../bin/duplicity:830 | 153 | #: ../bin/duplicity:839 |
3466 | 154 | #, python-format | 154 | #, python-format |
3467 | 155 | msgid "%d difference found" | 155 | msgid "%d difference found" |
3468 | 156 | msgid_plural "%d differences found" | 156 | msgid_plural "%d differences found" |
3469 | 157 | msgstr[0] "" | 157 | msgstr[0] "" |
3470 | 158 | msgstr[1] "" | 158 | msgstr[1] "" |
3471 | 159 | 159 | ||
3473 | 160 | #: ../bin/duplicity:849 | 160 | #: ../bin/duplicity:858 |
3474 | 161 | msgid "No extraneous files found, nothing deleted in cleanup." | 161 | msgid "No extraneous files found, nothing deleted in cleanup." |
3475 | 162 | msgstr "" | 162 | msgstr "" |
3476 | 163 | 163 | ||
3478 | 164 | #: ../bin/duplicity:854 | 164 | #: ../bin/duplicity:863 |
3479 | 165 | msgid "Deleting this file from backend:" | 165 | msgid "Deleting this file from backend:" |
3480 | 166 | msgid_plural "Deleting these files from backend:" | 166 | msgid_plural "Deleting these files from backend:" |
3481 | 167 | msgstr[0] "" | 167 | msgstr[0] "" |
3482 | 168 | msgstr[1] "" | 168 | msgstr[1] "" |
3483 | 169 | 169 | ||
3485 | 170 | #: ../bin/duplicity:866 | 170 | #: ../bin/duplicity:875 |
3486 | 171 | msgid "Found the following file to delete:" | 171 | msgid "Found the following file to delete:" |
3487 | 172 | msgid_plural "Found the following files to delete:" | 172 | msgid_plural "Found the following files to delete:" |
3488 | 173 | msgstr[0] "" | 173 | msgstr[0] "" |
3489 | 174 | msgstr[1] "" | 174 | msgstr[1] "" |
3490 | 175 | 175 | ||
3492 | 176 | #: ../bin/duplicity:870 | 176 | #: ../bin/duplicity:879 |
3493 | 177 | msgid "Run duplicity again with the --force option to actually delete." | 177 | msgid "Run duplicity again with the --force option to actually delete." |
3494 | 178 | msgstr "" | 178 | msgstr "" |
3495 | 179 | 179 | ||
3497 | 180 | #: ../bin/duplicity:913 | 180 | #: ../bin/duplicity:922 |
3498 | 181 | msgid "There are backup set(s) at time(s):" | 181 | msgid "There are backup set(s) at time(s):" |
3499 | 182 | msgstr "" | 182 | msgstr "" |
3500 | 183 | 183 | ||
3502 | 184 | #: ../bin/duplicity:915 | 184 | #: ../bin/duplicity:924 |
3503 | 185 | msgid "Which can't be deleted because newer sets depend on them." | 185 | msgid "Which can't be deleted because newer sets depend on them." |
3504 | 186 | msgstr "" | 186 | msgstr "" |
3505 | 187 | 187 | ||
3507 | 188 | #: ../bin/duplicity:919 | 188 | #: ../bin/duplicity:928 |
3508 | 189 | msgid "" | 189 | msgid "" |
3509 | 190 | "Current active backup chain is older than specified time. However, it will " | 190 | "Current active backup chain is older than specified time. However, it will " |
3510 | 191 | "not be deleted. To remove all your backups, manually purge the repository." | 191 | "not be deleted. To remove all your backups, manually purge the repository." |
3511 | 192 | msgstr "" | 192 | msgstr "" |
3512 | 193 | 193 | ||
3514 | 194 | #: ../bin/duplicity:925 | 194 | #: ../bin/duplicity:934 |
3515 | 195 | msgid "No old backup sets found, nothing deleted." | 195 | msgid "No old backup sets found, nothing deleted." |
3516 | 196 | msgstr "" | 196 | msgstr "" |
3517 | 197 | 197 | ||
3519 | 198 | #: ../bin/duplicity:928 | 198 | #: ../bin/duplicity:937 |
3520 | 199 | msgid "Deleting backup chain at time:" | 199 | msgid "Deleting backup chain at time:" |
3521 | 200 | msgid_plural "Deleting backup chains at times:" | 200 | msgid_plural "Deleting backup chains at times:" |
3522 | 201 | msgstr[0] "" | 201 | msgstr[0] "" |
3523 | 202 | msgstr[1] "" | 202 | msgstr[1] "" |
3524 | 203 | 203 | ||
3526 | 204 | #: ../bin/duplicity:939 | 204 | #: ../bin/duplicity:948 |
3527 | 205 | #, python-format | 205 | #, python-format |
3528 | 206 | msgid "Deleting incremental signature chain %s" | 206 | msgid "Deleting incremental signature chain %s" |
3529 | 207 | msgstr "" | 207 | msgstr "" |
3530 | 208 | 208 | ||
3532 | 209 | #: ../bin/duplicity:941 | 209 | #: ../bin/duplicity:950 |
3533 | 210 | #, python-format | 210 | #, python-format |
3534 | 211 | msgid "Deleting incremental backup chain %s" | 211 | msgid "Deleting incremental backup chain %s" |
3535 | 212 | msgstr "" | 212 | msgstr "" |
3536 | 213 | 213 | ||
3538 | 214 | #: ../bin/duplicity:944 | 214 | #: ../bin/duplicity:953 |
3539 | 215 | #, python-format | 215 | #, python-format |
3540 | 216 | msgid "Deleting complete signature chain %s" | 216 | msgid "Deleting complete signature chain %s" |
3541 | 217 | msgstr "" | 217 | msgstr "" |
3542 | 218 | 218 | ||
3544 | 219 | #: ../bin/duplicity:946 | 219 | #: ../bin/duplicity:955 |
3545 | 220 | #, python-format | 220 | #, python-format |
3546 | 221 | msgid "Deleting complete backup chain %s" | 221 | msgid "Deleting complete backup chain %s" |
3547 | 222 | msgstr "" | 222 | msgstr "" |
3548 | 223 | 223 | ||
3550 | 224 | #: ../bin/duplicity:952 | 224 | #: ../bin/duplicity:961 |
3551 | 225 | msgid "Found old backup chain at the following time:" | 225 | msgid "Found old backup chain at the following time:" |
3552 | 226 | msgid_plural "Found old backup chains at the following times:" | 226 | msgid_plural "Found old backup chains at the following times:" |
3553 | 227 | msgstr[0] "" | 227 | msgstr[0] "" |
3554 | 228 | msgstr[1] "" | 228 | msgstr[1] "" |
3555 | 229 | 229 | ||
3557 | 230 | #: ../bin/duplicity:956 | 230 | #: ../bin/duplicity:965 |
3558 | 231 | msgid "Rerun command with --force option to actually delete." | 231 | msgid "Rerun command with --force option to actually delete." |
3559 | 232 | msgstr "" | 232 | msgstr "" |
3560 | 233 | 233 | ||
3562 | 234 | #: ../bin/duplicity:1033 | 234 | #: ../bin/duplicity:1042 |
3563 | 235 | #, python-format | 235 | #, python-format |
3564 | 236 | msgid "Deleting local %s (not authoritative at backend)." | 236 | msgid "Deleting local %s (not authoritative at backend)." |
3565 | 237 | msgstr "" | 237 | msgstr "" |
3566 | 238 | 238 | ||
3568 | 239 | #: ../bin/duplicity:1037 | 239 | #: ../bin/duplicity:1046 |
3569 | 240 | #, python-format | 240 | #, python-format |
3570 | 241 | msgid "Unable to delete %s: %s" | 241 | msgid "Unable to delete %s: %s" |
3571 | 242 | msgstr "" | 242 | msgstr "" |
3572 | 243 | 243 | ||
3574 | 244 | #: ../bin/duplicity:1065 ../duplicity/dup_temp.py:263 | 244 | #: ../bin/duplicity:1074 ../duplicity/dup_temp.py:263 |
3575 | 245 | #, python-format | 245 | #, python-format |
3576 | 246 | msgid "Failed to read %s: %s" | 246 | msgid "Failed to read %s: %s" |
3577 | 247 | msgstr "" | 247 | msgstr "" |
3578 | 248 | 248 | ||
3580 | 249 | #: ../bin/duplicity:1079 | 249 | #: ../bin/duplicity:1088 |
3581 | 250 | #, python-format | 250 | #, python-format |
3582 | 251 | msgid "Copying %s to local cache." | 251 | msgid "Copying %s to local cache." |
3583 | 252 | msgstr "" | 252 | msgstr "" |
3584 | 253 | 253 | ||
3586 | 254 | #: ../bin/duplicity:1127 | 254 | #: ../bin/duplicity:1136 |
3587 | 255 | msgid "Local and Remote metadata are synchronized, no sync needed." | 255 | msgid "Local and Remote metadata are synchronized, no sync needed." |
3588 | 256 | msgstr "" | 256 | msgstr "" |
3589 | 257 | 257 | ||
3591 | 258 | #: ../bin/duplicity:1132 | 258 | #: ../bin/duplicity:1141 |
3592 | 259 | msgid "Synchronizing remote metadata to local cache..." | 259 | msgid "Synchronizing remote metadata to local cache..." |
3593 | 260 | msgstr "" | 260 | msgstr "" |
3594 | 261 | 261 | ||
3596 | 262 | #: ../bin/duplicity:1145 | 262 | #: ../bin/duplicity:1156 |
3597 | 263 | msgid "Sync would copy the following from remote to local:" | 263 | msgid "Sync would copy the following from remote to local:" |
3598 | 264 | msgstr "" | 264 | msgstr "" |
3599 | 265 | 265 | ||
3601 | 266 | #: ../bin/duplicity:1148 | 266 | #: ../bin/duplicity:1159 |
3602 | 267 | msgid "Sync would remove the following spurious local files:" | 267 | msgid "Sync would remove the following spurious local files:" |
3603 | 268 | msgstr "" | 268 | msgstr "" |
3604 | 269 | 269 | ||
3606 | 270 | #: ../bin/duplicity:1191 | 270 | #: ../bin/duplicity:1202 |
3607 | 271 | msgid "Unable to get free space on temp." | 271 | msgid "Unable to get free space on temp." |
3608 | 272 | msgstr "" | 272 | msgstr "" |
3609 | 273 | 273 | ||
3611 | 274 | #: ../bin/duplicity:1199 | 274 | #: ../bin/duplicity:1210 |
3612 | 275 | #, python-format | 275 | #, python-format |
3613 | 276 | msgid "Temp space has %d available, backup needs approx %d." | 276 | msgid "Temp space has %d available, backup needs approx %d." |
3614 | 277 | msgstr "" | 277 | msgstr "" |
3615 | 278 | 278 | ||
3617 | 279 | #: ../bin/duplicity:1202 | 279 | #: ../bin/duplicity:1213 |
3618 | 280 | #, python-format | 280 | #, python-format |
3619 | 281 | msgid "Temp has %d available, backup will use approx %d." | 281 | msgid "Temp has %d available, backup will use approx %d." |
3620 | 282 | msgstr "" | 282 | msgstr "" |
3621 | 283 | 283 | ||
3623 | 284 | #: ../bin/duplicity:1210 | 284 | #: ../bin/duplicity:1221 |
3624 | 285 | msgid "Unable to get max open files." | 285 | msgid "Unable to get max open files." |
3625 | 286 | msgstr "" | 286 | msgstr "" |
3626 | 287 | 287 | ||
3628 | 288 | #: ../bin/duplicity:1214 | 288 | #: ../bin/duplicity:1225 |
3629 | 289 | #, python-format | 289 | #, python-format |
3630 | 290 | msgid "" | 290 | msgid "" |
3631 | 291 | "Max open files of %s is too low, should be >= 1024.\n" | 291 | "Max open files of %s is too low, should be >= 1024.\n" |
3632 | 292 | "Use 'ulimit -n 1024' or higher to correct.\n" | 292 | "Use 'ulimit -n 1024' or higher to correct.\n" |
3633 | 293 | msgstr "" | 293 | msgstr "" |
3634 | 294 | 294 | ||
3636 | 295 | #: ../bin/duplicity:1263 | 295 | #: ../bin/duplicity:1274 |
3637 | 296 | msgid "" | 296 | msgid "" |
3638 | 297 | "RESTART: The first volume failed to upload before termination.\n" | 297 | "RESTART: The first volume failed to upload before termination.\n" |
3639 | 298 | " Restart is impossible...starting backup from beginning." | 298 | " Restart is impossible...starting backup from beginning." |
3640 | 299 | msgstr "" | 299 | msgstr "" |
3641 | 300 | 300 | ||
3643 | 301 | #: ../bin/duplicity:1269 | 301 | #: ../bin/duplicity:1280 |
3644 | 302 | #, python-format | 302 | #, python-format |
3645 | 303 | msgid "" | 303 | msgid "" |
3646 | 304 | "RESTART: Volumes %d to %d failed to upload before termination.\n" | 304 | "RESTART: Volumes %d to %d failed to upload before termination.\n" |
3647 | 305 | " Restarting backup at volume %d." | 305 | " Restarting backup at volume %d." |
3648 | 306 | msgstr "" | 306 | msgstr "" |
3649 | 307 | 307 | ||
3651 | 308 | #: ../bin/duplicity:1276 | 308 | #: ../bin/duplicity:1287 |
3652 | 309 | #, python-format | 309 | #, python-format |
3653 | 310 | msgid "" | 310 | msgid "" |
3654 | 311 | "RESTART: Impossible backup state: manifest has %d vols, remote has %d vols.\n" | 311 | "RESTART: Impossible backup state: manifest has %d vols, remote has %d vols.\n" |
3655 | @@ -314,7 +314,7 @@ | |||
3656 | 314 | " backup then restart the backup from the beginning." | 314 | " backup then restart the backup from the beginning." |
3657 | 315 | msgstr "" | 315 | msgstr "" |
3658 | 316 | 316 | ||
3660 | 317 | #: ../bin/duplicity:1298 | 317 | #: ../bin/duplicity:1309 |
3661 | 318 | msgid "" | 318 | msgid "" |
3662 | 319 | "\n" | 319 | "\n" |
3663 | 320 | "PYTHONOPTIMIZE in the environment causes duplicity to fail to\n" | 320 | "PYTHONOPTIMIZE in the environment causes duplicity to fail to\n" |
3664 | @@ -324,59 +324,59 @@ | |||
3665 | 324 | "See https://bugs.launchpad.net/duplicity/+bug/931175\n" | 324 | "See https://bugs.launchpad.net/duplicity/+bug/931175\n" |
3666 | 325 | msgstr "" | 325 | msgstr "" |
3667 | 326 | 326 | ||
3669 | 327 | #: ../bin/duplicity:1388 | 327 | #: ../bin/duplicity:1400 |
3670 | 328 | #, python-format | 328 | #, python-format |
3671 | 329 | msgid "Last %s backup left a partial set, restarting." | 329 | msgid "Last %s backup left a partial set, restarting." |
3672 | 330 | msgstr "" | 330 | msgstr "" |
3673 | 331 | 331 | ||
3675 | 332 | #: ../bin/duplicity:1392 | 332 | #: ../bin/duplicity:1404 |
3676 | 333 | #, python-format | 333 | #, python-format |
3677 | 334 | msgid "Cleaning up previous partial %s backup set, restarting." | 334 | msgid "Cleaning up previous partial %s backup set, restarting." |
3678 | 335 | msgstr "" | 335 | msgstr "" |
3679 | 336 | 336 | ||
3681 | 337 | #: ../bin/duplicity:1403 | 337 | #: ../bin/duplicity:1415 |
3682 | 338 | msgid "Last full backup date:" | 338 | msgid "Last full backup date:" |
3683 | 339 | msgstr "" | 339 | msgstr "" |
3684 | 340 | 340 | ||
3686 | 341 | #: ../bin/duplicity:1405 | 341 | #: ../bin/duplicity:1417 |
3687 | 342 | msgid "Last full backup date: none" | 342 | msgid "Last full backup date: none" |
3688 | 343 | msgstr "" | 343 | msgstr "" |
3689 | 344 | 344 | ||
3691 | 345 | #: ../bin/duplicity:1407 | 345 | #: ../bin/duplicity:1419 |
3692 | 346 | msgid "Last full backup is too old, forcing full backup" | 346 | msgid "Last full backup is too old, forcing full backup" |
3693 | 347 | msgstr "" | 347 | msgstr "" |
3694 | 348 | 348 | ||
3696 | 349 | #: ../bin/duplicity:1450 | 349 | #: ../bin/duplicity:1462 |
3697 | 350 | msgid "" | 350 | msgid "" |
3698 | 351 | "When using symmetric encryption, the signing passphrase must equal the " | 351 | "When using symmetric encryption, the signing passphrase must equal the " |
3699 | 352 | "encryption passphrase." | 352 | "encryption passphrase." |
3700 | 353 | msgstr "" | 353 | msgstr "" |
3701 | 354 | 354 | ||
3703 | 355 | #: ../bin/duplicity:1503 | 355 | #: ../bin/duplicity:1515 |
3704 | 356 | msgid "INT intercepted...exiting." | 356 | msgid "INT intercepted...exiting." |
3705 | 357 | msgstr "" | 357 | msgstr "" |
3706 | 358 | 358 | ||
3708 | 359 | #: ../bin/duplicity:1511 | 359 | #: ../bin/duplicity:1523 |
3709 | 360 | #, python-format | 360 | #, python-format |
3710 | 361 | msgid "GPG error detail: %s" | 361 | msgid "GPG error detail: %s" |
3711 | 362 | msgstr "" | 362 | msgstr "" |
3712 | 363 | 363 | ||
3714 | 364 | #: ../bin/duplicity:1521 | 364 | #: ../bin/duplicity:1533 |
3715 | 365 | #, python-format | 365 | #, python-format |
3716 | 366 | msgid "User error detail: %s" | 366 | msgid "User error detail: %s" |
3717 | 367 | msgstr "" | 367 | msgstr "" |
3718 | 368 | 368 | ||
3720 | 369 | #: ../bin/duplicity:1531 | 369 | #: ../bin/duplicity:1543 |
3721 | 370 | #, python-format | 370 | #, python-format |
3722 | 371 | msgid "Backend error detail: %s" | 371 | msgid "Backend error detail: %s" |
3723 | 372 | msgstr "" | 372 | msgstr "" |
3724 | 373 | 373 | ||
3726 | 374 | #: ../bin/rdiffdir:59 ../duplicity/commandline.py:237 | 374 | #: ../bin/rdiffdir:56 ../duplicity/commandline.py:237 |
3727 | 375 | #, python-format | 375 | #, python-format |
3728 | 376 | msgid "Error opening file %s" | 376 | msgid "Error opening file %s" |
3729 | 377 | msgstr "" | 377 | msgstr "" |
3730 | 378 | 378 | ||
3732 | 379 | #: ../bin/rdiffdir:122 | 379 | #: ../bin/rdiffdir:119 |
3733 | 380 | #, python-format | 380 | #, python-format |
3734 | 381 | msgid "File %s already exists, will not overwrite." | 381 | msgid "File %s already exists, will not overwrite." |
3735 | 382 | msgstr "" | 382 | msgstr "" |
3736 | @@ -493,8 +493,8 @@ | |||
3737 | 493 | #. Used in usage help to represent a Unix-style path name. Example: | 493 | #. Used in usage help to represent a Unix-style path name. Example: |
3738 | 494 | #. --archive-dir <path> | 494 | #. --archive-dir <path> |
3739 | 495 | #: ../duplicity/commandline.py:258 ../duplicity/commandline.py:268 | 495 | #: ../duplicity/commandline.py:258 ../duplicity/commandline.py:268 |
3742 | 496 | #: ../duplicity/commandline.py:285 ../duplicity/commandline.py:342 | 496 | #: ../duplicity/commandline.py:285 ../duplicity/commandline.py:351 |
3743 | 497 | #: ../duplicity/commandline.py:530 ../duplicity/commandline.py:746 | 497 | #: ../duplicity/commandline.py:548 ../duplicity/commandline.py:764 |
3744 | 498 | msgid "path" | 498 | msgid "path" |
3745 | 499 | msgstr "" | 499 | msgstr "" |
3746 | 500 | 500 | ||
3747 | @@ -505,8 +505,8 @@ | |||
3748 | 505 | #. Used in usage help to represent an ID for a GnuPG key. Example: | 505 | #. Used in usage help to represent an ID for a GnuPG key. Example: |
3749 | 506 | #. --encrypt-key <gpg_key_id> | 506 | #. --encrypt-key <gpg_key_id> |
3750 | 507 | #: ../duplicity/commandline.py:280 ../duplicity/commandline.py:287 | 507 | #: ../duplicity/commandline.py:280 ../duplicity/commandline.py:287 |
3753 | 508 | #: ../duplicity/commandline.py:362 ../duplicity/commandline.py:511 | 508 | #: ../duplicity/commandline.py:371 ../duplicity/commandline.py:529 |
3754 | 509 | #: ../duplicity/commandline.py:719 | 509 | #: ../duplicity/commandline.py:737 |
3755 | 510 | msgid "gpg-key-id" | 510 | msgid "gpg-key-id" |
3756 | 511 | msgstr "" | 511 | msgstr "" |
3757 | 512 | 512 | ||
3758 | @@ -514,42 +514,42 @@ | |||
3759 | 514 | #. matching one or more files, as described in the documentation. | 514 | #. matching one or more files, as described in the documentation. |
3760 | 515 | #. Example: | 515 | #. Example: |
3761 | 516 | #. --exclude <shell_pattern> | 516 | #. --exclude <shell_pattern> |
3764 | 517 | #: ../duplicity/commandline.py:295 ../duplicity/commandline.py:388 | 517 | #: ../duplicity/commandline.py:295 ../duplicity/commandline.py:397 |
3765 | 518 | #: ../duplicity/commandline.py:769 | 518 | #: ../duplicity/commandline.py:787 |
3766 | 519 | msgid "shell_pattern" | 519 | msgid "shell_pattern" |
3767 | 520 | msgstr "" | 520 | msgstr "" |
3768 | 521 | 521 | ||
3769 | 522 | #. Used in usage help to represent the name of a file. Example: | 522 | #. Used in usage help to represent the name of a file. Example: |
3770 | 523 | #. --log-file <filename> | 523 | #. --log-file <filename> |
3771 | 524 | #: ../duplicity/commandline.py:301 ../duplicity/commandline.py:308 | 524 | #: ../duplicity/commandline.py:301 ../duplicity/commandline.py:308 |
3775 | 525 | #: ../duplicity/commandline.py:313 ../duplicity/commandline.py:390 | 525 | #: ../duplicity/commandline.py:313 ../duplicity/commandline.py:399 |
3776 | 526 | #: ../duplicity/commandline.py:395 ../duplicity/commandline.py:406 | 526 | #: ../duplicity/commandline.py:404 ../duplicity/commandline.py:415 |
3777 | 527 | #: ../duplicity/commandline.py:715 | 527 | #: ../duplicity/commandline.py:733 |
3778 | 528 | msgid "filename" | 528 | msgid "filename" |
3779 | 529 | msgstr "" | 529 | msgstr "" |
3780 | 530 | 530 | ||
3781 | 531 | #. Used in usage help to represent a regular expression (regexp). | 531 | #. Used in usage help to represent a regular expression (regexp). |
3783 | 532 | #: ../duplicity/commandline.py:320 ../duplicity/commandline.py:397 | 532 | #: ../duplicity/commandline.py:320 ../duplicity/commandline.py:406 |
3784 | 533 | msgid "regular_expression" | 533 | msgid "regular_expression" |
3785 | 534 | msgstr "" | 534 | msgstr "" |
3786 | 535 | 535 | ||
3787 | 536 | #. Used in usage help to represent a time spec for a previous | 536 | #. Used in usage help to represent a time spec for a previous |
3788 | 537 | #. point in time, as described in the documentation. Example: | 537 | #. point in time, as described in the documentation. Example: |
3789 | 538 | #. duplicity remove-older-than time [options] target_url | 538 | #. duplicity remove-older-than time [options] target_url |
3792 | 539 | #: ../duplicity/commandline.py:354 ../duplicity/commandline.py:462 | 539 | #: ../duplicity/commandline.py:363 ../duplicity/commandline.py:474 |
3793 | 540 | #: ../duplicity/commandline.py:801 | 540 | #: ../duplicity/commandline.py:819 |
3794 | 541 | msgid "time" | 541 | msgid "time" |
3795 | 542 | msgstr "" | 542 | msgstr "" |
3796 | 543 | 543 | ||
3797 | 544 | #. Used in usage help. (Should be consistent with the "Options:" | 544 | #. Used in usage help. (Should be consistent with the "Options:" |
3798 | 545 | #. header.) Example: | 545 | #. header.) Example: |
3799 | 546 | #. duplicity [full|incremental] [options] source_dir target_url | 546 | #. duplicity [full|incremental] [options] source_dir target_url |
3802 | 547 | #: ../duplicity/commandline.py:358 ../duplicity/commandline.py:465 | 547 | #: ../duplicity/commandline.py:367 ../duplicity/commandline.py:477 |
3803 | 548 | #: ../duplicity/commandline.py:522 ../duplicity/commandline.py:734 | 548 | #: ../duplicity/commandline.py:540 ../duplicity/commandline.py:752 |
3804 | 549 | msgid "options" | 549 | msgid "options" |
3805 | 550 | msgstr "" | 550 | msgstr "" |
3806 | 551 | 551 | ||
3808 | 552 | #: ../duplicity/commandline.py:373 | 552 | #: ../duplicity/commandline.py:382 |
3809 | 553 | #, python-format | 553 | #, python-format |
3810 | 554 | msgid "" | 554 | msgid "" |
3811 | 555 | "Running in 'ignore errors' mode due to %s; please re-consider if this was " | 555 | "Running in 'ignore errors' mode due to %s; please re-consider if this was " |
3812 | @@ -557,150 +557,152 @@ | |||
3813 | 557 | msgstr "" | 557 | msgstr "" |
3814 | 558 | 558 | ||
3815 | 559 | #. Used in usage help to represent an imap mailbox | 559 | #. Used in usage help to represent an imap mailbox |
3817 | 560 | #: ../duplicity/commandline.py:386 | 560 | #: ../duplicity/commandline.py:395 |
3818 | 561 | msgid "imap_mailbox" | 561 | msgid "imap_mailbox" |
3819 | 562 | msgstr "" | 562 | msgstr "" |
3820 | 563 | 563 | ||
3822 | 564 | #: ../duplicity/commandline.py:400 | 564 | #: ../duplicity/commandline.py:409 |
3823 | 565 | msgid "file_descriptor" | 565 | msgid "file_descriptor" |
3824 | 566 | msgstr "" | 566 | msgstr "" |
3825 | 567 | 567 | ||
3826 | 568 | #. Used in usage help to represent a desired number of | 568 | #. Used in usage help to represent a desired number of |
3827 | 569 | #. something. Example: | 569 | #. something. Example: |
3828 | 570 | #. --num-retries <number> | 570 | #. --num-retries <number> |
3832 | 571 | #: ../duplicity/commandline.py:411 ../duplicity/commandline.py:433 | 571 | #: ../duplicity/commandline.py:420 ../duplicity/commandline.py:442 |
3833 | 572 | #: ../duplicity/commandline.py:448 ../duplicity/commandline.py:486 | 572 | #: ../duplicity/commandline.py:454 ../duplicity/commandline.py:460 |
3834 | 573 | #: ../duplicity/commandline.py:560 ../duplicity/commandline.py:729 | 573 | #: ../duplicity/commandline.py:498 ../duplicity/commandline.py:503 |
3835 | 574 | #: ../duplicity/commandline.py:507 ../duplicity/commandline.py:578 | ||
3836 | 575 | #: ../duplicity/commandline.py:747 | ||
3837 | 574 | msgid "number" | 576 | msgid "number" |
3838 | 575 | msgstr "" | 577 | msgstr "" |
3839 | 576 | 578 | ||
3840 | 577 | #. Used in usage help (noun) | 579 | #. Used in usage help (noun) |
3842 | 578 | #: ../duplicity/commandline.py:414 | 580 | #: ../duplicity/commandline.py:423 |
3843 | 579 | msgid "backup name" | 581 | msgid "backup name" |
3844 | 580 | msgstr "" | 582 | msgstr "" |
3845 | 581 | 583 | ||
3846 | 582 | #. noun | 584 | #. noun |
3849 | 583 | #: ../duplicity/commandline.py:495 ../duplicity/commandline.py:498 | 585 | #: ../duplicity/commandline.py:513 ../duplicity/commandline.py:516 |
3850 | 584 | #: ../duplicity/commandline.py:501 ../duplicity/commandline.py:700 | 586 | #: ../duplicity/commandline.py:519 ../duplicity/commandline.py:718 |
3851 | 585 | msgid "command" | 587 | msgid "command" |
3852 | 586 | msgstr "" | 588 | msgstr "" |
3853 | 587 | 589 | ||
3855 | 588 | #: ../duplicity/commandline.py:519 | 590 | #: ../duplicity/commandline.py:537 |
3856 | 589 | msgid "paramiko|pexpect" | 591 | msgid "paramiko|pexpect" |
3857 | 590 | msgstr "" | 592 | msgstr "" |
3858 | 591 | 593 | ||
3860 | 592 | #: ../duplicity/commandline.py:525 | 594 | #: ../duplicity/commandline.py:543 |
3861 | 593 | msgid "pem formatted bundle of certificate authorities" | 595 | msgid "pem formatted bundle of certificate authorities" |
3862 | 594 | msgstr "" | 596 | msgstr "" |
3863 | 595 | 597 | ||
3864 | 596 | #. Used in usage help. Example: | 598 | #. Used in usage help. Example: |
3865 | 597 | #. --timeout <seconds> | 599 | #. --timeout <seconds> |
3867 | 598 | #: ../duplicity/commandline.py:535 ../duplicity/commandline.py:763 | 600 | #: ../duplicity/commandline.py:553 ../duplicity/commandline.py:781 |
3868 | 599 | msgid "seconds" | 601 | msgid "seconds" |
3869 | 600 | msgstr "" | 602 | msgstr "" |
3870 | 601 | 603 | ||
3871 | 602 | #. abbreviation for "character" (noun) | 604 | #. abbreviation for "character" (noun) |
3873 | 603 | #: ../duplicity/commandline.py:541 ../duplicity/commandline.py:697 | 605 | #: ../duplicity/commandline.py:559 ../duplicity/commandline.py:715 |
3874 | 604 | msgid "char" | 606 | msgid "char" |
3875 | 605 | msgstr "" | 607 | msgstr "" |
3876 | 606 | 608 | ||
3878 | 607 | #: ../duplicity/commandline.py:663 | 609 | #: ../duplicity/commandline.py:681 |
3879 | 608 | #, python-format | 610 | #, python-format |
3880 | 609 | msgid "Using archive dir: %s" | 611 | msgid "Using archive dir: %s" |
3881 | 610 | msgstr "" | 612 | msgstr "" |
3882 | 611 | 613 | ||
3884 | 612 | #: ../duplicity/commandline.py:664 | 614 | #: ../duplicity/commandline.py:682 |
3885 | 613 | #, python-format | 615 | #, python-format |
3886 | 614 | msgid "Using backup name: %s" | 616 | msgid "Using backup name: %s" |
3887 | 615 | msgstr "" | 617 | msgstr "" |
3888 | 616 | 618 | ||
3890 | 617 | #: ../duplicity/commandline.py:671 | 619 | #: ../duplicity/commandline.py:689 |
3891 | 618 | #, python-format | 620 | #, python-format |
3892 | 619 | msgid "Command line error: %s" | 621 | msgid "Command line error: %s" |
3893 | 620 | msgstr "" | 622 | msgstr "" |
3894 | 621 | 623 | ||
3896 | 622 | #: ../duplicity/commandline.py:672 | 624 | #: ../duplicity/commandline.py:690 |
3897 | 623 | msgid "Enter 'duplicity --help' for help screen." | 625 | msgid "Enter 'duplicity --help' for help screen." |
3898 | 624 | msgstr "" | 626 | msgstr "" |
3899 | 625 | 627 | ||
3900 | 626 | #. Used in usage help to represent a Unix-style path name. Example: | 628 | #. Used in usage help to represent a Unix-style path name. Example: |
3901 | 627 | #. rsync://user[:password]@other_host[:port]//absolute_path | 629 | #. rsync://user[:password]@other_host[:port]//absolute_path |
3903 | 628 | #: ../duplicity/commandline.py:685 | 630 | #: ../duplicity/commandline.py:703 |
3904 | 629 | msgid "absolute_path" | 631 | msgid "absolute_path" |
3905 | 630 | msgstr "" | 632 | msgstr "" |
3906 | 631 | 633 | ||
3907 | 632 | #. Used in usage help. Example: | 634 | #. Used in usage help. Example: |
3908 | 633 | #. tahoe://alias/some_dir | 635 | #. tahoe://alias/some_dir |
3910 | 634 | #: ../duplicity/commandline.py:689 | 636 | #: ../duplicity/commandline.py:707 |
3911 | 635 | msgid "alias" | 637 | msgid "alias" |
3912 | 636 | msgstr "" | 638 | msgstr "" |
3913 | 637 | 639 | ||
3914 | 638 | #. Used in help to represent a "bucket name" for Amazon Web | 640 | #. Used in help to represent a "bucket name" for Amazon Web |
3915 | 639 | #. Services' Simple Storage Service (S3). Example: | 641 | #. Services' Simple Storage Service (S3). Example: |
3916 | 640 | #. s3://other.host/bucket_name[/prefix] | 642 | #. s3://other.host/bucket_name[/prefix] |
3918 | 641 | #: ../duplicity/commandline.py:694 | 643 | #: ../duplicity/commandline.py:712 |
3919 | 642 | msgid "bucket_name" | 644 | msgid "bucket_name" |
3920 | 643 | msgstr "" | 645 | msgstr "" |
3921 | 644 | 646 | ||
3922 | 645 | #. Used in usage help to represent the name of a container in | 647 | #. Used in usage help to represent the name of a container in |
3923 | 646 | #. Amazon Web Services' Cloudfront. Example: | 648 | #. Amazon Web Services' Cloudfront. Example: |
3924 | 647 | #. cf+http://container_name | 649 | #. cf+http://container_name |
3926 | 648 | #: ../duplicity/commandline.py:705 | 650 | #: ../duplicity/commandline.py:723 |
3927 | 649 | msgid "container_name" | 651 | msgid "container_name" |
3928 | 650 | msgstr "" | 652 | msgstr "" |
3929 | 651 | 653 | ||
3930 | 652 | #. noun | 654 | #. noun |
3932 | 653 | #: ../duplicity/commandline.py:708 | 655 | #: ../duplicity/commandline.py:726 |
3933 | 654 | msgid "count" | 656 | msgid "count" |
3934 | 655 | msgstr "" | 657 | msgstr "" |
3935 | 656 | 658 | ||
3936 | 657 | #. Used in usage help to represent the name of a file directory | 659 | #. Used in usage help to represent the name of a file directory |
3938 | 658 | #: ../duplicity/commandline.py:711 | 660 | #: ../duplicity/commandline.py:729 |
3939 | 659 | msgid "directory" | 661 | msgid "directory" |
3940 | 660 | msgstr "" | 662 | msgstr "" |
3941 | 661 | 663 | ||
3942 | 662 | #. Used in usage help, e.g. to represent the name of a code | 664 | #. Used in usage help, e.g. to represent the name of a code |
3943 | 663 | #. module. Example: | 665 | #. module. Example: |
3944 | 664 | #. rsync://user[:password]@other.host[:port]::/module/some_dir | 666 | #. rsync://user[:password]@other.host[:port]::/module/some_dir |
3946 | 665 | #: ../duplicity/commandline.py:724 | 667 | #: ../duplicity/commandline.py:742 |
3947 | 666 | msgid "module" | 668 | msgid "module" |
3948 | 667 | msgstr "" | 669 | msgstr "" |
3949 | 668 | 670 | ||
3950 | 669 | #. Used in usage help to represent an internet hostname. Example: | 671 | #. Used in usage help to represent an internet hostname. Example: |
3951 | 670 | #. ftp://user[:password]@other.host[:port]/some_dir | 672 | #. ftp://user[:password]@other.host[:port]/some_dir |
3953 | 671 | #: ../duplicity/commandline.py:738 | 673 | #: ../duplicity/commandline.py:756 |
3954 | 672 | msgid "other.host" | 674 | msgid "other.host" |
3955 | 673 | msgstr "" | 675 | msgstr "" |
3956 | 674 | 676 | ||
3957 | 675 | #. Used in usage help. Example: | 677 | #. Used in usage help. Example: |
3958 | 676 | #. ftp://user[:password]@other.host[:port]/some_dir | 678 | #. ftp://user[:password]@other.host[:port]/some_dir |
3960 | 677 | #: ../duplicity/commandline.py:742 | 679 | #: ../duplicity/commandline.py:760 |
3961 | 678 | msgid "password" | 680 | msgid "password" |
3962 | 679 | msgstr "" | 681 | msgstr "" |
3963 | 680 | 682 | ||
3964 | 681 | #. Used in usage help to represent a TCP port number. Example: | 683 | #. Used in usage help to represent a TCP port number. Example: |
3965 | 682 | #. ftp://user[:password]@other.host[:port]/some_dir | 684 | #. ftp://user[:password]@other.host[:port]/some_dir |
3967 | 683 | #: ../duplicity/commandline.py:750 | 685 | #: ../duplicity/commandline.py:768 |
3968 | 684 | msgid "port" | 686 | msgid "port" |
3969 | 685 | msgstr "" | 687 | msgstr "" |
3970 | 686 | 688 | ||
3971 | 687 | #. Used in usage help. This represents a string to be used as a | 689 | #. Used in usage help. This represents a string to be used as a |
3972 | 688 | #. prefix to names for backup files created by Duplicity. Example: | 690 | #. prefix to names for backup files created by Duplicity. Example: |
3973 | 689 | #. s3://other.host/bucket_name[/prefix] | 691 | #. s3://other.host/bucket_name[/prefix] |
3975 | 690 | #: ../duplicity/commandline.py:755 | 692 | #: ../duplicity/commandline.py:773 |
3976 | 691 | msgid "prefix" | 693 | msgid "prefix" |
3977 | 692 | msgstr "" | 694 | msgstr "" |
3978 | 693 | 695 | ||
3979 | 694 | #. Used in usage help to represent a Unix-style path name. Example: | 696 | #. Used in usage help to represent a Unix-style path name. Example: |
3980 | 695 | #. rsync://user[:password]@other.host[:port]/relative_path | 697 | #. rsync://user[:password]@other.host[:port]/relative_path |
3982 | 696 | #: ../duplicity/commandline.py:759 | 698 | #: ../duplicity/commandline.py:777 |
3983 | 697 | msgid "relative_path" | 699 | msgid "relative_path" |
3984 | 698 | msgstr "" | 700 | msgstr "" |
3985 | 699 | 701 | ||
3986 | 700 | #. Used in usage help to represent the name of a single file | 702 | #. Used in usage help to represent the name of a single file |
3987 | 701 | #. directory or a Unix-style path to a directory. Example: | 703 | #. directory or a Unix-style path to a directory. Example: |
3988 | 702 | #. file:///some_dir | 704 | #. file:///some_dir |
3990 | 703 | #: ../duplicity/commandline.py:774 | 705 | #: ../duplicity/commandline.py:792 |
3991 | 704 | msgid "some_dir" | 706 | msgid "some_dir" |
3992 | 705 | msgstr "" | 707 | msgstr "" |
3993 | 706 | 708 | ||
3994 | @@ -708,14 +710,14 @@ | |||
3995 | 708 | #. directory or a Unix-style path to a directory where files will be | 710 | #. directory or a Unix-style path to a directory where files will be |
3996 | 709 | #. coming FROM. Example: | 711 | #. coming FROM. Example: |
3997 | 710 | #. duplicity [full|incremental] [options] source_dir target_url | 712 | #. duplicity [full|incremental] [options] source_dir target_url |
3999 | 711 | #: ../duplicity/commandline.py:780 | 713 | #: ../duplicity/commandline.py:798 |
4000 | 712 | msgid "source_dir" | 714 | msgid "source_dir" |
4001 | 713 | msgstr "" | 715 | msgstr "" |
4002 | 714 | 716 | ||
4003 | 715 | #. Used in usage help to represent a URL files will be coming | 717 | #. Used in usage help to represent a URL files will be coming |
4004 | 716 | #. FROM. Example: | 718 | #. FROM. Example: |
4005 | 717 | #. duplicity [restore] [options] source_url target_dir | 719 | #. duplicity [restore] [options] source_url target_dir |
4007 | 718 | #: ../duplicity/commandline.py:785 | 720 | #: ../duplicity/commandline.py:803 |
4008 | 719 | msgid "source_url" | 721 | msgid "source_url" |
4009 | 720 | msgstr "" | 722 | msgstr "" |
4010 | 721 | 723 | ||
4011 | @@ -723,75 +725,75 @@ | |||
4012 | 723 | #. directory or a Unix-style path to a directory. where files will be | 725 | #. directory or a Unix-style path to a directory. where files will be |
4013 | 724 | #. going TO. Example: | 726 | #. going TO. Example: |
4014 | 725 | #. duplicity [restore] [options] source_url target_dir | 727 | #. duplicity [restore] [options] source_url target_dir |
4016 | 726 | #: ../duplicity/commandline.py:791 | 728 | #: ../duplicity/commandline.py:809 |
4017 | 727 | msgid "target_dir" | 729 | msgid "target_dir" |
4018 | 728 | msgstr "" | 730 | msgstr "" |
4019 | 729 | 731 | ||
4020 | 730 | #. Used in usage help to represent a URL files will be going TO. | 732 | #. Used in usage help to represent a URL files will be going TO. |
4021 | 731 | #. Example: | 733 | #. Example: |
4022 | 732 | #. duplicity [full|incremental] [options] source_dir target_url | 734 | #. duplicity [full|incremental] [options] source_dir target_url |
4024 | 733 | #: ../duplicity/commandline.py:796 | 735 | #: ../duplicity/commandline.py:814 |
4025 | 734 | msgid "target_url" | 736 | msgid "target_url" |
4026 | 735 | msgstr "" | 737 | msgstr "" |
4027 | 736 | 738 | ||
4028 | 737 | #. Used in usage help to represent a user name (i.e. login). | 739 | #. Used in usage help to represent a user name (i.e. login). |
4029 | 738 | #. Example: | 740 | #. Example: |
4030 | 739 | #. ftp://user[:password]@other.host[:port]/some_dir | 741 | #. ftp://user[:password]@other.host[:port]/some_dir |
4032 | 740 | #: ../duplicity/commandline.py:806 | 742 | #: ../duplicity/commandline.py:824 |
4033 | 741 | msgid "user" | 743 | msgid "user" |
4034 | 742 | msgstr "" | 744 | msgstr "" |
4035 | 743 | 745 | ||
4036 | 744 | #. Header in usage help | 746 | #. Header in usage help |
4038 | 745 | #: ../duplicity/commandline.py:823 | 747 | #: ../duplicity/commandline.py:841 |
4039 | 746 | msgid "Backends and their URL formats:" | 748 | msgid "Backends and their URL formats:" |
4040 | 747 | msgstr "" | 749 | msgstr "" |
4041 | 748 | 750 | ||
4042 | 749 | #. Header in usage help | 751 | #. Header in usage help |
4044 | 750 | #: ../duplicity/commandline.py:848 | 752 | #: ../duplicity/commandline.py:866 |
4045 | 751 | msgid "Commands:" | 753 | msgid "Commands:" |
4046 | 752 | msgstr "" | 754 | msgstr "" |
4047 | 753 | 755 | ||
4049 | 754 | #: ../duplicity/commandline.py:872 | 756 | #: ../duplicity/commandline.py:890 |
4050 | 755 | #, python-format | 757 | #, python-format |
4051 | 756 | msgid "Specified archive directory '%s' does not exist, or is not a directory" | 758 | msgid "Specified archive directory '%s' does not exist, or is not a directory" |
4052 | 757 | msgstr "" | 759 | msgstr "" |
4053 | 758 | 760 | ||
4055 | 759 | #: ../duplicity/commandline.py:881 | 761 | #: ../duplicity/commandline.py:899 |
4056 | 760 | #, python-format | 762 | #, python-format |
4057 | 761 | msgid "" | 763 | msgid "" |
4058 | 762 | "Sign key should be an 8 character hex string, like 'AA0E73D2'.\n" | 764 | "Sign key should be an 8 character hex string, like 'AA0E73D2'.\n" |
4059 | 763 | "Received '%s' instead." | 765 | "Received '%s' instead." |
4060 | 764 | msgstr "" | 766 | msgstr "" |
4061 | 765 | 767 | ||
4063 | 766 | #: ../duplicity/commandline.py:941 | 768 | #: ../duplicity/commandline.py:959 |
4064 | 767 | #, python-format | 769 | #, python-format |
4065 | 768 | msgid "" | 770 | msgid "" |
4066 | 769 | "Restore destination directory %s already exists.\n" | 771 | "Restore destination directory %s already exists.\n" |
4067 | 770 | "Will not overwrite." | 772 | "Will not overwrite." |
4068 | 771 | msgstr "" | 773 | msgstr "" |
4069 | 772 | 774 | ||
4071 | 773 | #: ../duplicity/commandline.py:946 | 775 | #: ../duplicity/commandline.py:964 |
4072 | 774 | #, python-format | 776 | #, python-format |
4073 | 775 | msgid "Verify directory %s does not exist" | 777 | msgid "Verify directory %s does not exist" |
4074 | 776 | msgstr "" | 778 | msgstr "" |
4075 | 777 | 779 | ||
4077 | 778 | #: ../duplicity/commandline.py:952 | 780 | #: ../duplicity/commandline.py:970 |
4078 | 779 | #, python-format | 781 | #, python-format |
4079 | 780 | msgid "Backup source directory %s does not exist." | 782 | msgid "Backup source directory %s does not exist." |
4080 | 781 | msgstr "" | 783 | msgstr "" |
4081 | 782 | 784 | ||
4083 | 783 | #: ../duplicity/commandline.py:981 | 785 | #: ../duplicity/commandline.py:999 |
4084 | 784 | #, python-format | 786 | #, python-format |
4085 | 785 | msgid "Command line warning: %s" | 787 | msgid "Command line warning: %s" |
4086 | 786 | msgstr "" | 788 | msgstr "" |
4087 | 787 | 789 | ||
4089 | 788 | #: ../duplicity/commandline.py:981 | 790 | #: ../duplicity/commandline.py:999 |
4090 | 789 | msgid "" | 791 | msgid "" |
4091 | 790 | "Selection options --exclude/--include\n" | 792 | "Selection options --exclude/--include\n" |
4092 | 791 | "currently work only when backing up,not restoring." | 793 | "currently work only when backing up,not restoring." |
4093 | 792 | msgstr "" | 794 | msgstr "" |
4094 | 793 | 795 | ||
4096 | 794 | #: ../duplicity/commandline.py:1029 | 796 | #: ../duplicity/commandline.py:1047 |
4097 | 795 | #, python-format | 797 | #, python-format |
4098 | 796 | msgid "" | 798 | msgid "" |
4099 | 797 | "Bad URL '%s'.\n" | 799 | "Bad URL '%s'.\n" |
4100 | @@ -799,61 +801,61 @@ | |||
4101 | 799 | "\"file:///usr/local\". See the man page for more information." | 801 | "\"file:///usr/local\". See the man page for more information." |
4102 | 800 | msgstr "" | 802 | msgstr "" |
4103 | 801 | 803 | ||
4105 | 802 | #: ../duplicity/commandline.py:1054 | 804 | #: ../duplicity/commandline.py:1072 |
4106 | 803 | msgid "Main action: " | 805 | msgid "Main action: " |
4107 | 804 | msgstr "" | 806 | msgstr "" |
4108 | 805 | 807 | ||
4110 | 806 | #: ../duplicity/backend.py:87 | 808 | #: ../duplicity/backend.py:109 |
4111 | 807 | #, python-format | 809 | #, python-format |
4112 | 808 | msgid "Import of %s %s" | 810 | msgid "Import of %s %s" |
4113 | 809 | msgstr "" | 811 | msgstr "" |
4114 | 810 | 812 | ||
4116 | 811 | #: ../duplicity/backend.py:164 | 813 | #: ../duplicity/backend.py:186 |
4117 | 812 | #, python-format | 814 | #, python-format |
4118 | 813 | msgid "Could not initialize backend: %s" | 815 | msgid "Could not initialize backend: %s" |
4119 | 814 | msgstr "" | 816 | msgstr "" |
4120 | 815 | 817 | ||
4122 | 816 | #: ../duplicity/backend.py:320 | 818 | #: ../duplicity/backend.py:311 |
4123 | 817 | #, python-format | 819 | #, python-format |
4124 | 818 | msgid "Attempt %s failed: %s: %s" | 820 | msgid "Attempt %s failed: %s: %s" |
4125 | 819 | msgstr "" | 821 | msgstr "" |
4126 | 820 | 822 | ||
4129 | 821 | #: ../duplicity/backend.py:322 ../duplicity/backend.py:352 | 823 | #: ../duplicity/backend.py:313 ../duplicity/backend.py:343 |
4130 | 822 | #: ../duplicity/backend.py:359 | 824 | #: ../duplicity/backend.py:350 |
4131 | 823 | #, python-format | 825 | #, python-format |
4132 | 824 | msgid "Backtrace of previous error: %s" | 826 | msgid "Backtrace of previous error: %s" |
4133 | 825 | msgstr "" | 827 | msgstr "" |
4134 | 826 | 828 | ||
4136 | 827 | #: ../duplicity/backend.py:350 | 829 | #: ../duplicity/backend.py:341 |
4137 | 828 | #, python-format | 830 | #, python-format |
4138 | 829 | msgid "Attempt %s failed. %s: %s" | 831 | msgid "Attempt %s failed. %s: %s" |
4139 | 830 | msgstr "" | 832 | msgstr "" |
4140 | 831 | 833 | ||
4142 | 832 | #: ../duplicity/backend.py:361 | 834 | #: ../duplicity/backend.py:352 |
4143 | 833 | #, python-format | 835 | #, python-format |
4144 | 834 | msgid "Giving up after %s attempts. %s: %s" | 836 | msgid "Giving up after %s attempts. %s: %s" |
4145 | 835 | msgstr "" | 837 | msgstr "" |
4146 | 836 | 838 | ||
4148 | 837 | #: ../duplicity/backend.py:546 ../duplicity/backend.py:570 | 839 | #: ../duplicity/backend.py:537 ../duplicity/backend.py:561 |
4149 | 838 | #, python-format | 840 | #, python-format |
4150 | 839 | msgid "Reading results of '%s'" | 841 | msgid "Reading results of '%s'" |
4151 | 840 | msgstr "" | 842 | msgstr "" |
4152 | 841 | 843 | ||
4154 | 842 | #: ../duplicity/backend.py:585 | 844 | #: ../duplicity/backend.py:576 |
4155 | 843 | #, python-format | 845 | #, python-format |
4156 | 844 | msgid "Running '%s' failed with code %d (attempt #%d)" | 846 | msgid "Running '%s' failed with code %d (attempt #%d)" |
4157 | 845 | msgid_plural "Running '%s' failed with code %d (attempt #%d)" | 847 | msgid_plural "Running '%s' failed with code %d (attempt #%d)" |
4158 | 846 | msgstr[0] "" | 848 | msgstr[0] "" |
4159 | 847 | msgstr[1] "" | 849 | msgstr[1] "" |
4160 | 848 | 850 | ||
4162 | 849 | #: ../duplicity/backend.py:589 | 851 | #: ../duplicity/backend.py:580 |
4163 | 850 | #, python-format | 852 | #, python-format |
4164 | 851 | msgid "" | 853 | msgid "" |
4165 | 852 | "Error is:\n" | 854 | "Error is:\n" |
4166 | 853 | "%s" | 855 | "%s" |
4167 | 854 | msgstr "" | 856 | msgstr "" |
4168 | 855 | 857 | ||
4170 | 856 | #: ../duplicity/backend.py:591 | 858 | #: ../duplicity/backend.py:582 |
4171 | 857 | #, python-format | 859 | #, python-format |
4172 | 858 | msgid "Giving up trying to execute '%s' after %d attempt" | 860 | msgid "Giving up trying to execute '%s' after %d attempt" |
4173 | 859 | msgid_plural "Giving up trying to execute '%s' after %d attempts" | 861 | msgid_plural "Giving up trying to execute '%s' after %d attempts" |
4174 | 860 | 862 | ||
4175 | === modified file 'setup.py' | |||
4176 | --- setup.py 2014-04-16 20:51:42 +0000 | |||
4177 | +++ setup.py 2014-04-16 20:51:42 +0000 | |||
4178 | @@ -28,8 +28,8 @@ | |||
4179 | 28 | 28 | ||
4180 | 29 | version_string = "$version" | 29 | version_string = "$version" |
4181 | 30 | 30 | ||
4184 | 31 | if sys.version_info[:2] < (2,4): | 31 | if sys.version_info[:2] < (2, 6): |
4185 | 32 | print "Sorry, duplicity requires version 2.4 or later of python" | 32 | print "Sorry, duplicity requires version 2.6 or later of python" |
4186 | 33 | sys.exit(1) | 33 | sys.exit(1) |
4187 | 34 | 34 | ||
4188 | 35 | incdir_list = libdir_list = None | 35 | incdir_list = libdir_list = None |
4189 | @@ -53,8 +53,6 @@ | |||
4190 | 53 | 'README', | 53 | 'README', |
4191 | 54 | 'README-REPO', | 54 | 'README-REPO', |
4192 | 55 | 'README-LOG', | 55 | 'README-LOG', |
4193 | 56 | 'tarfile-LICENSE', | ||
4194 | 57 | 'tarfile-CHANGES', | ||
4195 | 58 | 'CHANGELOG']), | 56 | 'CHANGELOG']), |
4196 | 59 | ] | 57 | ] |
4197 | 60 | 58 | ||
4198 | 61 | 59 | ||
4199 | === removed file 'tarfile-CHANGES' | |||
4200 | --- tarfile-CHANGES 2011-08-23 18:14:17 +0000 | |||
4201 | +++ tarfile-CHANGES 1970-01-01 00:00:00 +0000 | |||
4202 | @@ -1,3 +0,0 @@ | |||
4203 | 1 | tarfile.py is a copy of python2.7's tarfile.py. | ||
4204 | 2 | |||
4205 | 3 | No changes besides 2.4 compatibility have been made. | ||
4206 | 4 | 0 | ||
4207 | === removed file 'tarfile-LICENSE' | |||
4208 | --- tarfile-LICENSE 2011-10-05 14:13:31 +0000 | |||
4209 | +++ tarfile-LICENSE 1970-01-01 00:00:00 +0000 | |||
4210 | @@ -1,92 +0,0 @@ | |||
4211 | 1 | irdu-backup uses tarfile, written by Lars Gustäbel. The following | ||
4212 | 2 | notice was included in the tarfile distribution: | ||
4213 | 3 | |||
4214 | 4 | ----------------------------------------------------------------- | ||
4215 | 5 | tarfile - python module for accessing TAR archives | ||
4216 | 6 | |||
4217 | 7 | Lars Gustäbel <lars@gustaebel.de> | ||
4218 | 8 | ----------------------------------------------------------------- | ||
4219 | 9 | |||
4220 | 10 | |||
4221 | 11 | Description | ||
4222 | 12 | ----------- | ||
4223 | 13 | |||
4224 | 14 | The tarfile module provides a set of functions for accessing TAR | ||
4225 | 15 | format archives. Because it is written in pure Python, it does | ||
4226 | 16 | not require any platform specific functions. GZIP compressed TAR | ||
4227 | 17 | archives are seamlessly supported. | ||
4228 | 18 | |||
4229 | 19 | |||
4230 | 20 | Requirements | ||
4231 | 21 | ------------ | ||
4232 | 22 | |||
4233 | 23 | tarfile needs at least Python version 2.2. | ||
4234 | 24 | (For a tarfile for Python 1.5.2 take a look on the webpage.) | ||
4235 | 25 | |||
4236 | 26 | |||
4237 | 27 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
4238 | 28 | IMPORTANT NOTE (*NIX only) | ||
4239 | 29 | -------------------------- | ||
4240 | 30 | |||
4241 | 31 | The addition of character and block devices is enabled by a C | ||
4242 | 32 | extension module (_tarfile.c), because Python does not yet | ||
4243 | 33 | provide the major() and minor() macros. | ||
4244 | 34 | Currently Linux and FreeBSD are implemented. If your OS is not | ||
4245 | 35 | supported, then please send me a patch. | ||
4246 | 36 | |||
4247 | 37 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
4248 | 38 | |||
4249 | 39 | |||
4250 | 40 | Download | ||
4251 | 41 | -------- | ||
4252 | 42 | |||
4253 | 43 | You can download the newest version at URL: | ||
4254 | 44 | http://www.gustaebel.de/lars/tarfile/ | ||
4255 | 45 | |||
4256 | 46 | |||
4257 | 47 | Installation | ||
4258 | 48 | ------------ | ||
4259 | 49 | |||
4260 | 50 | 1. extract the tarfile-x.x.x.tar.gz archive to a temporary folder | ||
4261 | 51 | 2. type "python setup.py install" | ||
4262 | 52 | |||
4263 | 53 | |||
4264 | 54 | Contact | ||
4265 | 55 | ------- | ||
4266 | 56 | |||
4267 | 57 | Suggestions, comments, bug reports and patches to: | ||
4268 | 58 | lars@gustaebel.de | ||
4269 | 59 | |||
4270 | 60 | |||
4271 | 61 | License | ||
4272 | 62 | ------- | ||
4273 | 63 | |||
4274 | 64 | Copyright (C) 2002 Lars Gustäbel <lars@gustaebel.de> | ||
4275 | 65 | All rights reserved. | ||
4276 | 66 | |||
4277 | 67 | Permission is hereby granted, free of charge, to any person | ||
4278 | 68 | obtaining a copy of this software and associated documentation | ||
4279 | 69 | files (the "Software"), to deal in the Software without | ||
4280 | 70 | restriction, including without limitation the rights to use, | ||
4281 | 71 | copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
4282 | 72 | copies of the Software, and to permit persons to whom the | ||
4283 | 73 | Software is furnished to do so, subject to the following | ||
4284 | 74 | conditions: | ||
4285 | 75 | |||
4286 | 76 | The above copyright notice and this permission notice shall be | ||
4287 | 77 | included in all copies or substantial portions of the Software. | ||
4288 | 78 | |||
4289 | 79 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
4290 | 80 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
4291 | 81 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
4292 | 82 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
4293 | 83 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
4294 | 84 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
4295 | 85 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
4296 | 86 | OTHER DEALINGS IN THE SOFTWARE. | ||
4297 | 87 | |||
4298 | 88 | |||
4299 | 89 | README Version | ||
4300 | 90 | -------------- | ||
4301 | 91 | |||
4302 | 92 | $Id: tarfile-LICENSE,v 1.1 2002/10/29 01:49:46 bescoto Exp $ | ||
4303 | 93 | 0 | ||
4304 | === modified file 'testing/__init__.py' | |||
4305 | --- testing/__init__.py 2014-04-16 20:51:42 +0000 | |||
4306 | +++ testing/__init__.py 2014-04-16 20:51:42 +0000 | |||
4307 | @@ -1,3 +0,0 @@ | |||
4308 | 1 | import sys | ||
4309 | 2 | if sys.version_info < (2, 5,): | ||
4310 | 3 | import tests | ||
4311 | 4 | 0 | ||
4312 | === modified file 'testing/run-tests' | |||
4313 | --- testing/run-tests 2014-04-16 20:51:42 +0000 | |||
4314 | +++ testing/run-tests 2014-04-16 20:51:42 +0000 | |||
4315 | @@ -46,7 +46,7 @@ | |||
4316 | 46 | done | 46 | done |
4317 | 47 | 47 | ||
4318 | 48 | # run against all supported python versions | 48 | # run against all supported python versions |
4320 | 49 | for v in 2.4 2.5 2.6 2.7; do | 49 | for v in 2.6 2.7; do |
4321 | 50 | type python$v >& /dev/null | 50 | type python$v >& /dev/null |
4322 | 51 | if [ $? == 1 ]; then | 51 | if [ $? == 1 ]; then |
4323 | 52 | echo "python$v not found on system" | 52 | echo "python$v not found on system" |
4324 | 53 | 53 | ||
4325 | === modified file 'testing/run-tests-ve' | |||
4326 | --- testing/run-tests-ve 2014-04-16 20:51:42 +0000 | |||
4327 | +++ testing/run-tests-ve 2014-04-16 20:51:42 +0000 | |||
4328 | @@ -46,7 +46,7 @@ | |||
4329 | 46 | done | 46 | done |
4330 | 47 | 47 | ||
4331 | 48 | # run against all supported python versions | 48 | # run against all supported python versions |
4333 | 49 | for v in 2.4 2.5 2.6 2.7; do | 49 | for v in 2.6 2.7; do |
4334 | 50 | ve=~/virtual$v | 50 | ve=~/virtual$v |
4335 | 51 | if [ $? == 1 ]; then | 51 | if [ $? == 1 ]; then |
4336 | 52 | echo "virtual$v not found on system" | 52 | echo "virtual$v not found on system" |
4337 | 53 | 53 | ||
4338 | === modified file 'testing/tests/__init__.py' | |||
4339 | --- testing/tests/__init__.py 2014-04-16 20:51:42 +0000 | |||
4340 | +++ testing/tests/__init__.py 2014-04-16 20:51:42 +0000 | |||
4341 | @@ -41,12 +41,3 @@ | |||
4342 | 41 | # Standardize time | 41 | # Standardize time |
4343 | 42 | os.environ['TZ'] = 'US/Central' | 42 | os.environ['TZ'] = 'US/Central' |
4344 | 43 | time.tzset() | 43 | time.tzset() |
4345 | 44 | |||
4346 | 45 | # Automatically add all submodules into this namespace. Helps python2.4 | ||
4347 | 46 | # unittest work. | ||
4348 | 47 | if sys.version_info < (2, 5,): | ||
4349 | 48 | for module in os.listdir(_this_dir): | ||
4350 | 49 | if module == '__init__.py' or module[-3:] != '.py': | ||
4351 | 50 | continue | ||
4352 | 51 | __import__(module[:-3], locals(), globals()) | ||
4353 | 52 | del module | ||
4354 | 53 | 44 | ||
4355 | === modified file 'testing/tests/test_parsedurl.py' | |||
4356 | --- testing/tests/test_parsedurl.py 2011-11-04 04:33:06 +0000 | |||
4357 | +++ testing/tests/test_parsedurl.py 2014-04-16 20:51:42 +0000 | |||
4358 | @@ -55,6 +55,13 @@ | |||
4359 | 55 | assert pu.username is None, pu.username | 55 | assert pu.username is None, pu.username |
4360 | 56 | assert pu.port is None, pu.port | 56 | assert pu.port is None, pu.port |
4361 | 57 | 57 | ||
4362 | 58 | pu = duplicity.backend.ParsedUrl("file://home") | ||
4363 | 59 | assert pu.scheme == "file", pu.scheme | ||
4364 | 60 | assert pu.netloc == "", pu.netloc | ||
4365 | 61 | assert pu.path == "//home", pu.path | ||
4366 | 62 | assert pu.username is None, pu.username | ||
4367 | 63 | assert pu.port is None, pu.port | ||
4368 | 64 | |||
4369 | 58 | pu = duplicity.backend.ParsedUrl("ftp://foo@bar:pass@example.com:123/home") | 65 | pu = duplicity.backend.ParsedUrl("ftp://foo@bar:pass@example.com:123/home") |
4370 | 59 | assert pu.scheme == "ftp", pu.scheme | 66 | assert pu.scheme == "ftp", pu.scheme |
4371 | 60 | assert pu.netloc == "foo@bar:pass@example.com:123", pu.netloc | 67 | assert pu.netloc == "foo@bar:pass@example.com:123", pu.netloc |
4372 | @@ -121,7 +128,9 @@ | |||
4373 | 121 | def test_errors(self): | 128 | def test_errors(self): |
4374 | 122 | """Test various url errors""" | 129 | """Test various url errors""" |
4375 | 123 | self.assertRaises(InvalidBackendURL, duplicity.backend.ParsedUrl, | 130 | self.assertRaises(InvalidBackendURL, duplicity.backend.ParsedUrl, |
4377 | 124 | "ssh://foo@bar:pass@example.com:/home") | 131 | "ssh:///home") # we require a hostname for ssh |
4378 | 132 | self.assertRaises(InvalidBackendURL, duplicity.backend.ParsedUrl, | ||
4379 | 133 | "file:path") # no relative paths for non-netloc schemes | ||
4380 | 125 | self.assertRaises(UnsupportedBackendScheme, duplicity.backend.get_backend, | 134 | self.assertRaises(UnsupportedBackendScheme, duplicity.backend.get_backend, |
4381 | 126 | "foo://foo@bar:pass@example.com/home") | 135 | "foo://foo@bar:pass@example.com/home") |
4382 | 127 | 136 | ||
4383 | 128 | 137 | ||
4384 | === modified file 'testing/tests/test_tarfile.py' | |||
4385 | --- testing/tests/test_tarfile.py 2013-07-12 19:47:32 +0000 | |||
4386 | +++ testing/tests/test_tarfile.py 2014-04-16 20:51:42 +0000 | |||
4387 | @@ -1,7 +1,6 @@ | |||
4388 | 1 | # -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- | 1 | # -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- |
4389 | 2 | # | 2 | # |
4392 | 3 | # Copyright 2002 Ben Escoto <ben@emerose.org> | 3 | # Copyright 2013 Michael Terry <mike@mterry.name> |
4391 | 4 | # Copyright 2007 Kenneth Loafman <kenneth@loafman.com> | ||
4393 | 5 | # | 4 | # |
4394 | 6 | # This file is part of duplicity. | 5 | # This file is part of duplicity. |
4395 | 7 | # | 6 | # |
4396 | @@ -19,309 +18,18 @@ | |||
4397 | 19 | # along with duplicity; if not, write to the Free Software Foundation, | 18 | # along with duplicity; if not, write to the Free Software Foundation, |
4398 | 20 | # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 19 | # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
4399 | 21 | 20 | ||
4400 | 22 | # | ||
4401 | 23 | # unittest for the tarfile module | ||
4402 | 24 | # | ||
4403 | 25 | # $Id: test_tarfile.py,v 1.11 2009/04/02 14:47:12 loafman Exp $ | ||
4404 | 26 | |||
4405 | 27 | import helper | 21 | import helper |
4408 | 28 | import sys, os, shutil, StringIO, tempfile, unittest, stat | 22 | import unittest |
4409 | 29 | 23 | from duplicity import cached_ops | |
4410 | 30 | from duplicity import tarfile | 24 | from duplicity import tarfile |
4411 | 31 | 25 | ||
4412 | 32 | helper.setup() | 26 | helper.setup() |
4413 | 33 | 27 | ||
4705 | 34 | SAMPLETAR = "testtar.tar" | 28 | |
4706 | 35 | TEMPDIR = tempfile.mktemp() | 29 | class TarfileTest(unittest.TestCase): |
4707 | 36 | 30 | def test_cached_ops(self): | |
4708 | 37 | def join(*args): | 31 | self.assertTrue(tarfile.grp is cached_ops) |
4709 | 38 | return os.path.normpath(apply(os.path.join, args)) | 32 | self.assertTrue(tarfile.pwd is cached_ops) |
4419 | 39 | |||
4420 | 40 | class BaseTest(unittest.TestCase): | ||
4421 | 41 | """Base test for tarfile. | ||
4422 | 42 | """ | ||
4423 | 43 | |||
4424 | 44 | def setUp(self): | ||
4425 | 45 | os.mkdir(TEMPDIR) | ||
4426 | 46 | self.tar = tarfile.open(SAMPLETAR) | ||
4427 | 47 | self.tar.errorlevel = 1 | ||
4428 | 48 | |||
4429 | 49 | def tearDown(self): | ||
4430 | 50 | self.tar.close() | ||
4431 | 51 | shutil.rmtree(TEMPDIR) | ||
4432 | 52 | |||
4433 | 53 | def isroot(self): | ||
4434 | 54 | return hasattr(os, "geteuid") and os.geteuid() == 0 | ||
4435 | 55 | |||
4436 | 56 | class Test_All(BaseTest): | ||
4437 | 57 | """Allround test. | ||
4438 | 58 | """ | ||
4439 | 59 | files_in_tempdir = ["tempdir", | ||
4440 | 60 | "tempdir/0length", | ||
4441 | 61 | "tempdir/large", | ||
4442 | 62 | "tempdir/hardlinked1", | ||
4443 | 63 | "tempdir/hardlinked2", | ||
4444 | 64 | "tempdir/fifo", | ||
4445 | 65 | "tempdir/symlink"] | ||
4446 | 66 | |||
4447 | 67 | tempdir_data = {"0length": "", | ||
4448 | 68 | "large": "hello, world!" * 10000, | ||
4449 | 69 | "hardlinked1": "foo", | ||
4450 | 70 | "hardlinked2": "foo"} | ||
4451 | 71 | |||
4452 | 72 | def test_iteration(self): | ||
4453 | 73 | """Test iteration through temp2.tar""" | ||
4454 | 74 | self.make_temptar() | ||
4455 | 75 | i = 0 | ||
4456 | 76 | tf = tarfile.TarFile("none", "r", FileLogger(open("temp2.tar", "rb"))) | ||
4457 | 77 | tf.debug = 3 | ||
4458 | 78 | for tarinfo in tf: i += 1 #@UnusedVariable | ||
4459 | 79 | assert i >= 6, i | ||
4460 | 80 | |||
4461 | 81 | def _test_extraction(self): | ||
4462 | 82 | """Test if regular files and links are extracted correctly. | ||
4463 | 83 | """ | ||
4464 | 84 | for tarinfo in self.tar: | ||
4465 | 85 | if tarinfo.isreg() or tarinfo.islnk() or tarinfo.issym(): | ||
4466 | 86 | self.tar.extract(tarinfo, TEMPDIR) | ||
4467 | 87 | name = join(TEMPDIR, tarinfo.name) | ||
4468 | 88 | data1 = file(name, "rb").read() | ||
4469 | 89 | data2 = self.tar.extractfile(tarinfo).read() | ||
4470 | 90 | self.assert_(data1 == data2, | ||
4471 | 91 | "%s was not extracted successfully." | ||
4472 | 92 | % tarinfo.name) | ||
4473 | 93 | |||
4474 | 94 | if not tarinfo.issym(): | ||
4475 | 95 | self.assert_(tarinfo.mtime == os.path.getmtime(name), | ||
4476 | 96 | "%s's modification time was not set correctly." | ||
4477 | 97 | % tarinfo.name) | ||
4478 | 98 | |||
4479 | 99 | if tarinfo.isdev(): | ||
4480 | 100 | if hasattr(os, "mkfifo") and tarinfo.isfifo(): | ||
4481 | 101 | self.tar.extract(tarinfo, TEMPDIR) | ||
4482 | 102 | name = join(TEMPDIR, tarinfo.name) | ||
4483 | 103 | self.assert_(tarinfo.mtime == os.path.getmtime(name), | ||
4484 | 104 | "%s's modification time was not set correctly." | ||
4485 | 105 | % tarinfo.name) | ||
4486 | 106 | |||
4487 | 107 | elif hasattr(os, "mknod") and self.isroot(): | ||
4488 | 108 | self.tar.extract(tarinfo, TEMPDIR) | ||
4489 | 109 | name = join(TEMPDIR, tarinfo.name) | ||
4490 | 110 | self.assert_(tarinfo.mtime == os.path.getmtime(name), | ||
4491 | 111 | "%s's modification time was not set correctly." | ||
4492 | 112 | % tarinfo.name) | ||
4493 | 113 | |||
4494 | 114 | def test_addition(self): | ||
4495 | 115 | """Test if regular files are added correctly. | ||
4496 | 116 | For this, we extract all regular files from our sample tar | ||
4497 | 117 | and add them to a new one, which we check afterwards. | ||
4498 | 118 | """ | ||
4499 | 119 | files = [] | ||
4500 | 120 | for tarinfo in self.tar: | ||
4501 | 121 | if tarinfo.isreg(): | ||
4502 | 122 | self.tar.extract(tarinfo, TEMPDIR) | ||
4503 | 123 | files.append(tarinfo.name) | ||
4504 | 124 | |||
4505 | 125 | buf = StringIO.StringIO() | ||
4506 | 126 | tar = tarfile.open("test.tar", "w", buf) | ||
4507 | 127 | for f in files: | ||
4508 | 128 | path = join(TEMPDIR, f) | ||
4509 | 129 | tarinfo = tar.gettarinfo(path) | ||
4510 | 130 | tarinfo.name = f | ||
4511 | 131 | tar.addfile(tarinfo, file(path, "rb")) | ||
4512 | 132 | tar.close() | ||
4513 | 133 | |||
4514 | 134 | buf.seek(0) | ||
4515 | 135 | tar = tarfile.open("test.tar", "r", buf) | ||
4516 | 136 | for tarinfo in tar: | ||
4517 | 137 | data1 = file(join(TEMPDIR, tarinfo.name), "rb").read() | ||
4518 | 138 | data2 = tar.extractfile(tarinfo).read() | ||
4519 | 139 | self.assert_(data1 == data2) | ||
4520 | 140 | tar.close() | ||
4521 | 141 | |||
4522 | 142 | def make_tempdir(self): | ||
4523 | 143 | """Make a temp directory with assorted files in it""" | ||
4524 | 144 | try: | ||
4525 | 145 | os.lstat("tempdir") | ||
4526 | 146 | except OSError: | ||
4527 | 147 | pass | ||
4528 | 148 | else: # assume already exists | ||
4529 | 149 | assert not os.system("rm -r tempdir") | ||
4530 | 150 | os.mkdir("tempdir") | ||
4531 | 151 | |||
4532 | 152 | def write_file(name): | ||
4533 | 153 | """Write appropriate data into file named name in tempdir""" | ||
4534 | 154 | fp = open("tempdir/%s" % (name,), "wb") | ||
4535 | 155 | fp.write(self.tempdir_data[name]) | ||
4536 | 156 | fp.close() | ||
4537 | 157 | |||
4538 | 158 | # Make 0length file | ||
4539 | 159 | write_file("0length") | ||
4540 | 160 | os.chmod("tempdir/%s" % ("0length",), 0604) | ||
4541 | 161 | |||
4542 | 162 | # Make regular file 130000 bytes in length | ||
4543 | 163 | write_file("large") | ||
4544 | 164 | |||
4545 | 165 | # Make hard linked files | ||
4546 | 166 | write_file("hardlinked1") | ||
4547 | 167 | os.link("tempdir/hardlinked1", "tempdir/hardlinked2") | ||
4548 | 168 | |||
4549 | 169 | # Make a fifo | ||
4550 | 170 | os.mkfifo("tempdir/fifo") | ||
4551 | 171 | |||
4552 | 172 | # Make symlink | ||
4553 | 173 | os.symlink("foobar", "tempdir/symlink") | ||
4554 | 174 | |||
4555 | 175 | def make_temptar(self): | ||
4556 | 176 | """Tar up tempdir, write to "temp2.tar" """ | ||
4557 | 177 | try: | ||
4558 | 178 | os.lstat("temp2.tar") | ||
4559 | 179 | except OSError: | ||
4560 | 180 | pass | ||
4561 | 181 | else: | ||
4562 | 182 | assert not os.system("rm temp2.tar") | ||
4563 | 183 | |||
4564 | 184 | self.make_tempdir() | ||
4565 | 185 | tf = tarfile.TarFile("temp2.tar", "w") | ||
4566 | 186 | for filename in self.files_in_tempdir: | ||
4567 | 187 | tf.add(filename, filename, 0) | ||
4568 | 188 | tf.close() | ||
4569 | 189 | |||
4570 | 190 | def test_tarfile_creation(self): | ||
4571 | 191 | """Create directory, make tarfile, extract using gnutar, compare""" | ||
4572 | 192 | self.make_temptar() | ||
4573 | 193 | self.extract_and_compare_tarfile() | ||
4574 | 194 | |||
4575 | 195 | def extract_and_compare_tarfile(self): | ||
4576 | 196 | old_umask = os.umask(022) | ||
4577 | 197 | os.system("rm -r tempdir") | ||
4578 | 198 | assert not os.system("tar -xf temp2.tar") | ||
4579 | 199 | |||
4580 | 200 | def compare_data(name): | ||
4581 | 201 | """Assert data is what should be""" | ||
4582 | 202 | fp = open("tempdir/" + name, "rb") | ||
4583 | 203 | buf = fp.read() | ||
4584 | 204 | fp.close() | ||
4585 | 205 | assert buf == self.tempdir_data[name] | ||
4586 | 206 | |||
4587 | 207 | s = os.lstat("tempdir") | ||
4588 | 208 | assert stat.S_ISDIR(s.st_mode) | ||
4589 | 209 | |||
4590 | 210 | for key in self.tempdir_data: compare_data(key) | ||
4591 | 211 | |||
4592 | 212 | # Check to make sure permissions saved | ||
4593 | 213 | s = os.lstat("tempdir/0length") | ||
4594 | 214 | assert stat.S_IMODE(s.st_mode) == 0604, stat.S_IMODE(s.st_mode) | ||
4595 | 215 | |||
4596 | 216 | s = os.lstat("tempdir/fifo") | ||
4597 | 217 | assert stat.S_ISFIFO(s.st_mode) | ||
4598 | 218 | |||
4599 | 219 | # Check to make sure hardlinked files still hardlinked | ||
4600 | 220 | s1 = os.lstat("tempdir/hardlinked1") | ||
4601 | 221 | s2 = os.lstat("tempdir/hardlinked2") | ||
4602 | 222 | assert s1.st_ino == s2.st_ino | ||
4603 | 223 | |||
4604 | 224 | # Check symlink | ||
4605 | 225 | s = os.lstat("tempdir/symlink") | ||
4606 | 226 | assert stat.S_ISLNK(s.st_mode) | ||
4607 | 227 | |||
4608 | 228 | os.umask(old_umask) | ||
4609 | 229 | |||
4610 | 230 | class Test_FObj(BaseTest): | ||
4611 | 231 | """Test for read operations via file-object. | ||
4612 | 232 | """ | ||
4613 | 233 | |||
4614 | 234 | def _test_sparse(self): | ||
4615 | 235 | """Test extraction of the sparse file. | ||
4616 | 236 | """ | ||
4617 | 237 | BLOCK = 4096 | ||
4618 | 238 | for tarinfo in self.tar: | ||
4619 | 239 | if tarinfo.issparse(): | ||
4620 | 240 | f = self.tar.extractfile(tarinfo) | ||
4621 | 241 | b = 0 | ||
4622 | 242 | block = 0 | ||
4623 | 243 | while 1: | ||
4624 | 244 | buf = f.read(BLOCK) | ||
4625 | 245 | if not buf: | ||
4626 | 246 | break | ||
4627 | 247 | block += 1 | ||
4628 | 248 | self.assert_(BLOCK == len(buf)) | ||
4629 | 249 | if not b: | ||
4630 | 250 | self.assert_("\0" * BLOCK == buf, | ||
4631 | 251 | "sparse block is broken") | ||
4632 | 252 | else: | ||
4633 | 253 | self.assert_("0123456789ABCDEF" * 256 == buf, | ||
4634 | 254 | "sparse block is broken") | ||
4635 | 255 | b = 1 - b | ||
4636 | 256 | self.assert_(block == 24, "too few sparse blocks") | ||
4637 | 257 | f.close() | ||
4638 | 258 | |||
4639 | 259 | def _test_readlines(self): | ||
4640 | 260 | """Test readlines() method of _FileObject. | ||
4641 | 261 | """ | ||
4642 | 262 | self.tar.extract("pep.txt", TEMPDIR) | ||
4643 | 263 | lines1 = file(join(TEMPDIR, "pep.txt"), "r").readlines() | ||
4644 | 264 | lines2 = self.tar.extractfile("pep.txt").readlines() | ||
4645 | 265 | self.assert_(lines1 == lines2, "readline() does not work correctly") | ||
4646 | 266 | |||
4647 | 267 | def _test_seek(self): | ||
4648 | 268 | """Test seek() method of _FileObject, incl. random reading. | ||
4649 | 269 | """ | ||
4650 | 270 | self.tar.extract("pep.txt", TEMPDIR) | ||
4651 | 271 | data = file(join(TEMPDIR, "pep.txt"), "rb").read() | ||
4652 | 272 | |||
4653 | 273 | tarinfo = self.tar.getmember("pep.txt") | ||
4654 | 274 | fobj = self.tar.extractfile(tarinfo) | ||
4655 | 275 | |||
4656 | 276 | text = fobj.read() #@UnusedVariable | ||
4657 | 277 | fobj.seek(0) | ||
4658 | 278 | self.assert_(0 == fobj.tell(), | ||
4659 | 279 | "seek() to file's start failed") | ||
4660 | 280 | fobj.seek(4096, 0) | ||
4661 | 281 | self.assert_(4096 == fobj.tell(), | ||
4662 | 282 | "seek() to absolute position failed") | ||
4663 | 283 | fobj.seek(-2048, 1) | ||
4664 | 284 | self.assert_(2048 == fobj.tell(), | ||
4665 | 285 | "seek() to negative relative position failed") | ||
4666 | 286 | fobj.seek(2048, 1) | ||
4667 | 287 | self.assert_(4096 == fobj.tell(), | ||
4668 | 288 | "seek() to positive relative position failed") | ||
4669 | 289 | s = fobj.read(10) | ||
4670 | 290 | self.assert_(s == data[4096:4106], | ||
4671 | 291 | "read() after seek failed") | ||
4672 | 292 | fobj.seek(0, 2) | ||
4673 | 293 | self.assert_(tarinfo.size == fobj.tell(), | ||
4674 | 294 | "seek() to file's end failed") | ||
4675 | 295 | self.assert_(fobj.read() == "", | ||
4676 | 296 | "read() at file's end did not return empty string") | ||
4677 | 297 | fobj.seek(-tarinfo.size, 2) | ||
4678 | 298 | self.assert_(0 == fobj.tell(), | ||
4679 | 299 | "relative seek() to file's start failed") | ||
4680 | 300 | fobj.seek(1024) | ||
4681 | 301 | s1 = fobj.readlines() | ||
4682 | 302 | fobj.seek(1024) | ||
4683 | 303 | s2 = fobj.readlines() | ||
4684 | 304 | self.assert_(s1 == s2, | ||
4685 | 305 | "readlines() after seek failed") | ||
4686 | 306 | fobj.close() | ||
4687 | 307 | |||
4688 | 308 | class FileLogger: | ||
4689 | 309 | """Like a file but log requests""" | ||
4690 | 310 | def __init__(self, infp): | ||
4691 | 311 | self.infp = infp | ||
4692 | 312 | def read(self, length): | ||
4693 | 313 | #print "Reading ", length | ||
4694 | 314 | return self.infp.read(length) | ||
4695 | 315 | def seek(self, position): | ||
4696 | 316 | #print "Seeking to ", position | ||
4697 | 317 | return self.infp.seek(position) | ||
4698 | 318 | def tell(self): | ||
4699 | 319 | #print "Telling" | ||
4700 | 320 | return self.infp.tell() | ||
4701 | 321 | def close(self): | ||
4702 | 322 | #print "Closing" | ||
4703 | 323 | return self.infp.close() | ||
4704 | 324 | |||
4710 | 325 | 33 | ||
4711 | 326 | if __name__ == "__main__": | 34 | if __name__ == "__main__": |
4712 | 327 | unittest.main() | 35 | unittest.main() |
4713 | 328 | 36 | ||
4714 | === modified file 'testing/tests/test_unicode.py' | |||
4715 | --- testing/tests/test_unicode.py 2013-12-27 06:39:00 +0000 | |||
4716 | +++ testing/tests/test_unicode.py 2014-04-16 20:51:42 +0000 | |||
4717 | @@ -29,13 +29,11 @@ | |||
4718 | 29 | if 'duplicity' in sys.modules: | 29 | if 'duplicity' in sys.modules: |
4719 | 30 | del(sys.modules["duplicity"]) | 30 | del(sys.modules["duplicity"]) |
4720 | 31 | 31 | ||
4722 | 32 | @patch('gettext.translation') | 32 | @patch('gettext.install') |
4723 | 33 | def test_module_install(self, gettext_mock): | 33 | def test_module_install(self, gettext_mock): |
4724 | 34 | """Make sure we convert translations to unicode""" | 34 | """Make sure we convert translations to unicode""" |
4725 | 35 | import duplicity | 35 | import duplicity |
4729 | 36 | gettext_mock.assert_called_once_with('duplicity', fallback=True) | 36 | gettext_mock.assert_called_once_with('duplicity', unicode=True, names=['ngettext']) |
4727 | 37 | gettext_mock.return_value.install.assert_called_once_with(unicode=True) | ||
4728 | 38 | assert ngettext is gettext_mock.return_value.ungettext | ||
4730 | 39 | 37 | ||
4731 | 40 | if __name__ == "__main__": | 38 | if __name__ == "__main__": |
4732 | 41 | unittest.main() | 39 | unittest.main() |
4733 | 42 | 40 | ||
4734 | === removed file 'testing/testtar.tar' | |||
4735 | 43 | Binary files testing/testtar.tar 2002-10-29 01:49:46 +0000 and testing/testtar.tar 1970-01-01 00:00:00 +0000 differ | 41 | Binary files testing/testtar.tar 2002-10-29 01:49:46 +0000 and testing/testtar.tar 1970-01-01 00:00:00 +0000 differ |
/me hugs Ken