2
# Copyright (c) 2006-2008 Mitch Garnaat http://garnaat.org/
4
# Permission is hereby granted, free of charge, to any person obtaining a
5
# copy of this software and associated documentation files (the
6
# "Software"), to deal in the Software without restriction, including
7
# without limitation the rights to use, copy, modify, merge, publish, dis-
8
# tribute, sublicense, and/or sell copies of the Software, and to permit
9
# persons to whom the Software is furnished to do so, subject to the fol-
12
# The above copyright notice and this permission notice shall be included
13
# in all copies or substantial portions of the Software.
15
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
17
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
18
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23
from optparse import OptionParser
24
from boto.mapreduce.partitiondb import PartitionDB, Partition, Version
25
from boto.exception import SDBPersistenceError
26
from boto.sdb.persist import get_manager, get_domain
32
List and describe your PartitionDBs.
33
Called with no options, all PartitionDB objects defined in your default
34
domain (as specified in the "default_domain" option in the "[Persist]"
35
section of your boto config file) will be listed.
36
When called with a particular PartitionDB name (using -p option) all
37
Version objects of that PartitionDB object will be listed.
38
When called with the -p option and a particular Version name specified
39
(using the -v option) all Partitions in that Version object will be listed.
44
self.parser = OptionParser(usage=USAGE)
45
self.parser.add_option('-d', '--domain-name', action='store', type='string',
46
help='name of the SimpleDB domain where PDB objects are stored')
47
self.parser.add_option('-n', '--num-entries', action='store', type='int',
48
help='maximum number of entries to print (default 100)')
49
self.parser.set_defaults(num_entries=100)
50
self.parser.add_option('-p', '--pdb-name', action='store', type='string',
51
help='name of the PDB to describe')
52
self.parser.add_option('-v', '--version-name', action='store', type='string',
53
help='name of the PDB Version to describe')
54
self.options, self.args = self.parser.parse_args()
55
self.prog_name = sys.argv[0]
57
def describe_all(self):
58
print 'Using SimpleDB Domain: %s' % get_domain()
60
rs = PartitionDB.list()
63
print '%s\t%s\t%s' % (pdb.id, pdb.name, pdb.bucket_name)
65
if i == self.options.num_entries:
68
def describe_pdb(self, pdb_name):
69
print 'Using SimpleDB Domain: %s' % get_domain()
70
print 'PDB: %s' % pdb_name
73
pdb = PartitionDB.get(name=pdb_name)
75
for v in pdb.versions:
77
ds = v.date.isoformat()
80
print '%s\t%s\t%s' % (v.id, v.name, ds)
82
if i == self.options.num_entries:
84
cv = pdb.current_version()
86
print 'Current Version: %s' % cv.name
88
print 'Current Version: None'
89
except SDBPersistenceError:
90
self.parser.error('pdb_name (%s) unknown' % pdb_name)
92
def describe_version(self, pdb_name, version_name):
93
print 'Using SimpleDB Domain: %s' % get_domain()
94
print 'PDB: %s' % pdb_name
95
print 'Version: %s' % version_name
98
pdb = PartitionDB.get(name=pdb_name)
99
for v in pdb.versions:
100
if v.name == version_name:
102
for p in v.partitions():
103
print '%s\t%s' % (p.id, p.name)
105
if i == self.options.num_entries:
107
except SDBPersistenceError:
108
self.parser.error('pdb_name (%s) unknown' % pdb_name)
111
self.options, self.args = self.parser.parse_args()
112
self.manager = get_manager(self.options.domain_name)
114
if self.options.pdb_name:
115
if self.options.version_name:
116
self.describe_version(self.options.pdb_name, self.options.version_name)
118
self.describe_pdb(self.options.pdb_name)
122
if __name__ == "__main__":
123
describe = Describe()