This repository has been archived by the owner on Jan 16, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use an external python script instead of the ugly bash/python line
- Loading branch information
Showing
2 changed files
with
34 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import argparse | ||
import configparser | ||
|
||
|
||
def main(): | ||
"""Update ini entry of a config file""" | ||
|
||
parser = argparse.ArgumentParser(description='Update AskOmics config file') | ||
|
||
parser.add_argument('-p', '--path', type=str, help='Path to config file', required=True) | ||
parser.add_argument('-s', '--section', type=str, help='Section to add/update', required=True) | ||
parser.add_argument('-k', '--key', type=str, help='Key to add into the section', required=True) | ||
parser.add_argument('-v', '--value', type=str, help='Value of the key', required=True) | ||
|
||
args = parser.parse_args() | ||
|
||
path = args.path | ||
section = args.section | ||
key = args.key | ||
value = args.value | ||
|
||
config = configparser.ConfigParser() | ||
config.read(path) | ||
|
||
if section not in config.sections(): | ||
config.add_section(section) | ||
|
||
config[section][key] = value | ||
config.write(open(path, 'w')) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters