5
5
from dpdispatcher import dlog
6
6
from subprocess import TimeoutExpired
7
7
8
- # class LocalSession (object) :
9
- # def __init__ (self, jdata) :
10
- # self.work_path = os.path.abspath(jdata['work_path'])
11
- # assert(os.path.exists(self.work_path))
12
-
13
- # def get_work_root(self) :
14
- # return self.work_path
15
8
16
9
class SPRetObj (object ) :
17
10
def __init__ (self ,
@@ -60,18 +53,6 @@ def __init__(self,
60
53
self .temp_local_root = os .path .abspath (local_root )
61
54
self .temp_remote_root = os .path .abspath (remote_root )
62
55
self .remote_profile = remote_profile
63
- # self.work_profile = work_profile
64
- # self.job_uuid = job_uuid
65
- # self.submission = None
66
- # if job_uuid:
67
- # self.job_uuid = job_uuid
68
- # else:
69
- # self.job_uuid = str(uuid.uuid4())
70
-
71
- # self.remote_root = os.path.join(work_profile.get_work_root(), self.job_uuid)
72
- # dlog.debug("local_root is %s"% local_root)
73
-
74
- # os.makedirs(self.remote_root, exist_ok = True)
75
56
76
57
@classmethod
77
58
def load_from_dict (cls , context_dict ):
@@ -92,34 +73,9 @@ def bind_submission(self, submission):
92
73
self .submission = submission
93
74
self .local_root = os .path .join (self .temp_local_root , submission .work_base )
94
75
self .remote_root = os .path .join (self .temp_remote_root , submission .submission_hash )
95
- # print('debug:LocalContext.bind_submission', submission.submission_hash,
96
- # self.local_root, self.remote_root)
97
-
98
- # os.makedirs(self.remote_root, exist_ok = True)
99
- # self.job_uuid = submission.submission_hash
100
- # self.remote_root = os.path.join(self.work_profile.get_work_root(), self.job_uuid)
101
- # os.makedirs(self.remote_root, exist_ok = True)
102
- # print('local_context.bind_submission:self.remote_root', self.remote_root)
103
- # dlog.debug("remote_root is %s"% self.remote_root)
104
-
105
- # @property
106
- # def remote_root(self):
107
- # print('local_context.remote_root:self.submission.submission_hash', self.submission.submission_hash)
108
- # print('local_context.remote_root self.submission', self.submission)
109
- # self._remote_root = os.path.join(self.work_profile.get_work_root(), self.submission.submission_hash, self.submission.work_base)
110
- # os.makedirs(self._remote_root, exist_ok = True)
111
- # return self._remote_root
112
-
113
- # @property
114
- # def local_root(self):
115
- # # self.local_root = os.path.abspath(local_root)
116
- # self._local_root = os.path.join(, self.submission.submission_hash, self.submission.work_base)
117
- # return self._local_root
118
76
119
77
def upload (self , submission ):
120
78
os .makedirs (self .remote_root , exist_ok = True )
121
- # os.makedirs(self.remote_root, exist_ok = True)
122
- # job_dirs = [ ii.task_work_path for ii in submission.belonging_tasks]
123
79
for ii in submission .belonging_tasks :
124
80
local_job = os .path .join (self .local_root , ii .task_work_path )
125
81
remote_job = os .path .join (self .remote_root , ii .task_work_path )
@@ -138,13 +94,12 @@ def upload(self, submission):
138
94
raise RuntimeError ('cannot find upload file ' + os .path .join (local_job , jj ))
139
95
if os .path .exists (os .path .join (remote_job , jj )) :
140
96
os .remove (os .path .join (remote_job , jj ))
141
- _check_file_path (jj )
97
+ _check_file_path (os . path . join ( remote_job , jj ) )
142
98
os .symlink (os .path .join (local_job , jj ),
143
99
os .path .join (remote_job , jj ))
144
100
145
101
local_job = self .local_root
146
102
remote_job = self .remote_root
147
- # os.makedirs(remote_job, exist_ok = True)
148
103
149
104
file_list = []
150
105
for kk in submission .forward_common_files :
@@ -159,39 +114,19 @@ def upload(self, submission):
159
114
raise RuntimeError ('cannot find upload file ' + os .path .join (local_job , jj ))
160
115
if os .path .exists (os .path .join (remote_job , jj )) :
161
116
os .remove (os .path .join (remote_job , jj ))
162
- _check_file_path (jj )
117
+ _check_file_path (os . path . join ( remote_job , jj ) )
163
118
os .symlink (os .path .join (local_job , jj ),
164
119
os .path .join (remote_job , jj ))
165
120
166
- def upload_ (self ,
167
- job_dirs ,
168
- local_up_files ,
169
- dereference = True ) :
170
- for ii in job_dirs :
171
- local_job = os .path .join (self .local_root , ii )
172
- remote_job = os .path .join (self .remote_root , ii )
173
- os .makedirs (remote_job , exist_ok = True )
174
- for jj in local_up_files :
175
- if not os .path .exists (os .path .join (local_job , jj )):
176
- raise RuntimeError ('cannot find upload file ' + os .path .join (local_job , jj ))
177
- if os .path .exists (os .path .join (remote_job , jj )) :
178
- os .remove (os .path .join (remote_job , jj ))
179
- _check_file_path (jj )
180
- os .symlink (os .path .join (local_job , jj ),
181
- os .path .join (remote_job , jj ))
182
-
183
-
184
121
def download (self ,
185
122
submission ,
186
123
check_exists = False ,
187
124
mark_failure = True ,
188
125
back_error = False ) :
189
126
190
127
for ii in submission .belonging_tasks :
191
- # for ii in job_dirs :
192
128
local_job = os .path .join (self .local_root , ii .task_work_path )
193
129
remote_job = os .path .join (self .remote_root , ii .task_work_path )
194
- # flist = remote_down_files
195
130
flist = ii .backward_files
196
131
if back_error :
197
132
flist += glob (os .path .join (remote_job , 'error*' ))
@@ -227,18 +162,11 @@ def download(self,
227
162
elif os .path .isfile (lfile ) or os .path .islink (lfile ):
228
163
os .remove (lfile )
229
164
shutil .copyfile (rfile , lfile )
230
- # shutil.move(rfile, lfile)
231
165
else :
232
166
raise RuntimeError ('should not reach here!' )
233
167
else :
234
168
# no nothing in the case of linked files
235
169
pass
236
- # for ii in submission.belonging_tasks:
237
- # for ii in job_dirs :
238
- # local_job = os.path.join(self.local_root, ii.task_work_path)
239
- # remote_job = os.path.join(self.remote_root, ii.task_work_path)
240
- # flist = remote_down_files
241
- # flist = ii.backward_files
242
170
local_job = self .local_root
243
171
remote_job = self .remote_root
244
172
flist = submission .backward_common_files
@@ -274,61 +202,12 @@ def download(self,
274
202
elif os .path .isfile (lfile ) or os .path .islink (lfile ):
275
203
os .remove (lfile )
276
204
shutil .copyfile (rfile , lfile )
277
- # shutil.move(rfile, lfile)
278
205
else :
279
206
raise RuntimeError ('should not reach here!' )
280
207
else :
281
208
# no nothing in the case of linked files
282
209
pass
283
210
284
-
285
-
286
- def download_ (self ,
287
- job_dirs ,
288
- remote_down_files ,
289
- check_exists = False ,
290
- mark_failure = True ,
291
- back_error = False ) :
292
- for ii in job_dirs :
293
- local_job = os .path .join (self .local_root , ii )
294
- remote_job = os .path .join (self .remote_root , ii )
295
- flist = remote_down_files
296
- if back_error :
297
- flist += glob (os .path .join (remote_job , 'error*' ))
298
- for jj in flist :
299
- rfile = os .path .join (remote_job , jj )
300
- lfile = os .path .join (local_job , jj )
301
- if not os .path .realpath (rfile ) == os .path .realpath (lfile ) :
302
- if (not os .path .exists (rfile )) and (not os .path .exists (lfile )):
303
- if check_exists :
304
- if mark_failure :
305
- with open (os .path .join (self .local_root , ii , 'tag_failure_download_%s' % jj ), 'w' ) as fp :
306
- pass
307
- else :
308
- pass
309
- else :
310
- raise RuntimeError ('do not find download file ' + rfile )
311
- elif (not os .path .exists (rfile )) and (os .path .exists (lfile )) :
312
- # already downloaded
313
- pass
314
- elif (os .path .exists (rfile )) and (not os .path .exists (lfile )) :
315
- # trivial case, download happily
316
- shutil .move (rfile , lfile )
317
- elif (os .path .exists (rfile )) and (os .path .exists (lfile )) :
318
- # both exists, replace!
319
- dlog .info ('find existing %s, replacing by %s' % (lfile , rfile ))
320
- if os .path .isdir (lfile ):
321
- shutil .rmtree (lfile , ignore_errors = True )
322
- elif os .path .isfile (lfile ) or os .path .islink (lfile ):
323
- os .remove (lfile )
324
- shutil .move (rfile , lfile )
325
- else :
326
- raise RuntimeError ('should not reach here!' )
327
- else :
328
- # no nothing in the case of linked files
329
- pass
330
-
331
-
332
211
def block_checkcall (self ,
333
212
cmd ) :
334
213
proc = sp .Popen (cmd , cwd = self .remote_root , shell = True , stdout = sp .PIPE , stderr = sp .PIPE )
@@ -351,9 +230,6 @@ def block_call(self, cmd) :
351
230
def clean (self ):
352
231
shutil .rmtree (self .remote_root , ignore_errors = True )
353
232
354
- # def _clean(self) :
355
- # shutil.rmtree(self.remote_root, ignore_errors=True)
356
-
357
233
def write_file (self , fname , write_str ):
358
234
os .makedirs (self .remote_root , exist_ok = True )
359
235
with open (os .path .join (self .remote_root , fname ), 'w' ) as fp :
0 commit comments