Skip to content
This repository has been archived by the owner on Jan 16, 2020. It is now read-only.

Commit

Permalink
use an external python script instead of the ugly bash/python line
Browse files Browse the repository at this point in the history
  • Loading branch information
xgaia committed Dec 12, 2017
1 parent 948b198 commit 55004d4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
32 changes: 32 additions & 0 deletions config_updater.py
@@ -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()
4 changes: 2 additions & 2 deletions startAskomics.sh
Expand Up @@ -103,7 +103,7 @@ printenv | egrep "^ASKO_" | while read setting
do
key="askomics."$(echo $setting | egrep -o "^ASKO_[^=]+" | sed 's/^.\{5\}//g' | tr '[:upper:]' '[:lower:]')
value=$(echo $setting | egrep -o "=.*$" | sed 's/^=//g')
$python_ex -c "import configparser; config = configparser.ConfigParser(); config.read('"$config_path"'); config['app:main']['"$key"'] = '"$value"'; config.write(open('"$config_path"', 'w'))"
$python_ex config_updater.py -p $config_path -s "app:main" -k $key -v $value
done

# This take ASKOCONFIG_ env to update config in any sections
Expand All @@ -113,7 +113,7 @@ do
section=$(echo $sed_setting | egrep -o "^ASKOCONFIG_[^=]+" | sed 's/^.\{11\}//g' | cut -d "_" -f 1 | tr '[:upper:]' '[:lower:]')
key=$(echo $sed_setting | egrep -o "^ASKOCONFIG_[^=]+" | sed 's/^.\{11\}//g' | sed "s/$section\_//g" | tr '[:upper:]' '[:lower:]')
value=$(echo $sed_setting | egrep -o "=.*$" | sed 's/^=//g' | tr '[:upper:]' '[:lower:]')
$python_ex -c "import configparser; config = configparser.ConfigParser(); config.read('"$config_path"'); config.add_section('"$section"') if '"$section"' not in config.sections() else None; config['"$section"']['"$key"'] = '"$value"'; config.write(open('"$config_path"', 'w'))"
$python_ex config_updater.py -p $config_path -s $section -k $key -v $value
done

# Build Javascript ----------------------------------------
Expand Down

0 comments on commit 55004d4

Please sign in to comment.