Permalink
Browse files

Move logging code and imports and standardize indent levels.

  • Loading branch information...
robhudson committed Apr 9, 2009
1 parent 710981b commit d490a783402dc4d6eb82507433ab98ec8bc3f915
Showing with 29 additions and 27 deletions.
  1. +29 −27 dumpy/dumper.py
View
@@ -4,8 +4,6 @@
import datetime
import shutil
import tempfile
-from optparse import OptionParser
-import logging
try:
import boto
@@ -15,14 +13,6 @@
from boto.s3.key import Key
from boto.s3.connection import S3Connection
-logger = logging.getLogger("dumper")
-logger.setLevel(logging.ERROR)
-ch = logging.StreamHandler()
-ch.setLevel(logging.DEBUG)
-formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
-ch.setFormatter(formatter)
-logger.addHandler(ch)
-
class MySQLDumpError(Exception):
pass
@@ -341,7 +331,7 @@ def parse_config(self):
def process(self, file):
if boto is None:
raise Exception("You must have boto installed before using S3 support.")
-
+
self.parse_config()
conn = S3Connection(self.access_key, self.secret_key)
@@ -353,7 +343,11 @@ def process(self, file):
return file
if __name__ == '__main__':
- parser = OptionParser()
+
+ import logging
+ import optparse
+
+ parser = optparse.OptionParser()
parser.add_option("-D", "--database", dest="database",
help="Which database would you like to dump?", default='db1')
parser.add_option("-v", "--verbose",
@@ -362,26 +356,34 @@ def process(self, file):
parser.add_option("-a", "--all-databases",
action="store_true", dest="all", default=False,
help="Dump all databases")
-
+
(options, args) = parser.parse_args()
-
+
+ logger = logging.getLogger("dumper")
+ logger.setLevel(logging.ERROR)
+ ch = logging.StreamHandler()
+ ch.setLevel(logging.DEBUG)
+ formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
+ ch.setFormatter(formatter)
+ logger.addHandler(ch)
+
if options.verbose:
logger.setLevel(logging.DEBUG)
dbs_to_dump = []
-
+
if options.all:
- config = ConfigParser.SafeConfigParser()
- config.read(os.path.expanduser('~/.dumpy.cfg'))
- sections = config.sections()
- for db in sections:
- if db.startswith('database '):
- dbname = db.replace('database ', '')
- dbs_to_dump.append(dbname)
+ config = ConfigParser.SafeConfigParser()
+ config.read(os.path.expanduser('~/.dumpy.cfg'))
+ sections = config.sections()
+ for db in sections:
+ if db.startswith('database '):
+ dbname = db.replace('database ', '')
+ dbs_to_dump.append(dbname)
else:
- dbs_to_dump.append(options.database)
-
+ dbs_to_dump.append(options.database)
+
for db in dbs_to_dump:
- file = DatabaseBackup(db).backup()
- # Then call post processors, in the given order
- PostProcess(db).process(file)
+ file = DatabaseBackup(db).backup()
+ # Then call post processors, in the given order
+ file = PostProcess(db).process(file)

0 comments on commit d490a78

Please sign in to comment.