Exemplo n.º 1
0
 def do_download(self, line):
     """Download the selected logs."""
     for le in self.my_list:
         if le[0]:  # list row is marked as selected
             if not app_config.verbose:
                 sp = Spinner()
             res = self.down_load.get_DBI3_log(le[1].name_start)
             le[0] = False  # clear the select flag
             if not app_config.verbose:
                 sp.stop()
             get_log().info(res)
Exemplo n.º 2
0
 def do_convert(self, line):
     """Download AND convert the selected logs."""
     for le in self.my_list:
         if le[0]:  # list row is marked as selected
             if not app_config.verbose:
                 sp = Spinner()
             res = self.down_load.get_DBI3_log(le[1].name_start)
             if not app_config.verbose:
                 sp.stop()
             get_log().info(res)
             p_path = os.path.join(app_config.log_path,
                                   self.down_load.dbi3_sn)
             kml_name = le[1].start_dt.strftime("%Y%m%d_%H%M_{}".format(
                 self.down_load.dbi3_sn))
             if not app_config.verbose:
                 sp = Spinner()
             dbi3_obj = Dbi3LogConversion(
                 os.path.join(p_path, le[1].log_name), app_config)
             rtn, rtn_str = dbi3_obj.kml_convert(
                 os.path.join(app_config.kml_path, kml_name))
             if not app_config.verbose:
                 sp.stop()
             if rtn < 0:
                 get_log().info("Convert {} to {} FAILED: {}".format(
                     le[1].log_name, kml_name, rtn_str))
             elif rtn > 0 and app_config.verbose:
                 get_log().info("Convert {} to KML : {}".format(
                     le[1].log_name, rtn_str))
                 le[0] = False  # clear the select flag
             elif rtn == 0:
                 get_log().info("Convert {} to KML\n{}".format(
                     le[1].log_name, rtn_str))
                 le[0] = False  # clear the select flag
Exemplo n.º 3
0
    def do_delete(self, line):
        """Delete the selected log files on the DBI3"""
        deleted_log = False
        for le in self.my_list:
            if le[0]:  # list row is marked as selected
                new_val = input(
                    "This will delete {} {} from the DBI3.\nAre you sure you want to continue? "
                    .format(le[1].name_start, le[1].log_name))
                if new_val.startswith("y"):
                    self.down_load.delete_DBI3_log(le[1].name_start)
                    deleted_log = True
                    get_log().info("Deleted log {} {} from the DBI3".format(
                        le[1].log_name, le[1].name_start))

        # Delete has invalidated the list, so refresh
        if deleted_log:
            print("Refresh the log list--")
            self.do_refresh("")
Exemplo n.º 4
0
def convert_new_logs(app_config):
    """Convert new DBI3 logs to kml output

    For each DBI3 log file, if the corresponding kml file does not exists,
    run the conversion.

    :param Dbi3ConfigOptions app_config: Application config object
    :return: none
    """
    conv_list = Dbi3KmlList(config=app_config)
    conv_list.refresh_list()
    for le in conv_list.conversion_list:
        if le.new_file:  # only process files marked as new
            if not app_config.verbose:
                sp = Spinner()
            dbi3_obj = Dbi3LogConversion(le.log_filename, app_config)
            rtn, rtn_str = dbi3_obj.kml_convert(le.kml_filename)
            if not app_config.verbose:
                sp.stop()
            if rtn < 0:
                get_log().info(
                    "Convert FAILED {} to KML  new:{}  edits:{}   to {}\n{}".
                    format(le.log_name, "Y" if le.new_file else "N",
                           le.override, le.kml_name, rtn_str))
            elif rtn > 0 and app_config.verbose:
                # not converted warning (probably no GPS data)
                get_log().info(
                    "Convert {} to KML  new:{}  edits:{}\n{}".format(
                        le.log_name, "Y" if le.new_file else "N", le.override,
                        rtn_str))
            elif rtn == 0:
                get_log().info(
                    "Converted {} to KML  new:{}  edits:{}\n{}".format(
                        le.log_name, "Y" if le.new_file else "N", le.override,
                        rtn_str))
Exemplo n.º 5
0
def process_dbi():
    """Non-interactive DBI3 download/convert method.
    Download 'new' logs from the DBI3.  Convert 'new' downloaded logs to KML.
    'new' is defined as a log newer than what is currently on the PC.
    """
    _verify_paths()  # ensure log/kml paths exist

    down_load = None
    try:
        # log list elements contain list 'startRad26, stopRad26, start_dt, stop_dt, log_filename'
        # The log list automatically marks new logs as selected for download.
        down_load = DBI3LogDownload(app_config)
        if not app_config.verbose:
            sp = Spinner()
        log_list = down_load.get_DBI3_log_list(True)

        if log_list is not None:
            rtn = down_load.download_new_logs(log_list)
        if not app_config.verbose:
            sp.stop()
        if rtn:
            get_log().info("\n  ".join(rtn))

    except IOError as e:
        if down_load is not None and down_load.dbi3_sn is not None:
            sn = down_load.dbi3_sn
        else:
            sn = "No SN"
        com = app_config.com_port if app_config.com_port is not None else "NoPort"
        print("IO error with DBI3({}) on {}: {}".format(sn, com, e))
        print("Skip DBI3 log downloads")
        return

    # Based on the SN of the DBI3 we are connected to, adjust the log path
    app_config.update_dbi3_sn(down_load.dbi3_sn)
    convert_new_logs(app_config)
Exemplo n.º 6
0
    def do_convert(self, line):
        """Convert the currently selected DBI3 logs to KML"""
        # le array, [0]=select bool, [1]=ConversionList namedtuple
        for le in self.my_list:
            if le[0]:
                if not app_config.verbose:
                    sp = Spinner()
                dbi3_obj = Dbi3LogConversion(le[1].log_filename, app_config)
                rtn, rtn_str = dbi3_obj.kml_convert(le[1].kml_filename)
                if not app_config.verbose:
                    sp.stop()
                if rtn < 0:
                    get_log().info("Convert {} to KML {} FAILED: {}".format(
                        le[1].log_name, le[1].kml_name, rtn_str))
                elif rtn > 0 and app_config.verbose:
                    get_log().info("Convert {} to KML: {}".format(
                        le[1].log_name, rtn_str))
                    le[0] = False  # clear the select flag
                elif rtn == 0:
                    get_log().info("Convert {} to KML\n{}".format(
                        le[1].log_name, rtn_str))
                    le[0] = False  # clear the select flag

                # TODO - this is a temporary hack for development
                #        csv enabled by command line flag
                if do_csv:
                    csv_filename = os.path.join(os.path.expanduser("~"),
                                                "Documents",
                                                le[1].kml_name + ".csv")
                    rtn, rtn_str = dbi3_obj.csv_convert(csv_filename)
                    if rtn < 0:
                        get_log().info(
                            "Convert {} to CSV {} FAILED: {}".format(
                                le[1].log_name, csv_filename, rtn_str))
                    elif rtn > 0 and app_config.verbose:
                        get_log().info("Convert {} to CSV: {}".format(
                            le[1].log_name, rtn_str))
                    elif rtn == 0:
                        get_log().info("Convert {} to CSV\n{}".format(
                            le[1].log_name, rtn_str))