Mercurial > repos > shellac > sam_consensus_v3
annotate env/bin/sdbadmin @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
| author | shellac | 
|---|---|
| date | Mon, 22 Mar 2021 18:12:50 +0000 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 
0
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
1 #!/Users/cmdms/OneDrive-UOB/Development/Projects/2021/sam-consensus-v3/env/bin/python3 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
2 # Copyright (c) 2009 Chris Moyer http://kopertop.blogspot.com/ | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
3 # | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
4 # Permission is hereby granted, free of charge, to any person obtaining a | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
5 # copy of this software and associated documentation files (the | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
6 # "Software"), to deal in the Software without restriction, including | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
7 # without limitation the rights to use, copy, modify, merge, publish, dis- | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
8 # tribute, sublicense, and/or sell copies of the Software, and to permit | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
9 # persons to whom the Software is furnished to do so, subject to the fol- | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
10 # lowing conditions: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
11 # | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
12 # The above copyright notice and this permission notice shall be included | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
13 # in all copies or substantial portions of the Software. | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
14 # | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
18 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
21 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
22 # | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
23 # Tools to dump and recover an SDB domain | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
24 # | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
25 VERSION = "%prog version 1.0" | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
26 import boto | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
27 import time | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
28 from boto import sdb | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
29 from boto.compat import json | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
30 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
31 def choice_input(options, default=None, title=None): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
32 """ | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
33 Choice input | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
34 """ | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
35 if title == None: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
36 title = "Please choose" | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
37 print title | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
38 objects = [] | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
39 for n, obj in enumerate(options): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
40 print "%s: %s" % (n, obj) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
41 objects.append(obj) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
42 choice = int(raw_input(">>> ")) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
43 try: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
44 choice = objects[choice] | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
45 except: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
46 choice = default | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
47 return choice | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
48 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
49 def confirm(message="Are you sure?"): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
50 choice = raw_input("%s [yN] " % message) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
51 return choice and len(choice) > 0 and choice[0].lower() == "y" | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
52 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
53 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
54 def dump_db(domain, file_name, use_json=False, sort_attributes=False): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
55 """ | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
56 Dump SDB domain to file | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
57 """ | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
58 f = open(file_name, "w") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
59 if use_json: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
60 for item in domain: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
61 data = {"name": item.name, "attributes": item} | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
62 print >> f, json.dumps(data, sort_keys=sort_attributes) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
63 else: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
64 doc = domain.to_xml(f) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
65 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
66 def empty_db(domain): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
67 """ | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
68 Remove all entries from domain | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
69 """ | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
70 for item in domain: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
71 item.delete() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
72 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
73 def load_db(domain, file, use_json=False): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
74 """ | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
75 Load a domain from a file, this doesn't overwrite any existing | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
76 data in the file so if you want to do a full recovery and restore | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
77 you need to call empty_db before calling this | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
78 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
79 :param domain: The SDB Domain object to load to | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
80 :param file: The File to load the DB from | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
81 """ | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
82 if use_json: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
83 for line in file.readlines(): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
84 if line: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
85 data = json.loads(line) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
86 item = domain.new_item(data['name']) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
87 item.update(data['attributes']) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
88 item.save() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
89 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
90 else: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
91 domain.from_xml(file) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
92 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
93 def check_valid_region(conn, region): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
94 if conn is None: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
95 print 'Invalid region (%s)' % region | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
96 sys.exit(1) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
97 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
98 def create_db(domain_name, region_name): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
99 """Create a new DB | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
100 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
101 :param domain: Name of the domain to create | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
102 :type domain: str | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
103 """ | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
104 sdb = boto.sdb.connect_to_region(region_name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
105 check_valid_region(sdb, region_name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
106 return sdb.create_domain(domain_name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
107 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
108 if __name__ == "__main__": | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
109 from optparse import OptionParser | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
110 parser = OptionParser(version=VERSION, usage="Usage: %prog [--dump|--load|--empty|--list|-l] [options]") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
111 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
112 # Commands | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
113 parser.add_option("--dump", help="Dump domain to file", dest="dump", default=False, action="store_true") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
114 parser.add_option("--load", help="Load domain contents from file", dest="load", default=False, action="store_true") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
115 parser.add_option("--empty", help="Empty all contents of domain", dest="empty", default=False, action="store_true") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
116 parser.add_option("-l", "--list", help="List All domains", dest="list", default=False, action="store_true") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
117 parser.add_option("-c", "--create", help="Create domain", dest="create", default=False, action="store_true") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
118 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
119 parser.add_option("-a", "--all-domains", help="Operate on all domains", action="store_true", default=False, dest="all_domains") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
120 if json: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
121 parser.add_option("-j", "--use-json", help="Load/Store as JSON instead of XML", action="store_true", default=False, dest="json") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
122 parser.add_option("-s", "--sort-attibutes", help="Sort the element attributes", action="store_true", default=False, dest="sort_attributes") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
123 parser.add_option("-d", "--domain", help="Do functions on domain (may be more then one)", action="append", dest="domains") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
124 parser.add_option("-f", "--file", help="Input/Output file we're operating on", dest="file_name") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
125 parser.add_option("-r", "--region", help="Region (e.g. us-east-1[default] or eu-west-1)", default="us-east-1", dest="region_name") | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
126 (options, args) = parser.parse_args() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
127 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
128 if options.create: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
129 for domain_name in options.domains: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
130 create_db(domain_name, options.region_name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
131 exit() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
132 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
133 sdb = boto.sdb.connect_to_region(options.region_name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
134 check_valid_region(sdb, options.region_name) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
135 if options.list: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
136 for db in sdb.get_all_domains(): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
137 print db | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
138 exit() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
139 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
140 if not options.dump and not options.load and not options.empty: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
141 parser.print_help() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
142 exit() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
143 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
144 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
145 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
146 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
147 # | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
148 # Setup | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
149 # | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
150 if options.domains: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
151 domains = [] | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
152 for domain_name in options.domains: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
153 domains.append(sdb.get_domain(domain_name)) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
154 elif options.all_domains: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
155 domains = sdb.get_all_domains() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
156 else: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
157 domains = [choice_input(options=sdb.get_all_domains(), title="No domain specified, please choose one")] | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
158 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
159 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
160 # | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
161 # Execute the commands | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
162 # | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
163 stime = time.time() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
164 if options.empty: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
165 if confirm("WARNING!!! Are you sure you want to empty the following domains?: %s" % domains): | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
166 stime = time.time() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
167 for domain in domains: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
168 print "--------> Emptying %s <--------" % domain.name | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
169 empty_db(domain) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
170 else: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
171 print "Canceling operations" | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
172 exit() | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
173 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
174 if options.dump: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
175 for domain in domains: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
176 print "--------> Dumping %s <---------" % domain.name | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
177 if options.file_name: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
178 file_name = options.file_name | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
179 else: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
180 file_name = "%s.db" % domain.name | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
181 dump_db(domain, file_name, options.json, options.sort_attributes) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
182 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
183 if options.load: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
184 for domain in domains: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
185 print "---------> Loading %s <----------" % domain.name | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
186 if options.file_name: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
187 file_name = options.file_name | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
188 else: | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
189 file_name = "%s.db" % domain.name | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
190 load_db(domain, open(file_name, "rb"), options.json) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
191 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
192 | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
193 total_time = round(time.time() - stime, 2) | 
| 
 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 
shellac 
parents:  
diff
changeset
 | 
194 print "--------> Finished in %s <--------" % total_time | 
