Browse Source

Error : input.png file doesn't exist #18

master
PommeDroid 3 years ago
parent
commit
12d29ff384
  1. 18
      argv.py
  2. 3
      main.py
  3. 9
      scripts/build.py
  4. 8
      scripts/setup.py
  5. 4
      utils.py

18
argv.py

@ -39,8 +39,13 @@ def check_args(args): @@ -39,8 +39,13 @@ def check_args(args):
if not os.path.isfile(args.input):
print("Error : {} file doesn't exist".format(
args.input), file=sys.stderr)
exit(1)
sys.exit(1)
def check_args_out():
if not args.output:
_, extension = os.path.splitext(args.input)
args.output = "output{}".format(extension)
check_args_out()
check_args_in()
@ -57,13 +62,12 @@ def run(): @@ -57,13 +62,12 @@ def run():
"-d", "--debug", action="store_true", help="enble log debug mod"
)
parser.add_argument(
"-i", "--input", default="input.png", help="path of the photo to transform"
"-i", "--input", help="path of the photo to transform", required=True
)
parser.add_argument(
"-o",
"--output",
default="output.png",
help="path where the transformed photo will be saved. (default: output.png or output.gif)",
help="path where the transformed photo will be saved. (default: output.<input extension>)",
)
processing_mod = parser.add_mutually_exclusive_group()
processing_mod.add_argument(
@ -200,6 +204,11 @@ def run(): @@ -200,6 +204,11 @@ def run():
parser.set_defaults(func=main)
gpu_info_parser.set_defaults(func=gpu_info.main)
# Show usage is no args is provided
if len(sys.argv) == 1:
parser.print_usage()
parser.exit()
args = parser.parse_args()
# Handle special cases for ignoring arguments in json file if provided in command line
@ -214,7 +223,6 @@ def run(): @@ -214,7 +223,6 @@ def run():
"--auto-resize-crop", "--auto-rescale", "--overlay"), l))
args = parser.parse_args(l + sys.argv[1:])
check_args(args)
set_config_args(args)
args.func(args)

3
main.py

@ -80,8 +80,7 @@ def simple_gif_processing(phases): @@ -80,8 +80,7 @@ def simple_gif_processing(phases):
:param phases: <ImageTransform[]> list of image transformation
:return: <SimpleGIFTransform> a gif process run ready
"""
return SimpleGIFTransform(conf.args['input'], phases,
conf.args['output'] if conf.args['output'] != "output.png" else "output.gif")
return SimpleGIFTransform(conf.args['input'], phases, conf.args['output'])
def multiple_gif_processing(phases, n):

9
scripts/build.py

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
import argparse
import importlib
from importlib import util
import logging
import os
import subprocess
@ -23,15 +24,15 @@ def check_dependencies(): @@ -23,15 +24,15 @@ def check_dependencies():
if c.get_os() == c.OS.UNKNOWN:
c.log.fatal("Unknown OS !")
exit(1)
sys.exit(1)
if c.get_python_version() < (3, 5):
c.log.fatal("Unsupported python version !")
exit(1)
sys.exit(1)
if not c.check_pyinstaller():
c.log.fatal("Pyinstaller is not install. It's a required dependency !")
exit(1)
sys.exit(1)
def cli_build(args, dist_path="./dist"):
@ -62,7 +63,7 @@ def cli_build(args, dist_path="./dist"): @@ -62,7 +63,7 @@ def cli_build(args, dist_path="./dist"):
r = subprocess.run(cmd)
if r.returncode != 0:
c.log.fatal("Cli build failed")
exit(1)
sys.exit(1)
c.log.info('Cli successfully built')

8
scripts/setup.py

@ -32,11 +32,11 @@ def check_dependencies(): @@ -32,11 +32,11 @@ def check_dependencies():
if c.get_os() == c.OS.UNKNOWN:
c.log.fatal("Unknown OS !")
exit(1)
sys.exit(1)
if c.get_python_version() < (3, 5):
c.log.fatal("Unsupported python version !")
exit(1)
sys.exit(1)
def pyinstaller(args, pip_commands_extend=None):
@ -47,7 +47,7 @@ def pyinstaller(args, pip_commands_extend=None): @@ -47,7 +47,7 @@ def pyinstaller(args, pip_commands_extend=None):
r = subprocess.run([sys.executable, '-m', 'pip', 'install', 'pyinstaller'] + pip_commands_extend)
if r.returncode != 0:
c.log.fatal("Pyinstaller installation failed")
exit(1)
sys.exit(1)
c.log.info('Pyinstaller successfully installed')
@ -88,7 +88,7 @@ def cli_setup(args, pip_commands_extend=None): @@ -88,7 +88,7 @@ def cli_setup(args, pip_commands_extend=None):
os.remove(path)
if r.returncode != 0:
c.log.fatal("Cli dependencies installation failed")
exit(1)
sys.exit(1)
c.log.info('Cli dependencies successfully installed')

4
utils.py

@ -24,7 +24,7 @@ def read_image(path): @@ -24,7 +24,7 @@ def read_image(path):
if image is None:
print("Error : {} file is not valid image".format(
path), file=sys.stderr)
exit(1)
sys.exit(1)
return image
@ -48,7 +48,7 @@ def check_shape(image, shape=(512, 512, 3)): @@ -48,7 +48,7 @@ def check_shape(image, shape=(512, 512, 3)):
if image.shape != shape:
print("Error : image is not 512 x 512, got shape: {}".format(
image.shape), file=sys.stderr)
exit(1)
sys.exit(1)

Loading…
Cancel
Save