Skip to content

Commit be8a1e8

Browse files
author
Oren Cohen
committed
Use argparse.FileType to parse config file
1 parent ca5dff6 commit be8a1e8

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

tools/importer/importer.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@ def __call__(self, parser, namespace, values, option_string=None):
4444
setattr(namespace, self.dest, directory)
4545

4646

47-
class StoreValidFile(argparse.Action):
48-
def __call__(self, parser, namespace, values, option_string=None):
49-
fn = abspath(values)
50-
if not isfile(fn):
51-
raise argparse.ArgumentError(
52-
None, "The file %s does not exist!" % fn)
53-
setattr(namespace, self.dest, fn)
54-
55-
5647
class SetLogLevel(argparse.Action):
5748
def __call__(self, parser, namespace, values, option_string=None):
5849
logging.basicConfig(level=values)
@@ -261,7 +252,7 @@ def normalize_commit_sha(sha_lst):
261252
parser.add_argument('-c', '--config-file',
262253
help="Configuration file",
263254
required=True,
264-
action=StoreValidFile)
255+
type=argparse.FileType('r'))
265256

266257
if ROOT not in abspath(os.curdir):
267258
parser.error("This script must be run from the mbed-os directory "
@@ -274,8 +265,7 @@ def normalize_commit_sha(sha_lst):
274265
commit_msg = "[" + repo_dir + "]" + ": Updated to " + sha
275266

276267
# Read configuration data
277-
with open(args.config_file, 'r') as config:
278-
json_data = json.load(config)
268+
json_data = json.load(args.config_file)
279269

280270
'''
281271
Check if branch exists already, in case branch is present

0 commit comments

Comments
 (0)