Skip to main content

Executes a cmd while interpreting its completion percentage.

The completion percentage of the cmd is stored in an attribute percentage and the user can obtain percentage increments by executing increment or by passing a callback when initializing.

This class is useful to use within a child thread, so the child thread executes the cmd, blocking and updating the increment and percentage to the parent thread, that can do other things in the meantime.

Examples

Badblocks

def my_callback(increment, total):
   print(f'Update: +{increment}% / {total}%.')

def child_thread():
  progress = ProgressiveCmd('badblocks', '-st', 'random', '-w', 'dev/sda1', digits=ProgressiveCmd.DECIMALS, decimal_digits=2, read=35, callback=my_callback)
  progress.run()

t = threading.Thread(target=child_thread)
t.start()

Shred

def my_callback(increment, total):
   print(f'Update: +{increment} / {total}%.')

def child_thread():
  progress = ProgressiveCmd('shred', '-vn 1', 'dev/sda1', callback=my_callback)
  progress.run()

t = threading.Thread(target=child_thread)
t.start()

fsarchiver

def my_callback(increment, total):
   print(f'Update: +{increment} / {total}%.')

def child_thread():
  progress = ProgressiveCmd('fsarchiver', 'restfs', '-v', 'foo/bar/', 'id=0,dest=dev/sda1', callback=my_callback)
  progress.run()

t = threading.Thread(target=child_thread)
t.start()

Using tqdm

You can use the increment value to update tqdm:

t = tqdm(total=100)

def my_callback(increment, total):
    t.update(increment)

def child_thread():
  progress = ProgressiveCmd('a-program', callback=my_callback)
  progress.run()

thread = threading.Thread(target=child_thread)
thread.start()

Testing

  1. git clone this project.

  2. Execute python setup.py test in the project folder.

Contributing

Is a missing or wrong code? Say it in the issues! Feel free to contribute.

Release files for progressive-cmd 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for progressive-cmd 0.1.1
File Size Uploaded
progressive-cmd-0.1.1.tar.gz 5.3 kB Details

Release files / progressive-cmd-0.1.1.tar.gz

Download URL progressive-cmd-0.1.1.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b6985bdc05eccce77406207a6a6d96eee5a17f1475fa65135f03d8d2a3a27ea6
BLAKE2b-256 checksum
How to use checksums
fa4ff62944fcef3083bde793eabd80662c531c17d541bda174d78f3e3c288ba7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.7

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page