Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Error handling for circular references (#36)
Browse files Browse the repository at this point in the history
- error handling for:
  - circular references;
  - use of non-supported languages;
- some modularity.
  • Loading branch information
bertilhatt authored and Mte90 committed Oct 16, 2018
1 parent e193886 commit a8e422f
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions manageterms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,32 @@
import argparse, os.path
from utils.data_handlers import open_typo_file, save_typo_data

# Parse argument
parser = argparse.ArgumentParser(description='add new terms!')

parser.add_argument('-wrong', dest="wrong", type=str, required=True)
parser.add_argument('-right', dest="right", type=str, required=True)
parser.add_argument('-lang', dest="lang", type=str, required=True)
args = parser.parse_args()

script_path = os.path.dirname(os.path.realpath(__file__))
lang_path = script_path + '/words/' + args.lang + '.json'
def parse_argument(_parser_):
_parser_.add_argument('-wrong', dest="wrong", type=str, required=True)
_parser_.add_argument('-right', dest="right", type=str, required=True)
_parser_.add_argument('-lang', dest="lang", type=str, required=True)
args = _parser_.parse_args()
return args


def store_new_argument(_args_):
try:
lang_path = script_path + '/words/' + _args_.lang + '.json'
typo_data = open_typo_file(lang_path)
typo_data[args.right].add(_args_.wrong)
save_typo_data(lang_path, typo_data)
except FileNotFoundError:
raise ValueError('SyntaxAlert only supports en, es, fr, it at the moment.')

typo_data = open_typo_file(lang_path)
typo_data[args.right].add(args.wrong)
# Parse argument
parser = argparse.ArgumentParser(description='add new terms!')

save_typo_data(lang_path, typo_data)
# Check argument is not circular
if args.right == args.wrong:
raise ValueError('You can’t replace a word with itself. It will create a loop.')
else:
# Store argument
script_path = os.path.dirname(os.path.realpath(__file__))
store_new_argument(args)

0 comments on commit a8e422f

Please sign in to comment.