Changed argument parsing to method.

master
Rostislav Lán 2 years ago
parent d92d35d16f
commit 907bfa3508

@ -12,27 +12,25 @@ import matplotlib.pyplot as plt
# Import custom image filter library # Import custom image filter library
import filters as flt import filters as flt
parser = ap.ArgumentParser(prog='main.py',
description='loads and stores image')
parser.add_argument("-i", "--input_file", help="Input file", required=True)
parser.add_argument("-o", "--output_file", help="Output file", required=True)
parser.add_argument('-d', "--dpi", type=int, required=True)
#parser.add_argument( '-s', '--size')
parser.add_argument('filters', type=str, nargs='*')
args = parser.parse_args()
class app: class app:
def __init__(self, input_file, output_file, dpi, filters): def __init__(self):
self.input_file = input_file self.parse_arguments()
self.output_file = output_file self.input_file = self.args.input_file
self.output_file = self.args.output_file
self.img = plt.imread(self.input_file) self.img = plt.imread(self.input_file)
self.dpi = dpi self.dpi = self.args.dpi
self.filters = filters self.filters = self.args.filters
self.apply_filters() self.apply_filters()
def parse_arguments(self):
parser = ap.ArgumentParser(prog='main.py', description='loads and stores image')
parser.add_argument("-i", "--input_file", help="Input file", required=True)
parser.add_argument("-o", "--output_file", help="Output file", required=True)
parser.add_argument('-d', "--dpi", type=int, required=True)
#parser.add_argument( '-s', '--size')
parser.add_argument('filters', type=str, nargs='*')
self.args = parser.parse_args()
def filter_factory(self, filter_name): def filter_factory(self, filter_name):
if filter_name == "average": if filter_name == "average":
return flt.filter_average return flt.filter_average
@ -53,5 +51,4 @@ class app:
# Save processed image # Save processed image
plt.savefig(self.output_file) plt.savefig(self.output_file)
app = app()
app = app(args.input_file, args.output_file, args.dpi, args.filters)

Loading…
Cancel
Save