def _list_dir(self, path): path = self._dir_path(path) iterator = GCSObject(path).ls(delimiter='/') _, object_name = self._local_filesystem_path_to_gcs_path(path) object_name = self._dir_path(object_name) blobs = list(iterator) prefixes = iterator.prefixes files = [] dirs = [] for blob in blobs: name = blob.name.replace(object_name, '', 1) if name != '': size = readable_size(blob.size) modified = blob.updated.strftime("%Y-%m-%d") files.append(FileInfo(name, size, modified)) for prefix in prefixes: dirs.append(DirectoryInfo(prefix.replace(object_name, '', 1)[:-1])) files.sort() dirs.sort() return files, dirs
def list_dir(self): iterator = self.client().list_blobs(self.bucket_name(), prefix=self.dir_key(), delimiter='/') blobs = list(iterator) prefixes = iterator.prefixes files = [] dirs = [] for blob in blobs: name = blob.name.replace(self.dir_key(), '', 1) if name != '': size = readable_size(blob.size) modified = blob.updated.strftime("%Y-%m-%d") files.append(FileInfo(name, size, modified)) for prefix in prefixes: dirs.append( DirectoryInfo(prefix.replace(self.dir_key(), '', 1)[:-1])) files.sort() dirs.sort() return files, dirs
def clean_file_field(self): """ Check for file name, size limits and whether they are readable """ files = self.files.getlist('file_field') for file in files: validators.validate_filename(file.name) # Special error if not file: raise forms.ValidationError( 'Could not read file: %(file_name)s', params={'file_name': file.name}) for file in files: if file.size > ActiveProject.INDIVIDUAL_FILE_SIZE_LIMIT: raise forms.ValidationError( 'File %(file_name)s is larger than the individual size limit: %(individual_size_limit)s', code='exceed_individual_limit', params={ 'file_name': file.name, 'individual_size_limit': utility.readable_size( ActiveProject.INDIVIDUAL_FILE_SIZE_LIMIT) }) if sum( f.size for f in files ) > self.project.core_project.storage_allowance - self.project.storage_used( ): raise forms.ValidationError( 'Total upload volume exceeds remaining quota', code='exceed_remaining_quota', ) return files