Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: third_party/gsutil/boto/sdb/db/manager/__init__.py

Issue 12042069: Scripts to download files from google storage based on sha1 sums (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Removed gsutil/tests and gsutil/docs Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright (c) 2006,2007,2008 Mitch Garnaat http://garnaat.org/
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish, dis-
7 # tribute, sublicense, and/or sell copies of the Software, and to permit
8 # persons to whom the Software is furnished to do so, subject to the fol-
9 # lowing conditions:
10 #
11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE.
21 import boto
22
23
24 def get_manager(cls):
25 """
26 Returns the appropriate Manager class for a given Model class. It
27 does this by looking in the boto config for a section like this::
28
29 [DB]
30 db_type = SimpleDB
31 db_user = <aws access key id>
32 db_passwd = <aws secret access key>
33 db_name = my_domain
34 [DB_TestBasic]
35 db_type = SimpleDB
36 db_user = <another aws access key id>
37 db_passwd = <another aws secret access key>
38 db_name = basic_domain
39 db_port = 1111
40
41 The values in the DB section are "generic values" that will be used
42 if nothing more specific is found. You can also create a section for
43 a specific Model class that gives the db info for that class.
44 In the example above, TestBasic is a Model subclass.
45 """
46 db_user = boto.config.get('DB', 'db_user', None)
47 db_passwd = boto.config.get('DB', 'db_passwd', None)
48 db_type = boto.config.get('DB', 'db_type', 'SimpleDB')
49 db_name = boto.config.get('DB', 'db_name', None)
50 db_table = boto.config.get('DB', 'db_table', None)
51 db_host = boto.config.get('DB', 'db_host', "sdb.amazonaws.com")
52 db_port = boto.config.getint('DB', 'db_port', 443)
53 enable_ssl = boto.config.getbool('DB', 'enable_ssl', True)
54 sql_dir = boto.config.get('DB', 'sql_dir', None)
55 debug = boto.config.getint('DB', 'debug', 0)
56 # first see if there is a fully qualified section name in the Boto config
57 module_name = cls.__module__.replace('.', '_')
58 db_section = 'DB_' + module_name + '_' + cls.__name__
59 if not boto.config.has_section(db_section):
60 db_section = 'DB_' + cls.__name__
61 if boto.config.has_section(db_section):
62 db_user = boto.config.get(db_section, 'db_user', db_user)
63 db_passwd = boto.config.get(db_section, 'db_passwd', db_passwd)
64 db_type = boto.config.get(db_section, 'db_type', db_type)
65 db_name = boto.config.get(db_section, 'db_name', db_name)
66 db_table = boto.config.get(db_section, 'db_table', db_table)
67 db_host = boto.config.get(db_section, 'db_host', db_host)
68 db_port = boto.config.getint(db_section, 'db_port', db_port)
69 enable_ssl = boto.config.getint(db_section, 'enable_ssl', enable_ssl)
70 debug = boto.config.getint(db_section, 'debug', debug)
71 elif hasattr(cls, "_db_name") and cls._db_name is not None:
72 # More specific then the generic DB config is any _db_name class propert y
73 db_name = cls._db_name
74 elif hasattr(cls.__bases__[0], "_manager"):
75 return cls.__bases__[0]._manager
76 if db_type == 'SimpleDB':
77 from sdbmanager import SDBManager
78 return SDBManager(cls, db_name, db_user, db_passwd,
79 db_host, db_port, db_table, sql_dir, enable_ssl)
80 elif db_type == 'XML':
81 from xmlmanager import XMLManager
82 return XMLManager(cls, db_name, db_user, db_passwd,
83 db_host, db_port, db_table, sql_dir, enable_ssl)
84 else:
85 raise ValueError('Unknown db_type: %s' % db_type)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698