Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract archive callback. #74

Closed
MiyamuraMiyako opened this issue Feb 15, 2020 · 12 comments
Closed

Extract archive callback. #74

MiyamuraMiyako opened this issue Feb 15, 2020 · 12 comments
Labels
enhancement New feature or request for extraction Issue on extraction, decompression or decryption help wanted Extra attention is needed
Milestone

Comments

@MiyamuraMiyako
Copy link

Is your feature request related to a problem? Please describe.
I need complute extract progress and process every file when one file extracted.

Describe the solution you'd like
Add callback param in extractall function.

Describe alternatives you've considered
None

Additional context
None

@miurahr miurahr added enhancement New feature or request for extraction Issue on extraction, decompression or decryption labels Feb 15, 2020
@miurahr miurahr added the help wanted Extra attention is needed label Feb 26, 2020
@miurahr

This comment has been minimized.

@MiyamuraMiyako
Copy link
Author

Yes, I think just report IsDirectory, FileName and PercentDone.

@miurahr

This comment has been minimized.

@MiyamuraMiyako
Copy link
Author

All extract thread concurrently submit maybe cause issue, I think need add synchronize lock, but maybe cause extract efficiency.

@github-actions
Copy link

github-actions bot commented Apr 6, 2020

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@miurahr
Copy link
Owner

miurahr commented May 22, 2020

@MiyamuraMiyako now #130 implement a primitive progress callback mechanism.
Could you try it? You can see how to use it on test_basic.py:446 test_extract_callback test case.

@miurahr
Copy link
Owner

miurahr commented May 22, 2020

Current API does not provide percentage, but provide filename and extracted bytes.
User can get list of filename, its property and file size from list() method, then API user can calculate a percentage, display whether it is a directory.

@MiyamuraMiyako
Copy link
Author

I tested this version, It can achieve I need.

@miurahr
Copy link
Owner

miurahr commented May 23, 2020

Now you can find a CLI option --verbose at #130 which produce such as

$ python -m py7zr x --verbose tests/data/test_1.7z 
- scripts                                                                  (0%)
- scripts/py7zr                                                           (15%)
- setup.cfg                                                               (23%)
- setup.py                                                               (100%)

You can find a sample code in py7zr/cli.py


class CliExtractCallback(py7zr.callbacks.ExtractCallback):

    def __init__(self, total_bytes, ofd=sys.stdout):
        self.ofd = ofd
        self.archive_total = total_bytes
        self.total_bytes = 0
        self.columns, _ = shutil.get_terminal_size(fallback=(80, 24))
        self.pwidth = 0

    def report_start(self, processing_file_path, processing_bytes):
        self.ofd.write('- {}'.format(processing_file_path))
        self.pwidth += len(processing_file_path) + 2

    def report_end(self, processing_file_path, wrote_bytes):
        self.total_bytes += int(wrote_bytes)
        plest = self.columns - self.pwidth
        progress = self.total_bytes / self.archive_total
        msg = '({:.0%})\n'.format(progress)
        if plest - len(msg) > 0:
            self.ofd.write(msg.rjust(plest))
        else:
            self.ofd.write(msg)
        self.pwidth = 0


if __name__ == "__main__":
    with py7zr.SevenZipFile('target.7z', 'r') as a:
        archive_info = a.archiveinfo()
        cb = CliExtractCallback(total_bytes=archive_info.uncompressed)
        a.extractall(callback=cb)

@miurahr
Copy link
Owner

miurahr commented May 23, 2020

v0.7.0b3 released with callback.

@miurahr miurahr modified the milestones: Encryption support, v0.7 May 24, 2020
@miurahr miurahr closed this as completed May 24, 2020
@miurahr miurahr pinned this issue Oct 28, 2020
@gmankab
Copy link

gmankab commented Mar 27, 2023

hello

please help me add file to archive, and printing callback in percents

@miurahr
Copy link
Owner

miurahr commented Mar 29, 2023

@gmankab please raise another ticket to request callback feature for archive/write functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request for extraction Issue on extraction, decompression or decryption help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants