Code Monkey home page Code Monkey logo

tarfile-progress-reporter's Introduction

tarfile Progress Extension

This module is a wrapper around the standard tarfile library in Python. It adds the ability to pass a progress callback to the following TarFile methods:

  • TarFile.add()
  • TarFile.addfile()
  • TarFile.extractall()
  • TarFile.extract()
  • TarFile.extractfile()

Each of those methods has a new progress argument. Any function passed to the progress argument will be called once per percentage increace, with a single integer value between 0 and 100.

This module is a drop-in replacement for the standard tarfile library, and should only require the import statments be changes.

Notes

When you use the TarFile.add() method your callback will receive a percentage complete for each file as it is added, rather than for the entire operation.

This means that when displaying information to users you need make it clear the the progress bar will fill up multiple times, once for each file added.

This also applies to the TarFile.extractall() method, if the input tar file is a stream. If the input tar file is a bog standard file then your callback will receive a percentage complete for the entire operation.

Examples

Replacing tarfile with tarfile_progress

Replace the following:

import tarfile

with

from tarfile_progress import tarfile_progress as tarfile

From the command line

This example uses the included example function, and is done from the command line.

>>> from tarfile_progress import tarfile_progress as tarfile
>>> tar = tarfile.open('test.tar', 'w')
>>> tar.add('monty', progress = tarfile.progressprint)
|##################################################| 100% File complete
>>> tar.extractall(tarfile.progressprint)
|##################################################| 100% File complete

Setting up a callback

This uses the included example function.

from tarfile_progress import tarfile_progress as tarfile

print 'Opening a new file'

# Open up a new tar file for writing
tar = tarfile.open('test.tar', 'w')

print 'Adding a new file'

# Add a new file to it, and pass it the progress callback
tar.add('monty', progress = tarfile.progressprint)

print 'Extracting files'

# Extract all the files, with progress
tar.extractall(progress = tarfile.progressprint)

This will result in the following output

Opening a new file
Adding a new file
|##################################################| 100% File complete
Extracting files
|##################################################| 100% File complete

tarfile-progress-reporter's People

Contributors

thomaspurchas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

tarfile-progress-reporter's Issues

Add license

Currently, there is no license specified with this project. The github ToS gives us the right to view and fork your repo, but aside from that things fall back to the Berne Convention, namely that you, as the author, are automatically assigned copyright (and haven't granted anyone else permission). That is, without an explicit license, legally the rest of us can do very little with your code, particularly in a corporate environment.

The good news is that since you're the only author, it's very easy for you to fix this - you can just assign a license now. If you don't already have one in mind, http://choosealicense.com/ and https://tldrlegal.com/ will probably be helpful in choosing one, and I would be glad to answer any questions that I can as well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.