Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: third_party/gsutil/20110627/boto/boto/file/bucket.py

Issue 10199002: Upgrade gsutil to 3.4 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright 2010 Google Inc.
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish, dis-
7 # tribute, sublicense, and/or sell copies of the Software, and to permit
8 # persons to whom the Software is furnished to do so, subject to the fol-
9 # lowing conditions:
10 #
11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE.
21
22 # File representation of bucket, for use with "file://" URIs.
23
24 import os
25 from key import Key
26 from boto.file.simpleresultset import SimpleResultSet
27 from boto.s3.bucketlistresultset import BucketListResultSet
28
29 class Bucket(object):
30 def __init__(self, name, contained_key):
31 """Instantiate an anonymous file-based Bucket around a single key.
32 """
33 self.name = name
34 self.contained_key = contained_key
35
36 def __iter__(self):
37 return iter(BucketListResultSet(self))
38
39 def __str__(self):
40 return 'anonymous bucket for file://' + self.contained_key
41
42 def delete_key(self, key_name, headers=None,
43 version_id=None, mfa_token=None):
44 """
45 Deletes a key from the bucket.
46
47 :type key_name: string
48 :param key_name: The key name to delete
49
50 :type version_id: string
51 :param version_id: Unused in this subclass.
52
53 :type mfa_token: tuple or list of strings
54 :param mfa_token: Unused in this subclass.
55 """
56 os.remove(key_name)
57
58 def get_all_keys(self, headers=None, **params):
59 """
60 This method returns the single key around which this anonymous Bucket
61 was instantiated.
62
63 :rtype: SimpleResultSet
64 :return: The result from file system listing the keys requested
65
66 """
67 key = Key(self.name, self.contained_key)
68 return SimpleResultSet([key])
69
70 def get_key(self, key_name, headers=None, version_id=None):
71 """
72 Check to see if a particular key exists within the bucket.
73 Returns: An instance of a Key object or None
74
75 :type key_name: string
76 :param key_name: The name of the key to retrieve
77
78 :type version_id: string
79 :param version_id: Unused in this subclass.
80
81 :rtype: :class:`boto.file.key.Key`
82 :returns: A Key object from this bucket.
83 """
84 fp = open(key_name, 'rb')
85 return Key(self.name, key_name, fp)
86
87 def new_key(self, key_name=None):
88 """
89 Creates a new key
90
91 :type key_name: string
92 :param key_name: The name of the key to create
93
94 :rtype: :class:`boto.file.key.Key`
95 :returns: An instance of the newly created key object
96 """
97 dir_name = os.path.dirname(key_name)
98 if dir_name and not os.path.exists(dir_name):
99 os.makedirs(dir_name)
100 fp = open(key_name, 'wb')
101 return Key(self.name, key_name, fp)
OLDNEW
« no previous file with comments | « third_party/gsutil/20110627/boto/boto/file/__init__.py ('k') | third_party/gsutil/20110627/boto/boto/file/connection.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698