Esempio n. 1
0
 def re_index(self, request, pk=None):
     """Re-index blob"""
     volume = get_object_for_user_or_404(request.user,
                                         'p2_core.use_volume',
                                         pk=pk)
     signatures = []
     for blob in volume.blob_set.all():
         signatures.append(
             signal_marshall.s('p2.core.signals.BLOB_PAYLOAD_UPDATED',
                               kwargs={
                                   'blob': {
                                       'class':
                                       class_to_path(blob.__class__),
                                       'pk': blob.uuid.hex,
                                   }
                               }))
         signatures.append(
             signal_marshall.s('p2.core.signals.BLOB_POST_SAVE',
                               kwargs={
                                   'blob': {
                                       'class':
                                       class_to_path(blob.__class__),
                                       'pk': blob.uuid.hex,
                                   }
                               }))
     result = group(*signatures)().get()
     # Since each blob needs two calls we return the length divided by two
     return Response(len(result) / 2)
Esempio n. 2
0
File: models.py Progetto: BeryJu/p2
 def save(self, *args, **kwargs):
     """Name file on storage after generated UUID and populate initial attributes"""
     # Save current time as `created` attribute. This can be changed by users,
     # but p2.log creates a log entry for new Blob being created
     if ATTR_BLOB_STAT_CTIME not in self.attributes:
         self.attributes[ATTR_BLOB_STAT_CTIME] = now()
     # Create/update `date_updated` attribute
     self.attributes[ATTR_BLOB_STAT_MTIME] = now()
     # Only save payload if it changed
     if self._writing_handle:
         self._writing_handle.seek(0)
         self.volume.storage.controller.commit(self, self._writing_handle)
     # Check if path exists already
     self.__failsafe_path()
     # Update prefix
     self.__update_prefix()
     self.volume.storage.controller.collect_attributes(self)
     super().save(*args, **kwargs)
     if self._writing_handle:
         signal_marshall.delay('p2.core.signals.BLOB_PAYLOAD_UPDATED',
                               kwargs={
                                   'blob': {
                                       'class':
                                       class_to_path(self.__class__),
                                       'pk': self.uuid.hex,
                                   }
                               })
Esempio n. 3
0
 def setUp(self):
     self.storage = get_test_storage()
     self.volume = Volume.objects.create(name='p2-unittest-public-access',
                                         storage=self.storage)
     self.component = Component.objects.create(
         volume=self.volume,
         controller_path=class_to_path(PublicAccessController))
Esempio n. 4
0
File: models.py Progetto: BeryJu/p2
 def component(self, class_or_path):
     """Get component instance for class or class path.
     Return None if component not confugued."""
     if not isinstance(class_or_path, str):
         class_or_path = class_to_path(class_or_path)
     component = self.component_set.filter(controller_path=class_or_path,
                                           enabled=True)
     if component.exists():
         return component.first()
     return None
Esempio n. 5
0
File: utils.py Progetto: BeryJu/p2
def get_test_storage():
    """Get fully instantiated storage"""
    storage_name = 'p2-unittest'
    storage, _ = Storage.objects.get_or_create(
        name=storage_name,
        controller_path=class_to_path(LocalStorageController),
        defaults={'tags': {
            TAG_ROOT_PATH: mkdtemp()
        }})
    return storage
Esempio n. 6
0
 def setUp(self):
     self.storage_path = './storage/local-unittest/'
     self.storage = Storage.objects.create(
         name='local-storage-1',
         controller_path=class_to_path(LocalStorageController),
         tags={
             TAG_ROOT_PATH: self.storage_path
         })
     self.volume = Volume.objects.create(
         name='local-volume-1',
         storage=self.storage)
Esempio n. 7
0
 def setUp(self):
     self.storage = get_test_storage()
     self.volume = Volume.objects.create(
         name='test-volume',
         storage=self.storage)
     self.image_component = Component.objects.create(
         volume=self.volume,
         controller_path=class_to_path(ImageController),
         tags={
             TAG_IMAGE_EXIF_TAGS: [EXIF_MODEL]
         })
Esempio n. 8
0
def create_default_storage(apps, schema_editor):
    from django.contrib.auth.models import User
    from django.conf import settings
    from p2.lib.reflection import class_to_path
    from p2.storage.local.constants import TAG_ROOT_PATH
    from guardian.conf import settings as guardian_settings
    from p2.storage.local.controller import LocalStorageController
    Storage = apps.get_model('p2_core', 'Storage')
    Volume = apps.get_model('p2_core', 'Volume')
    # Use local storage if we're in debug
    storage_path = '/storage/' if not settings.DEBUG else './storage/'
    # Only apply if no storage exists
    if Storage.objects.all().exists():
        return
    storage = Storage.objects.create(
        name='local-storage',
        controller_path=class_to_path(LocalStorageController),
        tags={
            # /storage/ is always mounted
            TAG_ROOT_PATH: storage_path
        })
    Volume.objects.create(name='default-volume', storage=storage)
Esempio n. 9
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        components = []
        existing_components = get_objects_for_user(self.request.user, 'p2_core.view_component')
        for controller in COMPONENT_MANAGER.list():
            controller_path = class_to_path(controller)
            # Check if component for this volume is configure
            existing_component = existing_components.filter(
                controller_path=controller_path,
                volume=self.object)
            if existing_component.exists():
                components.append(existing_component.first())
            else:
                # Create an in-memory Object with the controller_path assigned
                _component = Component()
                _component.controller_path = controller_path
                _component.volume = self.object
                # Set an extra attribute so the template can reflect it
                _component.configured = False
                _component.enabled = False
                components.append(_component)

        context['components'] = components
        return context
Esempio n. 10
0
 def as_choices(self):
     """Get list of tuples of (path to class, class name)"""
     self.__actual_load()
     for cls in self.__class_list:
         yield (class_to_path(cls), cls.__name__)
Esempio n. 11
0
File: tasks.py Progetto: BeryJu/p2
def run_expire(self):
    """Remove blobs which have expired"""
    LOGGER.debug("Running expiry...")
    for component in Component.objects.filter(
            controller_path=class_to_path(ExpiryController), enabled=True):
        component.controller.expire_volume(component.volume)
Esempio n. 12
0
def component_post_save(sender, instance, **kwargs):
    """Trigger initial sync after we've been saved"""
    if instance.controller_path == class_to_path(ReplicationController):
        initial_full_replication.delay(instance.volume.pk)