Exemple #1
0
    def setUp(self):
        # create DeviceOwner to pass the setup_wizard middleware check
        DeviceOwner.objects.create(username='******', password=123)

        self.client = Client()
        self.hash = hashlib.md5("DUMMYDATA".encode()).hexdigest()
        self.extension = dict(file_formats.choices).get("pdf")
        self.filename = "{}.{}".format(self.hash, self.extension)
        self.title = "abc123!@#$%^&*();'[],./?><"
        self.contentnode = ContentNode(title=self.title)
        self.available = True
        self.preset = format_presets.DOCUMENT
        self.file = File(checksum=self.hash,
                         extension=self.extension,
                         available=self.available,
                         contentnode=self.contentnode,
                         preset=self.preset)

        self.path = get_content_storage_file_path(self.filename)
        path_dir = os.path.dirname(self.path)
        if not os.path.exists(path_dir):
            os.makedirs(path_dir)
        tempfile = open(self.path, "w")
        tempfile.write("test")
        tempfile.close()
Exemple #2
0
    def get_importable(self, obj):
        if 'request' not in self.context or not self.context['request'].query_params.get('importing_from_drive_id', None) or obj.kind == content_kinds.TOPIC:
            return True
        else:
            drive_id = self.context['request'].query_params.get('importing_from_drive_id', None)
            datafolder = cache.get(drive_id, None)

            if datafolder is None:
                drives = get_mounted_drives_with_channel_info()
                if drive_id in drives:
                    datafolder = drives[drive_id].datafolder
                    cache.set(drive_id, datafolder, 60)  # cache the datafolder for 1 minute
                else:
                    raise serializers.ValidationError(
                        'The external drive with given drive id does not exist.')

            files = obj.files.all()
            if not files.exists():
                return False

            importable = True
            for f in files:
                # If one of the files under the node is unavailable on the external drive, mark the node as unimportable
                file_path = get_content_storage_file_path(f.local_file.get_filename(), datafolder)
                importable = importable and os.path.exists(file_path)
            return importable
Exemple #3
0
    def setUp(self):
        provision_device()

        self.client = Client()
        self.hash = hashlib.md5("DUMMYDATA".encode()).hexdigest()
        self.extension = file_formats.PDF
        self.filename = "{}.{}".format(self.hash, self.extension)
        self.title = "abc123!@#$%^&*();'[],./?><"
        self.contentnode = ContentNode(title=self.title)
        self.available = True
        self.preset = format_presets.DOCUMENT
        self.local_file = LocalFile(id=self.hash,
                                    extension=self.extension,
                                    available=self.available)
        self.file = File(local_file=self.local_file,
                         available=self.available,
                         contentnode=self.contentnode,
                         preset=self.preset)

        self.path = get_content_storage_file_path(self.filename)
        path_dir = os.path.dirname(self.path)
        if not os.path.exists(path_dir):
            os.makedirs(path_dir)
        tempfile = open(self.path, "w")
        tempfile.write("test")
        tempfile.close()
Exemple #4
0
    def get_importable(self, instance):
        drive_id = self.context['request'].query_params.get('importing_from_drive_id', None)

        # If node is from a remote source, assume it is importable.
        # Topics are annotated as importable by default, but client may disable importing
        # of the topic if it determines that the entire topic sub-tree is already on the device.
        if drive_id is None or instance.kind == content_kinds.TOPIC:
            return True

        # If non-topic ContentNode has no files, then it is not importable.
        content_files = instance.files.all()
        if not content_files.exists():
            return False

        # Inspecting the external drive's files
        datafolder = cache.get(drive_id, None)

        if datafolder is None:
            drive_ids = get_mounted_drives_with_channel_info()
            if drive_id in drive_ids:
                datafolder = drive_ids[drive_id].datafolder
                cache.set(drive_id, datafolder, 60)  # cache the datafolder for 1 minute
            else:
                raise serializers.ValidationError('The external drive with given drive id {} does not exist.'.format(drive_id))

        importable = True
        for f in content_files:
            # Node is importable only if all of its Files are on the external drive
            file_path = get_content_storage_file_path(f.local_file.get_filename(), datafolder)
            importable = importable and os.path.exists(file_path)
            if not importable:
                break
        return importable
Exemple #5
0
    def get_importable(self, obj):
        if 'request' not in self.context or not self.context['request'].query_params.get('importing_from_drive_id', None) or obj.kind == content_kinds.TOPIC:
            return True
        else:
            drive_id = self.context['request'].query_params.get('importing_from_drive_id', None)
            datafolder = cache.get(drive_id, None)

            if datafolder is None:
                drives = get_mounted_drives_with_channel_info()
                if drive_id in drives:
                    datafolder = drives[drive_id].datafolder
                    cache.set(drive_id, datafolder, 60)  # cache the datafolder for 1 minute
                else:
                    raise serializers.ValidationError(
                        'The external drive with given drive id does not exist.')

            files = obj.files.all()
            if not files.exists():
                return False

            importable = True
            for f in files:
                # If one of the files under the node is unavailable on the external drive, mark the node as unimportable
                file_path = get_content_storage_file_path(f.local_file.get_filename(), datafolder)
                importable = importable and os.path.exists(file_path)
            return importable
    def setUp(self):
        # create DeviceOwner to pass the setup_wizard middleware check
        DeviceOwner.objects.create(username='******', password=123)

        self.client = Client()
        self.hash = hashlib.md5("DUMMYDATA".encode()).hexdigest()
        self.extension = file_formats.PDF
        self.filename = "{}.{}".format(self.hash, self.extension)
        self.title = "abc123!@#$%^&*();'[],./?><"
        self.contentnode = ContentNode(title=self.title)
        self.available = True
        self.preset = format_presets.DOCUMENT
        self.file = File(checksum=self.hash, extension=self.extension, available=self.available,
                         contentnode=self.contentnode, preset=self.preset)

        self.path = get_content_storage_file_path(self.filename)
        path_dir = os.path.dirname(self.path)
        if not os.path.exists(path_dir):
            os.makedirs(path_dir)
        tempfile = open(self.path, "w")
        tempfile.write("test")
        tempfile.close()
    def setUp(self):
        provision_device()

        self.client = Client()
        self.hash = hashlib.md5("DUMMYDATA".encode()).hexdigest()
        self.extension = file_formats.PDF
        self.filename = "{}.{}".format(self.hash, self.extension)
        self.title = "abc123!@#$%^&*();'[],./?><"
        self.contentnode = ContentNode(title=self.title)
        self.available = True
        self.preset = format_presets.DOCUMENT
        self.local_file = LocalFile(id=self.hash, extension=self.extension, available=self.available)
        self.file = File(local_file=self.local_file, available=self.available,
                         contentnode=self.contentnode, preset=self.preset)

        self.path = get_content_storage_file_path(self.filename)
        path_dir = os.path.dirname(self.path)
        if not os.path.exists(path_dir):
            os.makedirs(path_dir)
        tempfile = open(self.path, "w")
        tempfile.write("test")
        tempfile.close()