GISHydroNXT System Documentation
#*********************************************************************************
# Author: UMD
# Date: 24-07-2018
# Modified: n/a
# Classes: ExecuteTR20()
# Functions: hydro.openbrowser
# Modules: arcpy ; os ; webbrowser
# Comments: n/a
#*********************************************************************************
class ExecuteTR20(object):
"""Implementation for GISHydroNXT_addin.button15 (Button)"""
def __init__(self):
self.enabled = False
self.checked = False
def onClick(self):
if os.path.exists(optfolder + "/WinTR20tmp"):
shutil.rmtree(optfolder + "/WinTR20tmp")
if os.path.exists(optfolder + "/TR20"):
# specify path of input file
path = optfolder + "/TR20"
src = optfolder + "/TR20in.txt"
shutil.copy2(src, path) # To update "TR20in.txt" file
os.chdir(path)
Popen(["cmd", "/C", Directory + "/data/mdfiles/TR20/WinTR20_V31_64bit.exe TR20in.txt"])
else:
path = optfolder + "/TR20"
os.mkdir(path, 0755)
src2 = optfolder + "/TR20in.txt"
shutil.copy2(src2, path)
os.chdir(path)
Popen(["cmd", "/C", Directory + "/data/mdfiles/TR20/WinTR20_V31_64bit.exe TR20in.txt"])
copyfile(Directory + "/data/mdfiles/TR20/WinTR20_V31_64bit.exe", optfolder + "/TR20/WinTR20_V31_64bit.exe")
#*******************************************************************************************************
# Change extension of "TR20in.out" file from ".out" to ".txt" and open it in text editor
#*******************************************************************************************************
time.sleep(3) # sleep time is introduced to make sure above output is generated
if os.path.exists(optfolder + "/WinTR20tmp"):
WinTR20_path = optfolder + "/WinTR20tmp"
WinTR20_err = optfolder + "/TR20/TR20in.err"
shutil.copy2(WinTR20_err, WinTR20_path) # copy error file to temp folder
TR20err1 = optfolder + "/WinTR20tmp/TR20in.err"
base = os.path.splitext(TR20err1)[0]
os.rename(TR20err1, base + "_err.txt")
#*******************************************************************************************************
# If TR20 error file size is greater than "0" then display a warning message to check error file
#*******************************************************************************************************
filestats = os.path.getsize(optfolder + "/WinTR20tmp/TR20in_err.txt")
if filestats > 0:
pythonaddins.MessageBox("Please check file " + optfolder + "/TR20/TR20in.err" + " for possible errors","TR20 Input file error",0)
WinTR20_of = optfolder + "/TR20/TR20in.out"
shutil.copy2(WinTR20_of, WinTR20_path) # copy output file to temp folder
TR20out1 = optfolder + "/WinTR20tmp/TR20in.out"
base = os.path.splitext(TR20out1)[0]
os.rename(TR20out1, base + ".txt")
TR20out2 = optfolder + "/WinTR20tmp/TR20in.txt"
hydro.openbrowser(TR20out2) # 7/2/2017: need a new thread to open text file
else:
WinTR20_path = optfolder + "/WinTR20tmp"
os.mkdir(WinTR20_path, 0755)
WinTR20_err = optfolder + "/TR20/TR20in.err"
shutil.copy2(WinTR20_err, WinTR20_path) # copy error file to temp folder
TR20err1 = optfolder + "/WinTR20tmp/TR20in.err"
base = os.path.splitext(TR20err1)[0]
os.rename(TR20err1, base + "_err.txt")
#*******************************************************************************************************
# If TR20 error file size is greater than "0" then display a warning message to check error file
#*******************************************************************************************************
filestats = os.path.getsize(optfolder + "/WinTR20tmp/TR20in_err.txt")
if filestats > 0:
pythonaddins.MessageBox("Please check file " + optfolder + "/TR20/TR20in.err" + " for possible errors","TR20 Input file error",0)
WinTR20_of = optfolder + "/TR20/TR20in.out"
shutil.copy2(WinTR20_of, WinTR20_path) # copy output file to temp folder
TR20out1 = optfolder + "/WinTR20tmp/TR20in.out"
base = os.path.splitext(TR20out1)[0]
os.rename(TR20out1, base + ".txt")
TR20out2 = optfolder + "/WinTR20tmp/TR20in.txt"
hydro.openbrowser(TR20out2)