fix crashes and add version option

This commit is contained in:
2023-05-25 15:09:37 +02:00
parent 54838c7d94
commit a0e7b459e1
2 changed files with 61 additions and 55 deletions

View File

@@ -26,6 +26,7 @@ allowedFiletypes = [ 'png', 'jpg' ];
def performChecks ( args, ap ): def performChecks ( args, ap ):
if ( args.details == None or args.details == '' ): if ( args.details == None or args.details == '' ):
if ( not args.printengines ): if ( not args.printengines ):
if ( not args.version ):
# Check if input and output file arguments are available # Check if input and output file arguments are available
if ( args.inputfile == None or args.inputfile == '' or args.outputfile == None or args.outputfile == '' ): if ( args.inputfile == None or args.inputfile == '' or args.outputfile == None or args.outputfile == '' ):
print( '\n\n ==> ERROR: Input and output file required! <==\n\n' ) print( '\n\n ==> ERROR: Input and output file required! <==\n\n' )
@@ -43,12 +44,13 @@ def performChecks ( args, ap ):
# check if engine argument is valid # check if engine argument is valid
try: try:
engineInfo[ args.engine ] engineInfo[ args.engine.lower() ]
except KeyError: except KeyError:
print( '\n==> ERROR: Engine not available. Ensure you have specified a valid engine' ) print( '\n==> ERROR: Engine not available. Ensure you have specified a valid engine' )
return False return False
# Check scalefactor argument and also verify that engine supports upscaling # Check scalefactor argument and also verify that engine supports upscaling
if ( args.scalefactor != None ):
if ( int( args.scalefactor ) > 4 and int( args.scalefactor ) < -4 ): if ( int( args.scalefactor ) > 4 and int( args.scalefactor ) < -4 ):
print( '\n==> ERROR: Invalid scale factor. Value has to be an integer between -4 and 4' ) print( '\n==> ERROR: Invalid scale factor. Value has to be an integer between -4 and 4' )
return False return False
@@ -58,6 +60,7 @@ def performChecks ( args, ap ):
return False return False
# Check sharpening argument and also verify that engine supports it # Check sharpening argument and also verify that engine supports it
if ( args.sharpening != None ):
if ( float( args.sharpening ) >= 1 and float( args.sharpening ) <= 0 ): if ( float( args.sharpening ) >= 1 and float( args.sharpening ) <= 0 ):
print( '\n==> ERROR: Invalid value for sharpening. Value has to be between 0 and 1' ) print( '\n==> ERROR: Invalid value for sharpening. Value has to be between 0 and 1' )
return False return False
@@ -67,7 +70,7 @@ def performChecks ( args, ap ):
return False return False
# check if scalefactor and / or sharpening is available # check if scalefactor and / or sharpening is available
if ( args.scalefactor == 0 and args.sharpening == 0 ): if ( ( args.scalefactor == 0 or args.scalefactor == None ) and ( args.sharpening == 0 or args.sharpening == None ) ):
print( '\n==> ERROR: Either scalefactor or sharpening argument required!' ) print( '\n==> ERROR: Either scalefactor or sharpening argument required!' )
return False return False
@@ -78,7 +81,7 @@ def performChecks ( args, ap ):
# Check if mode of engine is valid # Check if mode of engine is valid
try: try:
engineInfo[ args.engine ][ 'cliModeOptions' ][ args.mode ] engineInfo[ args.engine.lower() ][ 'cliModeOptions' ][ args.mode.lower() ]
except KeyError: except KeyError:
print( '\n==> ERROR: The specified mode is not supported by this engine. Options:' ) print( '\n==> ERROR: The specified mode is not supported by this engine. Options:' )
for option in engineInfo[ args.engine ][ 'cliModeOptions' ]: for option in engineInfo[ args.engine ][ 'cliModeOptions' ]:
@@ -86,13 +89,15 @@ def performChecks ( args, ap ):
return False return False
return True return True
else:
print( '\n\n==> You are running Version 1.1.0 of ImageVideoScaler-CLI <==\n' )
else: else:
print( '\n\n==> Available engines <==\n' ) print( '\n\n==> Available engines <==\n' )
for entry in engineList: for entry in engineList:
print( '--> ' + entry ) print( '--> ' + entry )
print( '\n\n' ) print( '\n\n' )
else: else:
print( '\n\n ==> INFOS about ' + engineInfo[ args.details ][ 'displayName' ] + '\n' ) print( '\n\n ==> INFOS about ' + engineInfo[ args.details.lower() ][ 'displayName' ] + '\n' )
print( ' --> Engine cli option is: ' + engineInfo[ args.details ][ 'abbr' ].lower() ) print( ' --> Engine cli option is: ' + engineInfo[ args.details ][ 'abbr' ].lower() )
print( ' --> CLI mode options are: ' ) print( ' --> CLI mode options are: ' )
for mode in engineInfo[ args.details ][ 'cliModeOptions' ]: for mode in engineInfo[ args.details ][ 'cliModeOptions' ]:
@@ -113,6 +118,7 @@ if __name__ == '__main__':
ap.add_argument( '-F', '--filetype', help='Change the file type of the temporary image files. Supports png, jpg. Video quality: png > jpg. PNG is default, if not specified.' ) ap.add_argument( '-F', '--filetype', help='Change the file type of the temporary image files. Supports png, jpg. Video quality: png > jpg. PNG is default, if not specified.' )
ap.add_argument( '-d', '--details', help='Get details on usage of a particular engine and exit. Reads the config.json file of that engine and displays it in a HR manner' ) ap.add_argument( '-d', '--details', help='Get details on usage of a particular engine and exit. Reads the config.json file of that engine and displays it in a HR manner' )
ap.add_argument( '-p', '--printengines', help='Print all engines and exit', action='store_true' ) ap.add_argument( '-p', '--printengines', help='Print all engines and exit', action='store_true' )
ap.add_argument( '-v', '--version', help='Print version and exit', action='store_true' )
ap.set_defaults( scaling = 0, sharpening = 0, threads = 4, engine = 'fsr', mode = 'fsr', filetype = 'png' ) ap.set_defaults( scaling = 0, sharpening = 0, threads = 4, engine = 'fsr', mode = 'fsr', filetype = 'png' )
args = ap.parse_args() args = ap.parse_args()