Exemplo n.º 1
0
    def output(self):
        first_time = False
        if self.start_time is None:
            first_time = True
            self.start_time = time.time()
        elapsed_time = 1000 * (time.time() - self.lastupdate)
        dur_s = int(time.time() - self.start_time)
        duration = pretty_duration(dur_s)
        # For NO_UI we still want a keepalive signal but we don't want the quick-update progress bars
        if NO_UI:
            if first_time or elapsed_time > self.timer:
                self.lastupdate = time.time()
                writestr = ""

                if self.byteFormat:
                    writestr = "        PROGRESS: {} / {}    {}     (Ellapsed: {})\n".format(
                        sizeof_fmt(self.progress), sizeof_fmt(self.total),
                        self.text, duration)
                else:
                    pct_done = int(100 * (self.progress / self.total))
                    writestr = "        PROGRESS: {:,} / {:,}  ({}%)  {}     (Ellapsed: {})\n".format(
                        self.progress, self.total, pct_done, self.text,
                        duration)
                sys.stdout.write(writestr)
                sys.stdout.flush()
            return
        if first_time or elapsed_time > self.timer:
            tSize = shutil.get_terminal_size((80, 20))
            self.lastupdate = time.time()
            done = 0
            if self.total > 0:
                done = int(50 * self.progress / self.total)
            self.erase()
            writestr = ""
            if self.byteFormat:
                writestr = "\r[{}{}]  {} / {}  {} (Ellapsed: {})     \n".format(
                    '=' * done, ' ' * (50 - done), sizeof_fmt(self.progress),
                    sizeof_fmt(self.total), self.text, duration)
            else:
                writestr = "\r[{}{}]  {:,} / {:,}  {} (Ellapsed: {})     \n".format(
                    '=' * done, ' ' * (50 - done), self.progress, self.total,
                    self.text, duration)

            if len(writestr) > tSize.columns - 1:
                writestr = writestr[0:tSize.columns - 4] + '   \n'

            sys.stdout.write(writestr)
            sys.stdout.flush()
            self.visible = True
Exemplo n.º 2
0
def print_geom_size(logger: Logger, geom_obj: BaseGeometry):
    try:
        size_str = sizeof_fmt(get_obj_size(geom_obj.wkb))
        logger.debug('Byte Size of output object: {} Type: {} IsValid: {} Length: {} Area: {}'.format(size_str, geom_obj.type, geom_obj.is_valid, geom_obj.length, geom_obj.area))
    except Exception as e:
        logger.debug(e)
        logger.debug('Byte Size of output object could not be determined')
Exemplo n.º 3
0
 def finish(self):
     if (self.start_time is None):
         duration = "0s"
     else:
         duration = pretty_duration(int(time.time() - self.start_time))
     if self.byteFormat:
         writestr = "Completed: {}  Total Time: {}     \n".format(
             sizeof_fmt(self.total), duration)
     else:
         writestr = "Completed {:,} operations.  Total Time: {}     \n".format(
             self.total, duration)
     log = Logger(self.text)
     log.info(writestr)
Exemplo n.º 4
0
    def layerprint(self, lyr_el, parent_el, project_root, level: int = 2):
        """Work in progress for printing Riverscapes layers

        Args:
            lyr_el ([type]): [description]
            section ([type]): [description]
            project_root ([type]): [description]
        """
        tag = lyr_el.tag
        name = lyr_el.find('Name').text
        # For geopackages
        layers = lyr_el.find('Layers')

        section = self.section(None, '{}: {}'.format(tag, name), parent_el, level=level, attrib={'class': 'rsc-layer'})

        meta = self.xml_project.get_metadata_dict(node=lyr_el)
        if meta is not None:
            self.create_table_from_dict(meta, section, attrib={'class': 'fullwidth'})

        path_el = ET.Element('pre', attrib={'class': 'path'})
        pathstr = lyr_el.find('Path').text
        size = 0
        fpath = os.path.join(project_root, pathstr)
        if os.path.isfile(fpath):
            size = os.path.getsize(fpath)

        if layers is not None:
            layers_container = ET.Element('div', attrib={'class': 'inner-layer-container'})
            RSReport.header(level + 1, 'Layers', layers_container)
            for layer_el in list(layers):
                self.layerprint(layer_el, layers_container, os.path.join(project_root, pathstr), level=level + 1)

            section.append(layers_container)

        footer = ET.Element('div', attrib={'class': 'layer-footer'})
        path_el.text = 'Project path: {}  ({})'.format(pathstr, sizeof_fmt(size))
        footer.append(path_el)
        section.append(footer)