cogeotiff / rio-cogeo

Cloud Optimized GeoTIFF creation and validation plugin for rasterio
https://cogeotiff.github.io/rio-cogeo/
BSD 3-Clause "New" or "Revised" License
308 stars 42 forks source link

Add Progress Option #273

Closed SellersEvan closed 8 months ago

SellersEvan commented 9 months ago

I am working on a project that utilized rio-cogeo and we needed to be able to get the progress of a conversion. I thought other people might also have this issue. Basically, what this new feature allows you to do is set a TextIO output (like sys.stdout) to output the progress as a percentage to (and just the percentage). This would allow something else to read this TextIO to get the percentage that the conversion is at. This can be extremely useful to allow developers to check the progress of an update.

Let me know if you have any questions.

SellersEvan commented 9 months ago

@vincentsarago Does this look something the team would be interested in?

vincentsarago commented 9 months ago

sorry @SellersEvan I was busy on other projects.

To be honest the proposed solution might be a bit too complex at the moment, especially that you're calling 4 times updateProgress with the same percent.

would an option to overwrite fout https://github.com/cogeotiff/rio-cogeo/blob/f9ea9b9d8591672a2c38eb34981220c69e79fc9c/rio_cogeo/cogeo.py#L304 be possible?

vincentsarago commented 9 months ago

worth noting that the percentage here does not reflect the status of the COG translation but only the reading part

SellersEvan commented 9 months ago

@vincentsarago

I removed the code complexity from the last update and instead opted to override the fout like you suggested. This adds some complexity to using it because Click will only output the progress if the output file is interactive, like a terminal. This can be hacked however, by overriding the text buffers isatty method to always return true - this is documented in the API examples.

Thoughts?