OLD | NEW |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 # Copyright 2012 Google Inc. All Rights Reserved. | 2 # Copyright 2012 Google Inc. All Rights Reserved. |
3 # | 3 # |
4 # Licensed under the Apache License, Version 2.0 (the "License"); | 4 # Licensed under the Apache License, Version 2.0 (the "License"); |
5 # you may not use this file except in compliance with the License. | 5 # you may not use this file except in compliance with the License. |
6 # You may obtain a copy of the License at | 6 # You may obtain a copy of the License at |
7 # | 7 # |
8 # http://www.apache.org/licenses/LICENSE-2.0 | 8 # http://www.apache.org/licenses/LICENSE-2.0 |
9 # | 9 # |
10 # Unless required by applicable law or agreed to in writing, software | 10 # Unless required by applicable law or agreed to in writing, software |
11 # distributed under the License is distributed on an "AS IS" BASIS, | 11 # distributed under the License is distributed on an "AS IS" BASIS, |
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 # See the License for the specific language governing permissions and | 13 # See the License for the specific language governing permissions and |
14 # limitations under the License. | 14 # limitations under the License. |
15 """Name expansion iterator and result classes. | 15 """Name expansion iterator and result classes. |
16 | 16 |
17 Name expansion support for the various ways gsutil lets users refer to | 17 Name expansion support for the various ways gsutil lets users refer to |
18 collections of data (via explicit wildcarding as well as directory, | 18 collections of data (via explicit wildcarding as well as directory, |
19 bucket, and bucket subdir implicit wildcarding). This class encapsulates | 19 bucket, and bucket subdir implicit wildcarding). This class encapsulates |
20 the various rules for determining how these expansions are done. | 20 the various rules for determining how these expansions are done. |
21 """ | 21 """ |
22 | 22 |
23 # Disable warnings for NameExpansionIteratorQueue functions; they implement | 23 # Disable warnings for NameExpansionIteratorQueue functions; they implement |
24 # an interface which does not follow lint guidelines. | 24 # an interface which does not follow lint guidelines. |
25 # pylint: disable=invalid-name | 25 # pylint: disable=invalid-name |
26 | 26 |
27 from __future__ import absolute_import | 27 from __future__ import absolute_import |
28 | 28 |
29 import multiprocessing | |
30 import os | 29 import os |
31 import sys | 30 import sys |
32 | 31 |
| 32 import gslib |
33 from gslib.exception import CommandException | 33 from gslib.exception import CommandException |
34 from gslib.plurality_checkable_iterator import PluralityCheckableIterator | 34 from gslib.plurality_checkable_iterator import PluralityCheckableIterator |
35 import gslib.wildcard_iterator | 35 import gslib.wildcard_iterator |
36 from gslib.wildcard_iterator import StorageUrlFromString | 36 from gslib.wildcard_iterator import StorageUrlFromString |
37 | 37 |
38 | 38 |
39 class NameExpansionResult(object): | 39 class NameExpansionResult(object): |
40 """Holds one fully expanded result from iterating over NameExpansionIterator. | 40 """Holds one fully expanded result from iterating over NameExpansionIterator. |
41 | 41 |
42 The member data in this class need to be pickleable because | 42 The member data in this class need to be pickleable because |
(...skipping 20 matching lines...) Expand all Loading... |
63 more than one BucketListingRef. | 63 more than one BucketListingRef. |
64 names_container: Bool indicator whether src_url names a container. | 64 names_container: Bool indicator whether src_url names a container. |
65 expanded_storage_url: StorageUrl that was expanded. | 65 expanded_storage_url: StorageUrl that was expanded. |
66 """ | 66 """ |
67 self.source_storage_url = source_storage_url | 67 self.source_storage_url = source_storage_url |
68 self.is_multi_source_request = is_multi_source_request | 68 self.is_multi_source_request = is_multi_source_request |
69 self.names_container = names_container | 69 self.names_container = names_container |
70 self.expanded_storage_url = expanded_storage_url | 70 self.expanded_storage_url = expanded_storage_url |
71 | 71 |
72 def __repr__(self): | 72 def __repr__(self): |
73 return '%s' % self._expanded_storage_url | 73 return '%s' % self.expanded_storage_url |
74 | 74 |
75 | 75 |
76 class _NameExpansionIterator(object): | 76 class _NameExpansionIterator(object): |
77 """Class that iterates over all source URLs passed to the iterator. | 77 """Class that iterates over all source URLs passed to the iterator. |
78 | 78 |
79 See details in __iter__ function doc. | 79 See details in __iter__ function doc. |
80 """ | 80 """ |
81 | 81 |
82 def __init__(self, command_name, debug, logger, gsutil_api, url_strs, | 82 def __init__(self, command_name, debug, logger, gsutil_api, url_strs, |
83 recursion_requested, all_versions=False, | 83 recursion_requested, all_versions=False, |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 Only a blocking get() function can be called, and the block and timeout | 348 Only a blocking get() function can be called, and the block and timeout |
349 params on that function are ignored. All other class functions raise | 349 params on that function are ignored. All other class functions raise |
350 NotImplementedError. | 350 NotImplementedError. |
351 | 351 |
352 This class is thread safe. | 352 This class is thread safe. |
353 """ | 353 """ |
354 | 354 |
355 def __init__(self, name_expansion_iterator, final_value): | 355 def __init__(self, name_expansion_iterator, final_value): |
356 self.name_expansion_iterator = name_expansion_iterator | 356 self.name_expansion_iterator = name_expansion_iterator |
357 self.final_value = final_value | 357 self.final_value = final_value |
358 self.lock = multiprocessing.Manager().Lock() | 358 self.lock = gslib.util.manager.Lock() |
359 | 359 |
360 def qsize(self): | 360 def qsize(self): |
361 raise NotImplementedError( | 361 raise NotImplementedError( |
362 'NameExpansionIteratorQueue.qsize() not implemented') | 362 'NameExpansionIteratorQueue.qsize() not implemented') |
363 | 363 |
364 def empty(self): | 364 def empty(self): |
365 raise NotImplementedError( | 365 raise NotImplementedError( |
366 'NameExpansionIteratorQueue.empty() not implemented') | 366 'NameExpansionIteratorQueue.empty() not implemented') |
367 | 367 |
368 def full(self): | 368 def full(self): |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 yield (True, exp_blr) | 521 yield (True, exp_blr) |
522 else: | 522 else: |
523 # Prefix that contains no objects, for example in the $folder$ case | 523 # Prefix that contains no objects, for example in the $folder$ case |
524 # or an empty filesystem directory. | 524 # or an empty filesystem directory. |
525 yield (False, blr) | 525 yield (False, blr) |
526 elif blr.IsObject(): | 526 elif blr.IsObject(): |
527 yield (False, blr) | 527 yield (False, blr) |
528 else: | 528 else: |
529 raise CommandException( | 529 raise CommandException( |
530 '_ImplicitBucketSubdirIterator got a bucket reference %s' % blr) | 530 '_ImplicitBucketSubdirIterator got a bucket reference %s' % blr) |
OLD | NEW |