-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileservice.py
More file actions
32 lines (25 loc) · 1.36 KB
/
Copy pathfileservice.py
File metadata and controls
32 lines (25 loc) · 1.36 KB
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
from pathlib import Path
from dataobjects import ItemFileMatchType
class ItemFileService:
_self = None
def __new__(cls):
if cls._self is None:
cls._self = super().__new__(cls)
return cls._self
def item_file_exists(self, file_name: str, file_name_matching: ItemFileMatchType, file_extension: str, item_directory: str) -> bool:
return len(self.item_files(file_name, file_name_matching, file_extension, item_directory)) > 0
def item_files(self, file_name: str, file_name_matching: ItemFileMatchType, file_extension: str, item_directory: str) -> list:
item_dir = Path(item_directory)
files = []
if file_name_matching == ItemFileMatchType.EXACT:
# file_name may be multiple files with optional description for each
# file1.ext|file1 description;file2.ext|file2 description
for file_desc in file_name.strip().split(";"):
fd = (file_desc+"|").split("|")
file = item_dir/(fd[0].strip()+file_extension)
if file.exists():
files.append({"file": file, "description": fd[1].strip()})
if file_name_matching == ItemFileMatchType.BEGINS:
for file in list(item_dir.glob(file_name+"*"+file_extension)):
files.append({"file":file, "description": ""})
return files