stdin check with usage

This commit is contained in:
Christoph J. Scherr 2023-09-18 13:15:04 +02:00
parent a80c723a32
commit 95866bca81
2 changed files with 6 additions and 0 deletions

View File

@ -13,6 +13,7 @@ This is a list of tasks that would be cool to add.
- (x) Install script to system
Using update-alternatives is the most handy
- (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
- ( ) Write a complete task for this stuff
*** Networking

View File

@ -4,6 +4,7 @@ import os
import sys
import io
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
MAX_SIZE: int = 0x100000
@ -69,6 +70,10 @@ def main():
# i read somewhere that file.readline() does not work like this, but as
# we are reading binary data anyways, I don't care.
# 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):
print("File is blocked, trying to wait...")
file = open(args.file, "rb")