This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
FileStateClient.py
99 lines (68 loc) · 2.71 KB
/
FileStateClient.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from FileState import FileState
from pUtil import tolog
def createFileStates(workDir, jobId, outFiles=None, inFiles=None, logFile=None, ftype="output"):
""" Create the initial file state dictionary """
# file list
if ftype == "output":
files = outFiles
files.append(logFile)
else:
files = inFiles
# create temporary file state object
FS = FileState(workDir=workDir, jobId=jobId, ftype=ftype)
FS.resetStates(files, ftype=ftype)
# cleanup
del FS
def updateFileStates(files, workDir, jobId, mode="file_state", state="not_created", ftype="output"):
""" Update the current file states (for all files) """
# create a temporary file state object
FS = FileState(workDir=workDir, jobId=jobId, ftype=ftype)
# update all files
for fileName in files:
FS.updateState(fileName, mode=mode, state=state)
# cleanup
del FS
def updateFileState(fileName, workDir, jobId, mode="file_state", state="not_created", ftype="output"):
""" Update the current file states (for all files) """
# create a temporary file state object
FS = FileState(workDir=workDir, jobId=jobId, ftype=ftype)
# update this file
FS.updateState(fileName, mode=mode, state=state)
# cleanup
del FS
def dumpFileStates(workDir, jobId, ftype="output"):
""" Update the current file states (for all files) """
# create a temporary file state object
FS = FileState(workDir=workDir, jobId=jobId, ftype=ftype)
# dump file states for all files
FS.dumpFileStates(ftype=ftype)
# cleanup
del FS
def getFilesOfState(workDir, jobId, ftype="output", state="transferred"):
""" Return a comma-separated list of files in a given state"""
# create a temporary file state object
FS = FileState(workDir=workDir, jobId=jobId, ftype=ftype)
# get the list
filenames = FS.getFilesOfState(state=state)
# cleanup
del FS
return filenames
def hasOnlyCopyToScratch(workDir, jobId):
""" Check if there are only copy_to_scratch tranfer modes in the file dictionary """
# goal: remove --directIn in cmd3 if there are only transfer mode "copy_to_scratch" files
# create a temporary file state object
FS = FileState(workDir=workDir, jobId=jobId, ftype="input")
# are there only "copy_to_scratch" files in the file dictionary?
status = FS.hasOnlyCopyToScratch()
# cleanup
del FS
return status
def getFileState(fileName, workDir, jobId, ftype="output"):
""" Return the current state of a given file """
# create a temporary file state object
FS = FileState(workDir=workDir, jobId=jobId, ftype=ftype)
# update this file
state = FS.getFileState(fileName)
# cleanup
del FS
return state