Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 56 lines (40 sloc) 1.699 kb
d2b144d Michael Ludvig 2008-04-29 Michal Ludvig <michal@logix.cz>
mludvig authored
1 #!/usr/bin/env python
add6b7f Michael Ludvig 2008-04-30 Michal Ludvig <michal@logix.cz>
mludvig authored
2 # vim: set fileencoding=utf-8 :
d2b144d Michael Ludvig 2008-04-29 Michal Ludvig <michal@logix.cz>
mludvig authored
3 ## Amazon S3 manager
4 ## Author: Michal Ludvig <michal@logix.cz>
5 ## http://www.logix.cz/michal
6 ## License: GPL Version 2
7
8 import sys
9 import os
10 import logging
11
12 from optparse import OptionParser, Option, OptionValueError, IndentedHelpFormatter
13 from logging import debug, info, warning, error
14
15 ## Our modules
16 from S3 import PkgInfo
17 from S3.SimpleDB import SimpleDB
18 from S3.Config import Config
19 from S3.Exceptions import *
20
add6b7f Michael Ludvig 2008-04-30 Michal Ludvig <michal@logix.cz>
mludvig authored
21 def display_response(response):
d439efb Michael Ludvig ATTENTION -- Mega WhiteSpace conversion !!!
mludvig authored
22 print "%s\n%s\n%s" % ('-'*40, response['data'], '-'*40)
23
d2b144d Michael Ludvig 2008-04-29 Michal Ludvig <michal@logix.cz>
mludvig authored
24 if __name__ == '__main__':
d439efb Michael Ludvig ATTENTION -- Mega WhiteSpace conversion !!!
mludvig authored
25 if float("%d.%d" %(sys.version_info[0], sys.version_info[1])) < 2.4:
26 sys.stderr.write("ERROR: Python 2.4 or higher required, sorry.\n")
27 sys.exit(1)
28 cfg = Config(os.getenv("HOME")+"/.s3cfg")
29
30 logging.root.setLevel(logging.DEBUG)
31 sdb = SimpleDB(cfg)
add6b7f Michael Ludvig 2008-04-30 Michal Ludvig <michal@logix.cz>
mludvig authored
32
d439efb Michael Ludvig ATTENTION -- Mega WhiteSpace conversion !!!
mludvig authored
33 try:
34 display_response(sdb.ListDomains())
add6b7f Michael Ludvig 2008-04-30 Michal Ludvig <michal@logix.cz>
mludvig authored
35
d439efb Michael Ludvig ATTENTION -- Mega WhiteSpace conversion !!!
mludvig authored
36 display_response(sdb.CreateDomain("logix.cz-test"))
add6b7f Michael Ludvig 2008-04-30 Michal Ludvig <michal@logix.cz>
mludvig authored
37
d439efb Michael Ludvig ATTENTION -- Mega WhiteSpace conversion !!!
mludvig authored
38 display_response(sdb.ListDomains())
add6b7f Michael Ludvig 2008-04-30 Michal Ludvig <michal@logix.cz>
mludvig authored
39
d439efb Michael Ludvig ATTENTION -- Mega WhiteSpace conversion !!!
mludvig authored
40 display_response(sdb.PutAttributes("logix.cz-test", "AbCd", {'First': "One", "Second" : 2, "Third" : u"drei"}))
41 display_response(sdb.PutAttributes("logix.cz-test", "XyZ", {'xyz' : ['x', 'y', 'z'], 'Third' : u'traja'}))
add6b7f Michael Ludvig 2008-04-30 Michal Ludvig <michal@logix.cz>
mludvig authored
42
d439efb Michael Ludvig ATTENTION -- Mega WhiteSpace conversion !!!
mludvig authored
43 display_response(sdb.GetAttributes("logix.cz-test", "AbCd", ['Second', 'Third']))
44 display_response(sdb.GetAttributes("logix.cz-test", "XyZ"))
add6b7f Michael Ludvig 2008-04-30 Michal Ludvig <michal@logix.cz>
mludvig authored
45
d439efb Michael Ludvig ATTENTION -- Mega WhiteSpace conversion !!!
mludvig authored
46 display_response(sdb.Query("logix.cz-test", "['xyz' = 'z']"))
add6b7f Michael Ludvig 2008-04-30 Michal Ludvig <michal@logix.cz>
mludvig authored
47
d439efb Michael Ludvig ATTENTION -- Mega WhiteSpace conversion !!!
mludvig authored
48 display_response(sdb.DeleteDomain("logix.cz-test"))
add6b7f Michael Ludvig 2008-04-30 Michal Ludvig <michal@logix.cz>
mludvig authored
49
d439efb Michael Ludvig ATTENTION -- Mega WhiteSpace conversion !!!
mludvig authored
50 display_response(sdb.ListDomains())
51 except S3Error, e:
52 error(e)
53 error(e.info)
add6b7f Michael Ludvig 2008-04-30 Michal Ludvig <michal@logix.cz>
mludvig authored
54
d439efb Michael Ludvig ATTENTION -- Mega WhiteSpace conversion !!!
mludvig authored
55 # vim:et:ts=4:sts=4:ai
Something went wrong with that request. Please try again.