Skip to content

Commit

Permalink
Only update the batch file if something changes
Browse files Browse the repository at this point in the history
Expanding on #6
  • Loading branch information
djw8605 committed Aug 30, 2013
1 parent 148f769 commit 474769c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
10 changes: 7 additions & 3 deletions R/grid.batchFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function(grid.input.Parameters, fName, yName, varlist, scriptName, remScriptName
#read outputs
while(count_done < length(cmd))
{
count_done_prev = count_done
count_done = 0
count=1
while(count<=length(cmd))
Expand All @@ -126,9 +127,12 @@ function(grid.input.Parameters, fName, yName, varlist, scriptName, remScriptName
else
ret[[count]]=grid.input.Parameters#c(y, paste("result from parameters:",cmd[count]))
count_done = count_done + 1
grid.input.Parameters = ret
unlink(yName)
save(list=c("grid.batch_done", "grid.input.Parameters"), file=yName)
if ( count_done_prev != count_done ) {
# Only update the file if something changed
grid.input.Parameters = ret
unlink(yName)
save(list=c("grid.batch_done", "grid.input.Parameters"), file=yName)
}

}
if(file.exists(paste(scriptName, "out",sep=""))){
Expand Down
15 changes: 10 additions & 5 deletions inst/GridR/R-bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,12 @@ def installR(install_dir):
# Ok, now move the R installation into the correct directory
tmp_r_dir = os.path.join(tmp_dir, 'R')
for rDir in os.listdir(tmp_r_dir):
shutil.rmtree(os.path.join(install_dir, rDir), ignore_errors=True)
shutil.move(os.path.join(tmp_r_dir, rDir), os.path.join(install_dir, rDir))
try:
shutil.rmtree(os.path.join(install_dir, rDir), ignore_errors=True)
shutil.move(os.path.join(tmp_r_dir, rDir), os.path.join(install_dir, rDir))
except OSError:
sys.stderr.write("Unable to move directory: %s, moving on..." % rDir)

#shutil.move(os.path.join(tmp_dir, 'R'), install_dir)
shutil.rmtree(tmp_dir)

Expand Down Expand Up @@ -245,19 +249,20 @@ def main():
# Initialize to some time way in the past
completed_date = datetime(1970, 1, 1)
try:
completed_date = datetime.fromtimestamp(os.path.getmtime(os.path.join(r_dir, ".completed")))
completed_date = datetime.utcfromtimestamp(os.path.getmtime(os.path.join(r_dir, ".completed")))

except OSError:
# If there's an OS error, then that typically means that the .completed file
# was removed (race condition). We can just ignore it.
sys.stderr.write("The .completed file was deleted on us")
sys.stderr.write("The .completed file was deleted on us\n")
pass

if completed_date < server_date:
sys.stderr.write("Completed time is before server time")
sys.stderr.write("Completed time is before server time\n")
sys.stderr.write(str(completed_date))
sys.stderr.write(str(server_date))
try:
os.remove(os.path.join(r_dir, ".started"))
os.remove(os.path.join(r_dir, ".completed"))
except OSError:
pass
Expand Down

0 comments on commit 474769c

Please sign in to comment.