summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-ximdb-ratings.py79
-rw-r--r--videodbpyrc23
2 files changed, 56 insertions, 46 deletions
diff --git a/imdb-ratings.py b/imdb-ratings.py
index 80df32f..0f9173a 100755
--- a/imdb-ratings.py
+++ b/imdb-ratings.py
@@ -23,13 +23,15 @@ MINRANK = 8
MINVOTES = 1000
# VideoDB database parameters
-confset = { # Parameters to connect to the database.
- 'db_server': '',
- 'db_password': '',
- 'db_database': '',
- 'db_user': '',
- 'db_charset': 'utf8',
- 'db_ssl': {},
+confset_db = { # Parameters to connect to the database.
+ 'server': '',
+ 'password': '',
+ 'database': '',
+ 'user': '',
+ 'charset': 'utf8',
+ }
+
+confset_ssl = { # Parameters to connect to the ssl database.
}
#################################################################
@@ -103,15 +105,15 @@ if RANK:
conffile = ConfigParser.ConfigParser()
if not CONF_FILE:
- # ./vdbpyrc
- CONF_FILE = ['vdbpyrc']
- # /etc/vdbpyrc
- CONF_FILE.append(os.path.join(os.sep, 'etc', 'vdbpyrc'))
+ # ./videodbpyrc
+ CONF_FILE = ['videodbpyrc']
+ # /etc/videodbpyrc
+ CONF_FILE.append(os.path.join(os.sep, 'etc', 'videodbpyrc'))
if os.name != 'posix':
# C:\\Python24\etc\imdbpyweb.conf
- CONF_FILE.append(os.path.join(sys.prefix, 'etc', 'vdbpyrc'))
- # ~/.vdbpyrc
- CONF_FILE.append(os.path.join(os.path.expanduser('~'), '.vdbpyrc'))
+ CONF_FILE.append(os.path.join(sys.prefix, 'etc', 'videodbpyrc'))
+ # ~/.videodbpyrc
+ CONF_FILE.append(os.path.join(os.path.expanduser('~'), '.videodbpyrc'))
try: conffile.read(CONF_FILE)
except ConfigParser.Error, e:
@@ -119,24 +121,30 @@ except ConfigParser.Error, e:
print str(e)
sys.exit(3)
-if not conffile.has_section('config'):
- print 'Section [config] not present in the configuration file.'
+if not conffile.has_section('db'):
+ print 'Section [db] not present in the configuration file.'
sys.exit(3)
-for key in ('db_server', 'db_user', 'db_password', 'db_database'):
- if not conffile.has_option('config', key):
- print 'Required option "%s" not present in the [config] section.'
+for key in ('server', 'user', 'password', 'database'):
+ if not conffile.has_option('db', key):
+ print 'Required option "%s" not present in the [db] section.'
sys.exit(3)
- confset[key] = conffile.get('config', key)
-
-if conffile.has_option('config', 'vdb_user'):
- VDB_USER = conffile.get('config', 'vdb_user') or None
-
-if conffile.has_option('config', 'db_prefix'):
- VDB_PREFIX = conffile.get('config', 'db_prefix') or None
-
-if conffile.has_option('config', 'db_ssl'):
- confset['db_ssl'] = conffile.get('config', 'db_ssl')
+ confset_db[key] = conffile.get('db', key)
+
+if conffile.has_option('db', 'prefix'):
+ VDB_PREFIX = conffile.get('db', 'prefix') or None
+
+if conffile.has_section('db_ssl'):
+ if conffile.has_option('db_ssl', 'key'):
+ confset_ssl['key'] = conffile.get('db_ssl', 'key')
+ if conffile.has_option('db_ssl', 'cert'):
+ confset_ssl['cert'] = conffile.get('db_ssl', 'cert')
+ if conffile.has_option('db_ssl', 'ca'):
+ confset_ssl['ca'] = conffile.get('db_ssl', 'ca')
+ if conffile.has_option('db_ssl', 'capath'):
+ confset_ssl['capath'] = conffile.get('db_ssl', 'capath')
+ if conffile.has_option('db_ssl', 'cipher'):
+ confset_ssl['cipher'] = conffile.get('db_ssl', 'cipher')
# ------- CONNECT TO THE DATABASE.
@@ -149,15 +157,10 @@ if VERBOSE:
print 'Connecting to the VideoDB database... ',
sys.stdout.flush()
try:
- db_ssl = confset['db_ssl'];
- if db_ssl: db_ssl = eval (db_ssl)
- db = MySQLdb.connect( db = confset['db_database'],
- host = confset['db_server'],
- user = confset['db_user'],
- passwd = confset['db_password'],
- charset = confset['db_charset'],
- ssl = db_ssl
- )
+ db = MySQLdb.connect(db=confset_db['database'], host=confset_db['server'],
+ user=confset_db['user'], passwd=confset_db['password'],
+ charset=confset_db['charset'],
+ ssl=confset_ssl)
curs = db.cursor()
except MySQLdb.Error, e:
print '\nUnable to connect to the database.'
diff --git a/videodbpyrc b/videodbpyrc
index a4ae1bf..98a966c 100644
--- a/videodbpyrc
+++ b/videodbpyrc
@@ -1,9 +1,16 @@
-[config]
+[db]
; Information to connect to the VideoDB database.
-db_server = localhost
-db_user = videodb
-db_password = videodb
-db_database = videodb
-;db_charset = utf8
-db_prefix = videodb_
-;db_ssl = {'ca':'/path/to/cert.pem',}
+server = localhost
+user = videodb
+password = videodb
+database = videodb
+;charset = utf8
+prefix = videodb_
+
+[db_ssl]
+;key = '' ; key is the path name to the key file.
+;cert = '' ; cert is the path name to the certificate file.
+;ca = '' ; ca is the path name to the certificate authority file.
+;capath = '' ; capath is the path name to a directory that contains trusted SSL CA certificates in pem format.
+;cipher = '' ; cipher is a list of permissible ciphers to use for SSL encryption.
+