Skip to content

simplify code in utility/parseArguments #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 22 additions & 43 deletions pcloudcv/utility/parseArguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,29 @@ def getParams(self):
def readConfigFile(self, file):
data_file = open(file, 'r').read()
complete_data = json.loads(data_file)
self.data = complete_data['config']
self.exec_name = complete_data['exec']
self.maxim = int(complete_data['maxim'])
self.data = complete_data.get('config')
self.maxim = int(complete_data.get('maxim'))
return complete_data

def writeToConfigFile(self, file):
data_file = open(file, 'w')
json.dump(self.complete_data, data_file)

def parseArguments(self, arg, file):
sourcepath = None
resultpath = None
name = None

def parseArguments(self, arg, config_file):
i = 0

if 'input' in arg:
sourcepath = arg['input']
if 'output' in arg:
resultpath = arg['output']
if 'exec' in arg:
name = arg['exec']
sourcepath = arg.get('input')
resultpath = arg.get('output')
name = arg.get('exec')

try:
self.readConfigFile(file)
config_dict = self.readConfigFile(config_file)

if name is not None:
self.exec_name = name
elif self.exec_name is None:
# exec param is not mentioned in config.json and config dictionary
if arg.get('exec') is None and config_dict.get('exec') is None:
raise ArgumentError(0)
elif name is None and self.exec_name is not None:
name = self.exec_name

if arg.get('exec') is None and config_dict.get('exec') is not None:
name = config_dict.get('exec')

self.changePath()

Expand All @@ -80,31 +72,18 @@ def parseArguments(self, arg, file):
log('W', str(e))

def changeSourcePath(self, path, execname):
try:
for d in self.data:
if d["name"] == execname:
d["path"] = path
self.source_path = path
return
raise ArgumentError(0)
for d in self.data:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we require a try-catch here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a try catch in parseArguments. from where its called.

if d["name"] == execname:
d["path"] = path
self.source_path = path

except ArgumentError as e:
log('W', str(e))
raise SystemExit

def changeOutputPath(self, path, execname):
try:
for d in self.data:
if d["name"] == execname:
d["output"] = path
self.output_path = path
return

raise ArgumentError(0)

except ArgumentError as e:
log('W', str(e))
raise SystemExit
for d in self.data:
if d["name"] == execname:
d["output"] = path
self.output_path = path
return

def verify(self):
if self.exec_name == ' ':
Expand Down