Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 54 lines (39 sloc) 1.571 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
## Amazon S3 manager
## Author: Michal Ludvig <michal@logix.cz>
## http://www.logix.cz/michal
## License: GPL Version 2

import sys
import os
import logging

from optparse import OptionParser, Option, OptionValueError, IndentedHelpFormatter
from logging import debug, info, warning, error

## Our modules
from S3 import PkgInfo
from S3.SimpleDB import SimpleDB
from S3.Config import Config
from S3.Exceptions import *

def display_response(response):
print "%s\n%s\n%s" % ('-'*40, response['data'], '-'*40)

if __name__ == '__main__':
if float("%d.%d" %(sys.version_info[0], sys.version_info[1])) < 2.4:
sys.stderr.write("ERROR: Python 2.4 or higher required, sorry.\n")
sys.exit(1)
cfg = Config(os.getenv("HOME")+"/.s3cfg")

logging.root.setLevel(logging.DEBUG)
sdb = SimpleDB(cfg)

try:
display_response(sdb.ListDomains())

display_response(sdb.CreateDomain("logix.cz-test"))

display_response(sdb.ListDomains())

display_response(sdb.PutAttributes("logix.cz-test", "AbCd", {'First': "One", "Second" : 2, "Third" : u"drei"}))
display_response(sdb.PutAttributes("logix.cz-test", "XyZ", {'xyz' : ['x', 'y', 'z'], 'Third' : u'traja'}))

display_response(sdb.GetAttributes("logix.cz-test", "AbCd", ['Second', 'Third']))
display_response(sdb.GetAttributes("logix.cz-test", "XyZ"))

display_response(sdb.Query("logix.cz-test", "['xyz' = 'z']"))

display_response(sdb.DeleteDomain("logix.cz-test"))

display_response(sdb.ListDomains())
except S3Error, e:
error(e)
error(e.info)
Something went wrong with that request. Please try again.