| |
@@ -9027,6 +9027,45 @@
|
| |
context.session.assertPerm('admin')
|
| |
return make_task(*args, **opts)
|
| |
|
| |
+ def listFiles(self, path_mask, volume=None):
|
| |
+ '''
|
| |
+ retrive a file list from koji
|
| |
+ :param path_mask: relative path mask (* to replace part of the path)
|
| |
+ could be used like "mbs/*-19/*.json"
|
| |
+ :return: dict containing file list, keys are file/dir name
|
| |
+ '''
|
| |
+ path_mask = os.path.normpath(path_mask)
|
| |
+ if not path_mask or path_mask.startswith('..'):
|
| |
+ raise koji.GenericError("Invalid path mask: %s" % path_mask)
|
| |
+ if volume is not None:
|
| |
+ # make sure the volume is valid
|
| |
+ lookup_name('volume', volume, strict=True)
|
| |
+ parts = path_mask.split('/')
|
| |
+ list_root_path = koji.pathinfo.work(volume=volume)
|
| |
+ return self._list_dir(list_root_path, parts)
|
| |
+
|
| |
+ @classmethod
|
| |
+ def _list_dir(cls, list_root_path, path_parts, level=0):
|
| |
+ ret_val = {'files': {}, 'subdirs': {}}
|
| |
+ if level < len(path_parts):
|
| |
+ template = path_parts[level]
|
| |
+ else:
|
| |
+ template = '*'
|
| |
+ template = template.replace('.', r'\.')
|
| |
+ template = template.replace('*', r'.*')
|
| |
+ template_re = re.compile(r'^' + template + r'$')
|
| |
+ for dir_entry in os.listdir(list_root_path):
|
| |
+ if dir_entry.startswith('.'):
|
| |
+ continue
|
| |
+ if not template_re.match(dir_entry):
|
| |
+ continue
|
| |
+ full_path = os.path.join(list_root_path, dir_entry)
|
| |
+ if os.path.isdir(full_path):
|
| |
+ ret_val['subdirs'][dir_entry] = cls._list_dir(full_path, path_parts, level + 1)
|
| |
+ else:
|
| |
+ ret_val['files'][dir_entry] = {'size': os.path.getsize(full_path)}
|
| |
+ return ret_val
|
| |
+
|
| |
def uploadFile(self, path, name, size, md5sum, offset, data, volume=None):
|
| |
#path: the relative path to upload to
|
| |
#name: the name of the file
|
| |
@@ -9167,7 +9206,6 @@
|
| |
# this will also free our lock
|
| |
os.close(fd)
|
| |
|
| |
-
|
| |
def downloadTaskOutput(self, taskID, fileName, offset=0, size=-1, volume=None):
|
| |
"""Download the file with the given name, generated by the task with the
|
| |
given ID."""
|
| |
used for MBS (fm-orchestrator)
Signed-off-by: Valerij Maljulin vmaljuli@redhat.com