Skip to content

Commit

Permalink
Rebased from master
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuluPro committed Jul 28, 2016
1 parent 2dd85f2 commit 0b7f4a7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
16 changes: 7 additions & 9 deletions dbbackup/management/commands/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.core.management.base import BaseCommand, LabelCommand, CommandError
from django.utils import six

from ...storage.base import StorageError
from ...storage import StorageError

input = raw_input if six.PY2 else input # @ReservedAssignment

Expand Down Expand Up @@ -43,9 +43,7 @@ def read_from_storage(self, path):
return self.storage.read_file(path)

def write_to_storage(self, file, path):
self.logger.info("Writing file to %s: %s, filename: %s",
self.storage.name, self.storage.backup_dir,
path)
self.logger.info("Writing file to %s", path)
self.storage.write_file(file, path)

def read_local_file(self, path):
Expand Down Expand Up @@ -88,8 +86,8 @@ def _cleanup_old_backups(self):
DBBACKUP_CLEANUP_KEEP and any backups that occur on first of the month.
"""
# database = self.database if self.content_type == 'db' else None
file_list = self.storage.clean_old_backups(encrypted=self.encrypt,
compressed=self.compress,
content_type=self.content_type)
# TODO: Make better filter
# database=database)
self.storage.clean_old_backups(encrypted=self.encrypt,
compressed=self.compress,
content_type=self.content_type)
# TODO: Make better filter
# database=database)
4 changes: 2 additions & 2 deletions dbbackup/management/commands/mediarestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.core.files.storage import get_storage_class

from ._base import BaseDbBackupCommand
from ...storage.base import BaseStorage, StorageError
from ...storage import get_storage, StorageError
from ... import utils


Expand Down Expand Up @@ -39,7 +39,7 @@ def handle(self, *args, **options):
self.replace = options.get('replace')
self.passphrase = options.get('passphrase')
self.interactive = options.get('interactive')
self.storage = BaseStorage.storage_factory()
self.storage = get_storage()
self.media_storage = get_storage_class()()
self._restore_backup()

Expand Down
5 changes: 4 additions & 1 deletion dbbackup/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ def write_file(self, filehandle, filename):

def read_file(self, filepath):
self.logger.debug('Reading file %s', filepath)
return self.storage.open(name=filepath, mode='rb')
file_ = self.storage.open(name=filepath, mode='rb')
if file_.name is None:
file_.name = filepath
return file_

def list_backups(self, encrypted=None, compressed=None, content_type=None,
database=None):
Expand Down
12 changes: 7 additions & 5 deletions dbbackup/tests/commands/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from mock import patch
from django.test import TestCase
from django.utils import six
from django.core.files import File
from dbbackup.management.commands._base import BaseDbBackupCommand
from dbbackup.tests.utils import (FakeStorage, DEV_NULL, HANDLED_FILES)
from dbbackup.storage import get_storage
from dbbackup.tests.utils import DEV_NULL, HANDLED_FILES


class BaseDbBackupCommandSetLoggerLevelTest(TestCase):
Expand All @@ -33,10 +35,10 @@ class BaseDbBackupCommandMethodsTest(TestCase):
def setUp(self):
HANDLED_FILES.clean()
self.command = BaseDbBackupCommand()
self.command.storage = FakeStorage()
self.command.storage = get_storage()

def test_read_from_storage(self):
HANDLED_FILES['written_files'].append(['foo', six.BytesIO(b'bar')])
HANDLED_FILES['written_files'].append(['foo', File(six.BytesIO(b'bar'))])
file_ = self.command.read_from_storage('foo')
self.assertEqual(file_.read(), b'bar')

Expand All @@ -54,7 +56,7 @@ def test_read_local_file(self):
os.remove(self.command.path)

def test_write_local_file(self):
fd, path = six.BytesIO(b"foo"), '/tmp/foo.bak'
fd, path = File(six.BytesIO(b"foo")), '/tmp/foo.bak'
self.command.write_local_file(fd, path)
self.assertTrue(os.path.exists(path))
# tearDown
Expand Down Expand Up @@ -90,7 +92,7 @@ def setUp(self):
self.command.encrypt = False
self.command.compress = False
self.command.servername = 'foo-server'
self.command.storage = FakeStorage()
self.command.storage = get_storage()
HANDLED_FILES['written_files'] = [(f, None) for f in [
'2015-02-06-042810.tar',
'2015-02-07-042810.tar',
Expand Down
6 changes: 3 additions & 3 deletions dbbackup/tests/commands/test_mediabackup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
from django.test import TestCase
from django.core.files.storage import get_storage_class
from dbbackup.management.commands.mediabackup import Command as DbbackupCommand
from dbbackup.tests.utils import (FakeStorage, DEV_NULL, HANDLED_FILES,
add_public_gpg)
from dbbackup.storage import get_storage
from dbbackup.tests.utils import DEV_NULL, HANDLED_FILES, add_public_gpg


class MediabackupBackupMediafilesTest(TestCase):
def setUp(self):
HANDLED_FILES.clean()
self.command = DbbackupCommand()
self.command.servername = 'foo-server'
self.command.storage = FakeStorage()
self.command.storage = get_storage()
self.command.stdout = DEV_NULL
self.command.compress = False
self.command.encrypt = False
Expand Down

0 comments on commit 0b7f4a7

Please # to comment.