Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moving the database name out of the TimestampRename processor and int…

…o its own processor called PrependDatabaseName.
  • Loading branch information...
commit 620aa1d92296cdee139016872d0a0c4dded01583 1 parent 3548aeb
@robhudson authored
View
2  README.rst
@@ -28,7 +28,7 @@ The following is an idea of what the configuration file, located at
name = dbname1
user = db1
password = db1
- postprocessing = TimestampRename, Bzip, SystemFileCopy, S3Copy
+ postprocessing = TimestampRename, PrependDatabaseName, Bzip, SystemFileCopy, S3Copy
[database db2]
type = postgresql
View
3  dumpy/base.py
@@ -126,9 +126,10 @@ def __init__(self, db):
self.db = db
self.builtin_processors = {
'Bzip': 'dumpy.postprocessor.bzip.Bzip',
- 'TimestampRename': 'dumpy.postprocessor.timestamp.TimestampRename',
'FileSystemCopy': 'dumpy.postprocessor.fscopy.FileSystemCopy',
+ 'PrependDatabaseName': 'dumpy.postprocessor.dbname.PrependDatabaseName',
'S3Copy': 'dumpy.postprocessor.s3copy.S3Copy',
+ 'TimestampRename': 'dumpy.postprocessor.timestamp.TimestampRename',
}
def parse_config(self):
View
36 dumpy/postprocessor/dbname.py
@@ -0,0 +1,36 @@
+import datetime
+import logging
+import os
+import shutil
+
+import dumpy
+
+logger = logging.getLogger("dumper")
+
+class PrependDatabaseName(dumpy.base.PostProcessBase):
+ """
+ A post procesor that renames the file by prepending the database name to
+ the existing file name.
+ """
+ def __init__(self, db):
+ self.db = db
+
+ def parse_config(self):
+ super(PrependDatabaseName, self).parse_config()
+
+ def process(self, file):
+
+ self.parse_config()
+
+ dir = os.path.dirname(file.name)
+ base, ext = os.path.splitext(os.path.basename(file.name))
+
+ new_file_name = '%s/%s-%s%s' % (dir, self.db, base, ext)
+
+ shutil.copy(file.name, new_file_name)
+ logger.info('%s - %s - Copying %s to %s' % (self.db, self.__class__.__name__, file.name, new_file_name))
+ new_file = open(new_file_name)
+ file.close()
+
+ return new_file
+
View
7 dumpy/postprocessor/timestamp.py
@@ -25,11 +25,8 @@ def process(self, file):
dir = os.path.dirname(file.name)
base, ext = os.path.splitext(os.path.basename(file.name))
- # @@@ Clint: Put DB name into renamed name, I dunno how i like this in here
- file_name_format = '%s/%s%s'
- if self.insert_db_name:
- file_name_format = '%s/'+self.db+'-%s%s'
- new_file_name = file_name_format % (dir, datetime.datetime.now().strftime(self.format), ext)
+
+ new_file_name = '%s/%s%s' % (dir, datetime.datetime.now().strftime(self.format), ext)
shutil.copy(file.name, new_file_name)
logger.info('%s - %s - Copying %s to %s' % (self.db, self.__class__.__name__, file.name, new_file_name))
Please sign in to comment.
Something went wrong with that request. Please try again.