-
Notifications
You must be signed in to change notification settings - Fork 0
/
gr_sys_utils.py
48 lines (37 loc) · 1.09 KB
/
gr_sys_utils.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
38
39
40
41
42
43
44
45
46
47
48
import os
from pathlib import Path
base_dir = Path(os.path.join(os.path.expanduser("~"), "geneRender"))
base_dir.mkdir(exist_ok=True)
def listdir(fld):
"""
List the files into a folder with the complete file path instead of the relative file path like os.listdir.
:param fld: string, folder path
"""
return [str(f) for f in Path(fld).glob("**/*") if f.is_file()]
def get_subdirs(folderpath):
"""
Returns the subfolders in a given folder
"""
return [str(f) for f in Path(folderpath).glob("**/*") if f.is_dir()]
def listify(obj):
"""
makes sure that the obj is a list
"""
if isinstance(obj, list):
return obj
elif isinstance(obj, tuple):
return list(obj)
else:
return [obj]
def return_list_smart(lst):
"""
If the list has length > returns the list
if it has length == 1 it returns the element
if it has length == 0 it returns None
"""
if len(lst) > 1:
return lst
elif len(lst) == 1:
return lst[0]
else:
return None