def retreive(self, storage_key, path, recursive=True):
        storage = get_storage_class(storage_key)
        lines = storage._get_dir_extra_details(path, recursive)

        items = []

        current_path = path
        stor = FileStorage.objects.get(config_name=storage_key)

        for line in lines:
            print '-'* 25
            if not line:
                print '<blank>'
                # blank line
                continue
            elif line.endswith(":"):
                # switch current directory
                current_path = line[:-1]
                print 'switch to "{}"'.format(current_path)
                continue
            ln = self._split_line(line)
            print ln

            if ln['directory'] == 'd':
                item = self._cache_directory(stor, current_path, ln)
            else:
                item = self._cache_file(stor, current_path, ln)
            items.append(item)
    def __init__(self, verbose_name=None, name=None, path='', match=None,
                 allow_files=True, allow_folders=False, storage_key=None, **kwargs):
        self.path = path
        self.match = match
        self.allow_files = allow_files
        self.allow_folders = allow_folders
        self.storage_key = storage_key
        self.storage = None
        if storage_key:
            self.storage = get_storage_class(self.storage_key)

        kwargs['max_length'] = kwargs.get('max_length', 2048)

        super(AkamaiFilePathField, self).__init__(verbose_name=verbose_name, name=name, **kwargs)
    def validate(self, value, model_instance):
        if not self.editable:
            # Skip validation for non-editable fields.
            return

        if value is None and not self.null:
            raise exceptions.ValidationError(self.error_messages['null'], code='null')

        if not self.blank and value in self.empty_values:
            raise exceptions.ValidationError(self.error_messages['blank'], code='blank')

        # find storage
        storage = get_storage_class('default')
        if not storage.exists(value):
            raise exceptions.ValidationError(
                self.error_messages['invalid_choice'],
                code='invalid_choice',
                params={'value': value},
            )
    def __init__(self, path='', match=None, recursive=False, allow_files=True,
                 allow_folders=False, required=True, widget=None, label=None,
                 initial=None, help_text='', storage_key=None, storage_field=None, *args, **kwargs):

        self.path, self.match, self.recursive = path, match, recursive
        self.allow_files, self.allow_folders = allow_files, allow_folders
        self.storage_key, self.storage_field = storage_key, storage_field

        super(AkamaiFilePathField, self).__init__(choices=(), required=required,
            widget=widget, label=label, initial=initial, help_text=help_text,
            *args, **kwargs)

        if storage_key:
            storage = get_storage_class(storage_key)
        elif storage_field:
            storage = django_storage.default_storage
        else:
            storage = django_storage.default_storage

        if storage.__class__ != AkamaiNetStorage:
            raise ImproperlyConfigured('AkamaiFilePathField only works with AkamaiNetStorage storage.')

        if self.required:
            self.choices = []
        else:
            self.choices = [("", "---------")]

        storage._start_connection()
        dirs, files = storage._get_dir_details(path, recursive=recursive, show_folders=allow_folders, show_files=allow_files)

        lines = sorted(dirs.keys() + files.keys(), key=str)

        if self.match is not None:
            self.match_re = re.compile(self.match)

        for line in lines:
            if self.match is None or self.match_re.search(line):
                self.choices.append((line, line))

        self.widget.choices = self.choices
 def get_storage(self):
     return get_storage_class(self.config_name)