Start of working BackupManager class
This commit is contained in:
+59
-2
@@ -1,7 +1,41 @@
|
|||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
from django.utils.translation import ugettext
|
||||||
|
|
||||||
|
|
||||||
class ModuleBackup(object):
|
class BackupManagerBase(object):
|
||||||
|
label = _(u'Base backup manager')
|
||||||
|
#def __init__(self, name, label):
|
||||||
|
# self.label = label
|
||||||
|
# self.name = name
|
||||||
|
|
||||||
|
def info(self):
|
||||||
|
return None
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return unicode(self.__class__.label)
|
||||||
|
|
||||||
|
|
||||||
|
class ModelFixtures(BackupManagerBase):
|
||||||
|
label = _(u'Model fixtures')
|
||||||
|
|
||||||
|
def __init__(self, models=None):
|
||||||
|
self.model_list = models or []
|
||||||
|
|
||||||
|
def info(self):
|
||||||
|
return u', '.join(self.model_list) or _(u'All')
|
||||||
|
|
||||||
|
|
||||||
|
class DirectoryCopy(BackupManagerBase):
|
||||||
|
label = _(u'Directory copy')
|
||||||
|
|
||||||
|
def __init__(self, path):
|
||||||
|
self.path = path
|
||||||
|
|
||||||
|
def info(self):
|
||||||
|
return self.path
|
||||||
|
|
||||||
|
|
||||||
|
class AppBackup(object):
|
||||||
_registry = {}
|
_registry = {}
|
||||||
|
|
||||||
STATE_BACKING_UP = 'backing_up'
|
STATE_BACKING_UP = 'backing_up'
|
||||||
@@ -22,12 +56,20 @@ class ModuleBackup(object):
|
|||||||
def get_all(cls):
|
def get_all(cls):
|
||||||
return cls._registry.values()
|
return cls._registry.values()
|
||||||
|
|
||||||
def __init__(self, name, label):
|
def __init__(self, name, label, backup_managers):
|
||||||
self.label = label
|
self.label = label
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.backup_managers = backup_managers
|
||||||
self.state = self.__class__.STATE_IDLE
|
self.state = self.__class__.STATE_IDLE
|
||||||
self.__class__._registry[name] = self
|
self.__class__._registry[name] = self
|
||||||
|
|
||||||
|
@property
|
||||||
|
def info(self):
|
||||||
|
results = []
|
||||||
|
for manager in self.backup_managers:
|
||||||
|
results.append(u'%s - %s' % (manager, manager.info() or _(u'Nothing')))
|
||||||
|
return u', '.join(results)
|
||||||
|
|
||||||
def backup(self, storage_module=None):
|
def backup(self, storage_module=None):
|
||||||
self.state = self.__class__.STATE_BACKING_UP
|
self.state = self.__class__.STATE_BACKING_UP
|
||||||
# call storage_module
|
# call storage_module
|
||||||
@@ -40,3 +82,18 @@ class ModuleBackup(object):
|
|||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return unicode(self.label)
|
return unicode(self.label)
|
||||||
|
|
||||||
|
|
||||||
|
class StorageModuleBase(object):
|
||||||
|
_registry = {}
|
||||||
|
|
||||||
|
def __init__(self, name, label):
|
||||||
|
self.label = label
|
||||||
|
self.name = name
|
||||||
|
self.__class__._registry[name] = self
|
||||||
|
|
||||||
|
def backup(self, *args, **kwargs):
|
||||||
|
raise NotImplemented
|
||||||
|
|
||||||
|
def restore(self, *args, **kwargs):
|
||||||
|
raise NotImplemented
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from django.core.urlresolvers import reverse
|
|||||||
|
|
||||||
from permissions.models import Permission
|
from permissions.models import Permission
|
||||||
|
|
||||||
from .api import ModuleBackup
|
from .api import AppBackup
|
||||||
#from .permissions import
|
#from .permissions import
|
||||||
|
|
||||||
|
|
||||||
@@ -17,12 +17,12 @@ def backup_view(request):
|
|||||||
#Permission.objects.check_permissions(request.user, [])
|
#Permission.objects.check_permissions(request.user, [])
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'object_list': ModuleBackup.get_all(),
|
'object_list': AppBackup.get_all(),
|
||||||
'title': _(u'apps registered for backup'),
|
'title': _(u'registered apps for backup'),
|
||||||
'hide_link': True,
|
'hide_link': True,
|
||||||
#'extra_columns': [
|
'extra_columns': [
|
||||||
# {'name': _(u'description'), 'attribute': 'description'},
|
{'name': _(u'info'), 'attribute': 'info'},
|
||||||
#],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
return render_to_response('generic_list.html', context,
|
return render_to_response('generic_list.html', context,
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from history.permissions import PERMISSION_HISTORY_VIEW
|
|||||||
from project_setup.api import register_setup
|
from project_setup.api import register_setup
|
||||||
from acls.api import class_permissions
|
from acls.api import class_permissions
|
||||||
from statistics.api import register_statistics
|
from statistics.api import register_statistics
|
||||||
|
from backups.api import AppBackup, ModelFixtures, DirectoryCopy
|
||||||
|
|
||||||
from .models import (Document, DocumentPage,
|
from .models import (Document, DocumentPage,
|
||||||
DocumentPageTransformation, DocumentType, DocumentTypeFilename,
|
DocumentPageTransformation, DocumentType, DocumentTypeFilename,
|
||||||
@@ -136,3 +137,4 @@ class_permissions(Document, [
|
|||||||
])
|
])
|
||||||
|
|
||||||
register_statistics(get_statistics)
|
register_statistics(get_statistics)
|
||||||
|
AppBackup('documents', _(u'Documents'), [ModelFixtures(), DirectoryCopy(document_settings.STORAGE_BACKEND)])
|
||||||
|
|||||||
Reference in New Issue
Block a user