-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingularity.py
37 lines (29 loc) · 1.13 KB
/
singularity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
## Helper functions for singularity container solution
from subprocess import check_output
import json
import os
#Source: https://singularityhub.github.io/singularity-cli/api/modules/spython/main/inspect.html#inspect
def get_container_details(image):
'''
Input: Container image file
Output: dict of labels
'''
cmd = ['singularity', 'inspect', image]
out_bytes = check_output(cmd)
out_decoded = out_bytes.decode('utf-8').replace("'", '"')
json_dict = json.loads(out_decoded)
json_dict['image.filename'] = os.path.split(image)[1]
return json_dict
def get_all_container(path):
''' This function is looking for img-files in a given path and returns their
absolute path as a list
'''
image_list = []
for root, _, files in os.walk(path):
for filename in files:
full_path = os.path.join(root, filename)
# FIXME better check for magic rather than extensionm
if os.path.splitext(full_path)[1] == '.img':
image_list.append(full_path)
sorted_image_list = sorted(image_list)
return sorted_image_list