mirror of https://github.com/ARMmbed/mbed-os.git
Use argparse.FileType to parse config file
parent
ca5dff69f5
commit
be8a1e804f
|
@ -44,15 +44,6 @@ class StoreDir(argparse.Action):
|
||||||
setattr(namespace, self.dest, directory)
|
setattr(namespace, self.dest, directory)
|
||||||
|
|
||||||
|
|
||||||
class StoreValidFile(argparse.Action):
|
|
||||||
def __call__(self, parser, namespace, values, option_string=None):
|
|
||||||
fn = abspath(values)
|
|
||||||
if not isfile(fn):
|
|
||||||
raise argparse.ArgumentError(
|
|
||||||
None, "The file %s does not exist!" % fn)
|
|
||||||
setattr(namespace, self.dest, fn)
|
|
||||||
|
|
||||||
|
|
||||||
class SetLogLevel(argparse.Action):
|
class SetLogLevel(argparse.Action):
|
||||||
def __call__(self, parser, namespace, values, option_string=None):
|
def __call__(self, parser, namespace, values, option_string=None):
|
||||||
logging.basicConfig(level=values)
|
logging.basicConfig(level=values)
|
||||||
|
@ -261,7 +252,7 @@ if __name__ == "__main__":
|
||||||
parser.add_argument('-c', '--config-file',
|
parser.add_argument('-c', '--config-file',
|
||||||
help="Configuration file",
|
help="Configuration file",
|
||||||
required=True,
|
required=True,
|
||||||
action=StoreValidFile)
|
type=argparse.FileType('r'))
|
||||||
|
|
||||||
if ROOT not in abspath(os.curdir):
|
if ROOT not in abspath(os.curdir):
|
||||||
parser.error("This script must be run from the mbed-os directory "
|
parser.error("This script must be run from the mbed-os directory "
|
||||||
|
@ -274,8 +265,7 @@ if __name__ == "__main__":
|
||||||
commit_msg = "[" + repo_dir + "]" + ": Updated to " + sha
|
commit_msg = "[" + repo_dir + "]" + ": Updated to " + sha
|
||||||
|
|
||||||
# Read configuration data
|
# Read configuration data
|
||||||
with open(args.config_file, 'r') as config:
|
json_data = json.load(args.config_file)
|
||||||
json_data = json.load(config)
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Check if branch exists already, in case branch is present
|
Check if branch exists already, in case branch is present
|
||||||
|
|
Loading…
Reference in New Issue