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

module level tools, runnable from a CLI? #35

Closed
tbielawa opened this Issue Aug 15, 2014 · 2 comments

Comments

Projects
None yet
2 participants
@tbielawa
Copy link
Owner

tbielawa commented Aug 15, 2014

For reference, the json library has json.tool to handle input streams. You can run it on a shell prompt to pretty print json

curl http://something.json | python -m json.tool

Wondering if there's anything useful bitmath could do like this?

$ python -m bitmath.best 1024
KiB(1)

^ this would actually simplify my own personal frequent use case where I get a number in bytes printed in one shell,and I can't quite tell how big it is. Usually I'll just open another shell, import bitmath and then print out Byte(some_number).best_prefix().

@tbielawa tbielawa added this to the hack day milestone Aug 15, 2014

@ashcrow

This comment has been minimized.

Copy link
Contributor

ashcrow commented Aug 15, 2014

How about this?

$ bitmath -f MB -t GB 1000.23
1.00023
$ bitmath -f Byte 100000
976.5625 KiB
$ bitmath --help
usage: bitmath [-h] -f
                   {Bit,Byte,KiB,MiB,GiB,TiB,PiB,EiB,kB,MB,GB,TB,PB,EB,Kib,Mib,Gib,Tib,Pib,Eib,kb,Mb,Gb,Tb,Pb,Eb}
                   [-t {Bit,Byte,KiB,MiB,GiB,TiB,PiB,EiB,kB,MB,GB,TB,PB,EB,Kib,Mib,Gib,Tib,Pib,Eib,kb,Mb,Gb,Tb,Pb,Eb}]
                   size

Converts from one type of size to another.

positional arguments:
  size                  The number to convert.

optional arguments:
  -h, --help            show this help message and exit
  -f {Bit,Byte,KiB,MiB,GiB,TiB,PiB,EiB,kB,MB,GB,TB,PB,EB,Kib,Mib,Gib,Tib,Pib,Eib,kb,Mb,Gb,Tb,Pb,Eb}, --from {Bit,Byte,KiB,MiB,GiB,TiB,PiB,EiB,kB,MB,GB,TB,PB,EB,Kib,Mib,Gib,Tib,Pib,Eib,kb,Mb,Gb,Tb,Pb,Eb}
                        Input type you are converting from.
  -t {Bit,Byte,KiB,MiB,GiB,TiB,PiB,EiB,kB,MB,GB,TB,PB,EB,Kib,Mib,Gib,Tib,Pib,Eib,kb,Mb,Gb,Tb,Pb,Eb}, --to {Bit,Byte,KiB,MiB,GiB,TiB,PiB,EiB,kB,MB,GB,TB,PB,EB,Kib,Mib,Gib,Tib,Pib,Eib,kb,Mb,Gb,Tb,Pb,Eb}
                        Input type you are converting to. Attempts to sense
                        best result if omitted.
@tbielawa

This comment has been minimized.

Copy link
Owner

tbielawa commented Aug 15, 2014

From IRC:

@tbielawa | 99%
@tbielawa | if Byte were the default for -f it'd be 100%
ashcrow | k
@tbielawa | so that 'bitmath 1024' would return 1 KiB
@tbielawa | that'd be so amazeballs
ashcrow | $ bitmath 1024
ashcrow | 1.0 KiB
@tbielawa | osnap
ashcrow | tbielawa: almost done
ashcrow | then I'll pull request it

@tbielawa tbielawa closed this in c5e4e3c Aug 15, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment