stdin check with usage
This commit is contained in:
parent
a80c723a32
commit
95866bca81
|
@ -13,6 +13,7 @@ This is a list of tasks that would be cool to add.
|
||||||
- (x) Install script to system
|
- (x) Install script to system
|
||||||
Using update-alternatives is the most handy
|
Using update-alternatives is the most handy
|
||||||
- (x) Accept input from stdin when no file is given
|
- (x) Accept input from stdin when no file is given
|
||||||
|
- (x) Print error when no file and stdin is given
|
||||||
- ( ) Process only first N or last N Bytes
|
- ( ) Process only first N or last N Bytes
|
||||||
- ( ) Write a complete task for this stuff
|
- ( ) Write a complete task for this stuff
|
||||||
*** Networking
|
*** Networking
|
||||||
|
|
|
@ -4,6 +4,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import io
|
import io
|
||||||
import fcntl # only for non blocking IO, if you dont know what it is, you can ignore it or study up
|
import fcntl # only for non blocking IO, if you dont know what it is, you can ignore it or study up
|
||||||
|
import select # to check if the file has data
|
||||||
|
|
||||||
# 2**30 bytes aka 1 Mebibyte
|
# 2**30 bytes aka 1 Mebibyte
|
||||||
MAX_SIZE: int = 0x100000
|
MAX_SIZE: int = 0x100000
|
||||||
|
@ -69,6 +70,10 @@ def main():
|
||||||
# i read somewhere that file.readline() does not work like this, but as
|
# i read somewhere that file.readline() does not work like this, but as
|
||||||
# we are reading binary data anyways, I don't care.
|
# we are reading binary data anyways, I don't care.
|
||||||
# check if the file is readable
|
# check if the file is readable
|
||||||
|
if not select.select([file, ], [], [], 0.0)[0]:
|
||||||
|
print("no data from stdin, are you trying to dump a file?")
|
||||||
|
parser.print_usage()
|
||||||
|
sys.exit(1)
|
||||||
if not file.peek(1):
|
if not file.peek(1):
|
||||||
print("File is blocked, trying to wait...")
|
print("File is blocked, trying to wait...")
|
||||||
file = open(args.file, "rb")
|
file = open(args.file, "rb")
|
||||||
|
|
Loading…
Reference in New Issue