Ejemplo n.º 1
0
 def postRun(self):
     """
     Run additional tasks at the end of the core run.
     
     By default this method refreshes the HEC-DSSVue catalogue (if 
     :attr:`.refreshCatalogue` is true) and displays any string in 
     :attr:`.message`.
     """
     
     if self.refreshCatalogue and self.mainWindow:
         self.mainWindow.updateCatalog()
 
     if self.message:
         MessageBox.showInformation(self.message, "HEC-DSSVue")
Ejemplo n.º 2
0
import sys
from hec.heclib.util import HecTime
from hec.script import MessageBox
script_name = arg2
try:
    # Add rtsutils package to sys.path before importing
    sys.path.append(os.path.join(os.environ['APPDATA'], "rsgis"))
    from rtsutils import cavistatus, usgs
except ImportError, ex:
    raise
tw = cavistatus.get_timewindow()
if tw != None:
    st, et = tw
    print("Time window: {}".format(tw))
else:
    raise Exception('No Forecast open or in "Setup Tab"')
rts_dss = os.path.join(
    cavistatus.get_database_directory(),
    '{}-usgs-data.dss'.format(cavistatus.get_watershed().getName()))
retrieve = usgs.USGSDataRetrieve()
retrieve.set_dssfilename(rts_dss)
retrieve.set_begin_date(st)
retrieve.set_end_date(et)
retrieve.set_timezone('GMT')
retrieve.set_tzdss('GMT')
loc_file = os.path.join(cavistatus.get_shared_directory(),
                        'usgs_locations.csv')
retrieve.set_locations_file(loc_file)
retrieve.run()
MessageBox.showInformation("Script '{}' done!".format(script_name),
                           "End Process")
Ejemplo n.º 3
0
    '-host=' + host,
    '-endpoint=' + endpoint,
    '-after=' + after,
    '-before=' + before,
    '-scheme=' + scheme,
    '-stdout'
])
print('Subprocess Command: {}'.format(CMD))
sp = subprocess.Popen(
    CMD,
    shell=True,
    cwd=os.path.join(RSGIS, 'rtsutils'),
    stdout=subprocess.PIPE,
    stderr=subprocess.STDOUT,
)
dss = HecDss.open(dbdss, DSSVERSION)
byte_array = bytearray()
for b in iter(partial(sp.stdout.read, 1), b''):
    byte_array.append(b)
    if b == '}':
        obj = json.loads(str(byte_array))
        byte_array = bytearray()
        if 'message' in obj.keys(): raise Exception(obj['message'])
        msg = put_to_dss(obj, dss)
        if msg: print(msg)
if dss: dss.close()
print('Script Done!')
_end = datetime.now()
dur = _end - _start
MessageBox.showInformation('Download to: {}\n\nAfter: {}\n\nBefore: {}\n\nTime Duration: {}'.format(dbdss, after, before, dur), script_name)
Ejemplo n.º 4
0
    def submit(self, event):
        '''Collect user inputs and initiate download of DSS files to process.

        Event is a java.awt.event.ActionEvent
        '''

        start_timer = end_timer = System.currentTimeMillis()
        # Build the JSON from the UI inputs and POST if we have JSON
        json_string = self.json_build()
        cumulus_logger.debug("JSON String Builder: {}".format(json_string))

        if json_string is not None:
            cumulus_logger.info("*" * 50)
            cumulus_logger.info("Initiated Cumulus Product Request")
            cumulus_logger.info("*" * 50)
            post_result = self.http_post(json_string, url_downloads)
            json_post_result = json.loads(post_result)
            id = json_post_result['id']
            max_timeout = 180
            while max_timeout > 0:
                get_result = self.http_get("/".join([url_downloads, id]))
                if get_result is not None:
                    json_get_result = json.loads(get_result)
                    progress = json_get_result['progress']                          #100%
                    stat = json_get_result['status']                                #SUCCESS
                    fname = json_get_result['file']                                 # not null

                    cumulus_logger.info("Status: {:>10}; Progress: {:>4.1f}%; Timeout: {:>4}".format(stat, progress, max_timeout))

                    if stat == 'FAILED':
                        cumulus_logger.error("Failed to load grid products.")
                        MessageBox.showError(
                            "Failed to load grid products.",
                            "Failed Download"
                            )
                        break

                    if int(progress) == 100 and stat == 'SUCCESS' and fname is not None:
                        dest_dssfile = self.txt_select_file.getText()
                        cumulus_logger.debug("DSS Download Filname: {}".format(fname))
                        downloaded_dssfile = download_dss(fname)
                        if downloaded_dssfile is not None:
                            cumulus_logger.info("DSS file downloaded.")
                            merged_dssfiles = merge_dss(downloaded_dssfile, dest_dssfile)
                            if len(merged_dssfiles) > 0:
                                end_timer = System.currentTimeMillis()

                                msg = "DSS file downloaded and merged to: {}".format(
                                        '\n'.join([f for f in merged_dssfiles])
                                        )
                                cumulus_logger.info(msg)
                                MessageBox.showInformation(msg,
                                    "Successful Processing"
                                )
                            else:
                                msg = "DSS file merge unsuccessful"
                                cumulus_logger.warning(msg)
                                MessageBox.showWarning(msg,
                                    "Unsuccessful Merge"
                                )
                        else:
                            msg = "Downloading and processing the DSS file failed!"
                            cumulus_logger.error(msg)
                            MessageBox.showError(msg,
                                "Failed Processing"
                                )
                        break
                    else:
                        Thread.sleep(2000)
                    max_timeout -= 1

            cumulus_logger. info(
                "Submit time duration (milliseconds): {}".format(
                    (end_timer - start_timer)
                )
            )
        # Try to clean up any dss6 and dss7 files in the temp
        try:
            tempdir = tempfile.gettempdir()
            dss_temp_files = os.listdir(tempdir)
            for f in dss_temp_files:
                if (f.endswith(".dss") or f.endswith(".dss")):
                    os.remove(os.path.join(tempdir, f))
        except OSError as ex:
            cumulus_logger.warning(str(ex))