Commit c2fefe47 by Máhonfai Bálint

Change get_disk_images function in store API to get list of files with given extensions

parent f99b5852
......@@ -935,7 +935,9 @@ class VmImportDiskForm(OperationForm):
self.user = kwargs.pop('user')
super(VmImportDiskForm, self).__init__(*args, **kwargs)
disk_paths = Store(self.user).get_disk_images()
disk_paths = Store(self.user).get_files_with_exts(
[f[0] for f in Disk.EXPORT_FORMATS]
)
disk_filenames = [os.path.basename(item) for item in disk_paths]
self.choices = zip(disk_paths, disk_filenames)
......
......@@ -110,14 +110,16 @@ class Store(object):
else:
return result
def get_disk_images(self, path='/'):
images = []
def get_files_with_exts(self, exts, path='/'):
"""
Get list of files from store with the given file extensions.
"""
matching_files = []
file_list = self.list(path, process=False)
export_formats = [item[0] for item in Disk.EXPORT_FORMATS]
for item in file_list:
if os.path.splitext(item['NAME'])[1].strip('.') in export_formats:
images.append(os.path.join(path, item['NAME']))
return images
if os.path.splitext(item['NAME'])[1].strip('.') in exts:
matching_files.append(os.path.join(path, item['NAME']))
return matching_files
def request_download(self, path):
r = self._request_cmd("DOWNLOAD", PATH=path, timeout=10)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment