Skip to content
This repository has been archived by the owner on Nov 4, 2018. It is now read-only.

Commit

Permalink
* s3cmd, S3/S3.py: New command 'ib' to get information about
Browse files Browse the repository at this point in the history
	  bucket (only 'LocationConstraint' supported for now).



git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@154 830e0280-6d2a-0410-9c65-932aecc39d9d
  • Loading branch information
mludvig committed Nov 12, 2007
1 parent a368faf commit 8215784
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

* s3cmd: Support for storing file attributes (like ownership,
mode, etc) in sync operation.
* s3cmd, S3/S3.py: New command 'ib' to get information about
bucket (only 'LocationConstraint' supported for now).

2007-10-01 Michal Ludvig <michal@logix.cz>

Expand Down
8 changes: 8 additions & 0 deletions S3/S3.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ def bucket_delete(self, bucket):
response = self.send_request(request)
return response

def bucket_info(self, bucket):
request = self.create_request("BUCKET_LIST", bucket = bucket + "?location")
response = self.send_request(request)
response['bucket-location'] = getTextFromXml(response['data'], ".//LocationConstraint") or "any"
return response

def object_put(self, filename, bucket, object, extra_headers = None):
if not os.path.isfile(filename):
raise ParameterError("%s is not a regular file" % filename)
Expand Down Expand Up @@ -256,6 +262,8 @@ def create_request(self, operation, bucket = None, object = None, headers = None
for param in params:
if params[param] not in (None, ""):
param_str += "&%s=%s" % (param, params[param])
else:
param_str += "&%s" % param
if param_str != "":
resource += "?" + param_str[1:]
debug("CreateRequest: resource=" + resource)
Expand Down
17 changes: 17 additions & 0 deletions s3cmd
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ def cmd_bucket_delete(args):
raise
output("Bucket '%s' removed" % uri.bucket())

def cmd_bucket_info(args):
uri = S3Uri(args[0])
if not uri.type == "s3" or not uri.has_bucket() or uri.has_object():
raise ParameterError("Expecting S3 URI with just the bucket name set instead of '%s'" % args[0])
try:
s3 = S3(Config())
response = s3.bucket_info(uri.bucket())
except S3Error, e:
if S3.codes.has_key(e.info["Code"]):
error(S3.codes[e.info["Code"]] % uri.bucket())
return
else:
raise
output("Bucket '%s':" % uri.bucket())
output(" Location: %s" % response['bucket-location'])

def cmd_object_put(args):
s3 = S3(Config())

Expand Down Expand Up @@ -566,6 +582,7 @@ commands = {}
commands_list = [
{"cmd":"mb", "label":"Make bucket", "param":"s3://BUCKET", "func":cmd_bucket_create, "argc":1},
{"cmd":"rb", "label":"Remove bucket", "param":"s3://BUCKET", "func":cmd_bucket_delete, "argc":1},
{"cmd":"ib", "label":"Bucket information", "param":"s3://BUCKET", "func":cmd_bucket_info, "argc":1},
{"cmd":"ls", "label":"List objects or buckets", "param":"[s3://BUCKET[/PREFIX]]", "func":cmd_ls, "argc":0},
{"cmd":"la", "label":"List all object in all buckets", "param":"", "func":cmd_buckets_list_all_all, "argc":0},
{"cmd":"put", "label":"Put file into bucket", "param":"FILE [FILE...] s3://BUCKET[/PREFIX]", "func":cmd_object_put, "argc":2},
Expand Down

0 comments on commit 8215784

Please sign in to comment.