diff options
author | 2019-02-05 16:50:28 -0800 | |
---|---|---|
committer | 2019-02-05 16:50:28 -0800 | |
commit | 15c65c78e94f5da6615ae0eddaa552e65eddafdf (patch) | |
tree | 1fd862be03438569cc39164e30cedd40bf9f9b33 | |
parent | f0d554d1232e7c79c8fdf3aac9cdf753f808c91e (diff) | |
download | srtool-15c65c78e94f5da6615ae0eddaa552e65eddafdf.tar.gz srtool-15c65c78e94f5da6615ae0eddaa552e65eddafdf.tar.bz2 srtool-15c65c78e94f5da6615ae0eddaa552e65eddafdf.zip |
srtool_utils: add master app clone support
Update the master app tool to create new master apps.
Also, update the master app change feature to remove the previous
apps data source entries. Note that the existing users and products
are left untouched (to keep the database records working); such
such obsolete content must be removed manually or the data base
restarted clean.
Creation example, using 'yoyo' for the "Yoyodyne Corporation":
$ ./stop.sh
$ ./master_app create yoyo
$ ./start.sh
Switch bask to Yocto Project example:
$ ./stop.sh
$ ./master_app yp
$ ./start.sh
Signed-off-by: David Reyna <David.Reyna@windriver.com>
-rwxr-xr-x | bin/common/srtool_utils.py | 27 | ||||
-rwxr-xr-x | bin/dev_tools/master_app.sh | 114 |
2 files changed, 141 insertions, 0 deletions
diff --git a/bin/common/srtool_utils.py b/bin/common/srtool_utils.py index b48582dc..8c13f3a1 100755 --- a/bin/common/srtool_utils.py +++ b/bin/common/srtool_utils.py @@ -112,6 +112,30 @@ def settings(): ################################# +# remove_app_sources +# + +def remove_app_sources(master_app): + conn = sqlite3.connect(srtDbName) + cur = conn.cursor() + cur_write = conn.cursor() + + # Scan the SRTool Settings + cur.execute("SELECT * FROM orm_datasource") + + is_change = False + for setting in cur: + if master_app == setting[ORM.DATASOURCE_SOURCE]: + print("Deleting [%s] = '%s','%s'" % (setting[ORM.DATASOURCE_ID], setting[ORM.DATASOURCE_SOURCE], setting[ORM.SRTSETTING_VALUE])) + sql = 'DELETE FROM orm_datasource WHERE id=?' + cur_write.execute(sql, (setting[ORM.DATASOURCE_ID],)) + is_change = True + + if is_change: + conn.commit() + conn.close() + +################################# # fix_new_reserved # @@ -168,6 +192,7 @@ def main(argv): parser.add_argument('--sources', '-s', nargs='?', const='display', help='SRTool Sources') parser.add_argument('--reset-sources', '-r', action='store_const', const='reset_sources', dest='command', help='Reset SRTool Sources') parser.add_argument('--settings', '-S', action='store_const', const='settings', dest='command', help='Show the SRT Settings') + parser.add_argument('--remove-app-sources', dest='remove_app_sources', help='Remove data sources for a previous app') parser.add_argument('--force', '-f', action='store_true', dest='force', help='Force the update') parser.add_argument('--verbose', '-v', action='store_true', dest='verbose', help='Debugging: verbose output') @@ -203,6 +228,8 @@ def main(argv): settings() elif 'fix_new_reserved' == args.command: fix_new_reserved() + elif args.remove_app_sources: + remove_app_sources(args.remove_app_sources) else: print("Command not found") master_log.close() diff --git a/bin/dev_tools/master_app.sh b/bin/dev_tools/master_app.sh index 3de9c600..bf11d7f1 100755 --- a/bin/dev_tools/master_app.sh +++ b/bin/dev_tools/master_app.sh @@ -5,8 +5,117 @@ # (a) renaming the other master(s) datasource files # (b) enabling the master datasource file # +# Create the new master app by: +# (a) clone the ACME master bin/lib directories +# (b) replace ACME labels in those files and file names +# (c) set as the new master app +# + +##################### +# common routines +# + +srtErrorLog='srt_errors.txt' + +srt_error_log() +{ + echo "|$1|" >> $srtErrorLog +} + +##################### +# create_master +# + +# Clone and prepare the new app from the ACME sample app +create_master () +{ + if [ -z "$master_app" ] ; then + echo "ERROR: missing new master app name" + return 1 + fi + if [ -d "bin/$master_app" ] ; then + echo "ERROR: new master app directory already exists:<$master_app>" + return 1 + fi + + # Refactor app names + title_name="$(tr '[:lower:]' '[:upper:]' <<< ${master_app:0:1})${master_app:1}" + upper_name="$(tr '[:lower:]' '[:upper:]' <<< ${master_app})" + lower_name="$(tr '[:upper:]' '[:lower:]' <<< ${master_app})" + + # Trial create new master dir, also tests name format + mkdir -p bin/$lower_name + mkdir -p lib/$lower_name + if [ 0 -ne $? ] ; then + echo "ERROR: problem creating new master app directories:<*/$lower_name>" + exit 1 + fi + + # Copy over 'acme' directories + cp -r bin/acme/* bin/$lower_name + cp -r lib/acme/* lib/$lower_name + + # Refactor the files + find bin/$lower_name -exec $0 refactor $title_name $upper_name $lower_name {} \; 2> /dev/null + find lib/$lower_name -exec $0 refactor $title_name $upper_name $lower_name {} \; 2> /dev/null + + echo "=== New master app <$master_app> created! ===" + echo " bin/$master_app" + echo " lib/$master_app" +} + +# Refactor the app labels within the files and file names +refactor () +{ + title_name=$2 + upper_name=$3 + lower_name=$4 + file_acme=$5 + + # Leave the ACME png files alone as placeholders - they need to be manually re-created + if [ "$file_acme" != "${file_acme/\.png//}" ] ; then + return + fi + + # Rename the file + file_name="$(echo $file_acme | sed -e "s|acme|$lower_name|")" + if [ "$file_acme" != "$file_name" ] ; then + mv -f $file_acme $file_name + fi + + # Do not bother to refactor cache files + if [ "$file_acme" != "${file_acme/__pycache__//}" ] ; then + return + fi + + # Refactor the file + sed -i -e "s|Acme|$title_name|g" $file_name + sed -i -e "s|ACME|$upper_name|g" $file_name + sed -i -e "s|acme|$lower_name|g" $file_name +} + +##################### +# main() +# master_app=$1 + +# Creation support +if [ "create" = "$master_app" ] ; then + master_app=$2 + if [ 'yes' != $(echo "$master_app" | sed -e "s|^[a-z][a-z0-9]*$|yes|") ] ; then + echo "ERROR: master app name <$master_app> must start with letter and then only have letters and numbers, and be in lower case" + exit 1 + fi + echo "$(create_master $master_app)" + # continue to set as new master app ... +fi +if [ "refactor" = "$master_app" ] ; then + refactor $* + exit 0 +fi + +# Set master if [ -z "$master_app" ] ; then master_app="yp" fi @@ -29,9 +138,14 @@ for p in $(find bin -name srtool_env.sh -exec grep -l "SRT_MAIN_APP" {} \;) ; do else echo "DISABLE_MASTER:$p" mv -f $ds_dir/datasource.json $ds_dir/datasource.json_sample 2> /dev/null + # Remove old app's datasources + prev_app=$(basename $ds_dir) + bin/common/srtool_utils.py --remove-app-sources $prev_app fi done if [ "yp" = "$master_app" ] ; then echo "SET_MASTER:./bin/$master_app" +else + echo bin/common/srtool_utils.py --remove-app-sources yp fi |