<commit_before>#!/bin/bash

# requires inotify to alert that xml file has been created by the Magento webforms plugin and deposited in the correct directory
# which is set by incrontab command for the bitnami user

starttime=$(( `date +%s` ))
datenow=$(date -R)

# parse the command-line very stupidly

xmldirectoryname=$1 # this is different when run from the command line v. from incrontab!
xmlbasefile=$2 # this is different when run from the command line!
echo "parameter 1 is" $1
echo  "parameter 2 is" $2
xmlfilename=$xmldirectoryname/$xmlbasefile

environment=$(xmlstarlet sel -t -v "/item/environment" "$xmlfilename")

if [ "$environment" = "Production" ] ; then

        . /opt/bitnami/apache2/htdocs/pk-production/conf/config.txt
        echo "loaded prod config file at " $datenow | tee --append ~/how_I_started

elif [ "$environment" = "Staging" ] ; then
        . /opt/bitnami/apache2/htdocs/pk-staging/development/conf/config.txt
        echo "loaded Staging config file at " $datenow | tee --append ~/how_I_started

else

        . /opt/bitnami/apache2/htdocs/pk-new/development/conf/config.txt
        echo "loaded dev config file at " $datenow | tee --append ~/how_I_started

fi

uuid=$(python  -c 'import uuid; print uuid.uuid1()')
mkdir -m 755 $logdir$uuid 
xform_log=$logdir$uuid/"xform_log"
echo "XXXXXXXXXX" | tee --append $xform_log
echo "xmlfilename provided by webforms is" $xmlfilename | tee --append $xform_log
echo "xform_log is" $xform_log | tee --append $xform_log
echo "started xform at " $starttime " details in" $xform_log "at" $xform_log | tee --append $xform_log


sku=`tail -1 < "$LOCAL_DATA""SKUs/sku_list"`
echo "sku" $sku | tee --append $xform_log

# get bzr revision
bazaar_revision=`bzr revno`
echo "bazaar revision number in" "$environment" "is" $bazaar_revision | tee --append $xform_log

cd $scriptpath
echo "scriptpath is" $scriptpath 

export PATH=$PATH:/opt/bitnami/java/bin

echo "PATH is" $PATH | tee --append $xform_log


# use xmlstarlet to extract variable values that are common to all Magento forms
submissionid=$(xmlstarlet sel -t -v "/item/id" "$xmlfilename")
webform_id=$(xmlstarlet sel -t -v "/item/webform_id" "$xmlfilename")
customerid=$(xmlstarlet sel -t -v "/item/customer_id" "$xmlfilename")
customer_name=$(xmlstarlet sel -t -v "/item/customer_name" "$xmlfilename")
customer_email=$(xmlstarlet sel -t -v "/item/customer_email" "$xmlfilename")


# echo them back so I can see that they are the correct variable values

echo "webform_id was" $webform_id | tee --append $xform_log
echo "submissionid was" $submissionid | tee --append $xform_log
echo "customerid was " $customerid | tee --append $xform_log
echo "customername was" $customer_name | tee --append $xform_log
echo "customeremail was" $customer_email | tee --append $xform_log $sfb_log

# begin case loop that checks to see what form has been submitted and acts accordingly

case $webform_id in

4)

# echo "found Magento form submission id 4, executing ccc"

bin/ccc.sh --xmlfilename "$xmlbasefile" --passuuid "$uuid" --format "xml" --builder "no"

echo "launched ccc from" $environment 
;;

21) 

	echo "running create your robot form 21" | tee --append $xform_log
	robotname=$(xmlstarlet sel -t -v "/item/robotname" "$xmlfilename")
	robotresidence=$(xmlstarlet sel -t -v "/item/robotresidence" "$xmlfilename")
	robotbooktype=$(xmlstarlet sel -t -v "/item/robotbooktype" "$xmlfilename")
	robotcoverfont=$(xmlstarlet sel -t -v "/item/robotcoverfont" "$xmlfilename")
	robotcovercolor=$(xmlstarlet sel -t -v "/item/robotcovercolor" "$xmlfilename")
	robotbio=$(xmlstarlet sel -t -v "/item/robotbio" "$xmlfilename")
	robotrows=$(xmlstarlet sel -t -v "/item/robotrows" "$xmlfilename")
	robotlanguage=$(xmlstarlet sel -t -v "/item/robotlanguage" "$xmlfilename")<commit_msg>portability for xform.sh<commit_after>#!/bin/bash

# requires inotify to alert that xml file has been created by the Magento webforms plugin and deposited in the correct directory
# which is set by incrontab command for the bitnami user

starttime=$(( `date +%s` ))
datenow=$(date -R)

# parse the command-line very stupidly

xmldirectoryname=$1 # this is different when run from the command line v. from incrontab!
xmlbasefile=$2 # this is different when run from the command line!
echo "parameter 1 is" $1
echo  "parameter 2 is" $2
xmlfilename=$xmldirectoryname/$xmlbasefile

environment=$(xmlstarlet sel -t -v "/item/environment" "$xmlfilename")

if [ "$environment" = "Production" ] ; then

        . $confpath"config.txt"
        echo "loaded $environment config file at " $datenow 

elif [ "$environment" = "Staging" ] ; then
        . $confpath"config.txt"
        echo "loaded $environment config file at " $datenow 

else

        . $confpath"config.txt"
        echo "loaded $environment config file at " $datenow 
fi

uuid=$(python  -c 'import uuid; print uuid.uuid1()')
mkdir -m 755 $logdir$uuid 
xform_log=$logdir$uuid/"xform_log"
echo "XXXXXXXXXX" | tee --append $xform_log
echo "xmlfilename provided by webforms is" $xmlfilename | tee --append $xform_log
echo "xform_log is" $xform_log | tee --append $xform_log
echo "started xform at " $starttime " details in" $xform_log "at" $xform_log | tee --append $xform_log


sku=`tail -1 < "$LOCAL_DATA""SKUs/sku_list"`
echo "sku" $sku | tee --append $xform_log

echo "$0 version in $environment" "is" $SFB_VERSION | tee --append $xform_log

cd $scriptpath
echo "scriptpath is" $scriptpath 

export PATH=$PATH:/opt/bitnami/java/bin

echo "PATH is" $PATH | tee --append $xform_log


# use xmlstarlet to extract variable values that are common to all Magento forms
submissionid=$(xmlstarlet sel -t -v "/item/id" "$xmlfilename")
webform_id=$(xmlstarlet sel -t -v "/item/webform_id" "$xmlfilename")
customerid=$(xmlstarlet sel -t -v "/item/customer_id" "$xmlfilename")
customer_name=$(xmlstarlet sel -t -v "/item/customer_name" "$xmlfilename")
customer_email=$(xmlstarlet sel -t -v "/item/customer_email" "$xmlfilename")


# echo them back so I can see that they are the correct variable values

echo "webform_id was" $webform_id | tee --append $xform_log
echo "submissionid was" $submissionid | tee --append $xform_log
echo "customerid was " $customerid | tee --append $xform_log
echo "customername was" $customer_name | tee --append $xform_log
echo "customeremail was" $customer_email | tee --append $xform_log $sfb_log

# begin case loop that checks to see what form has been submitted and acts accordingly

case $webform_id in

4)

# echo "found Magento form submission id 4, executing ccc"

bin/ccc.sh --xmlfilename "$xmlbasefile" --passuuid "$uuid" --format "xml" --builder "no"

echo "launched $0 from" $environment 
;;

21) 

	echo "running create your robot form 21" | tee --append $xform_log
	robotname=$(xmlstarlet sel -t -v "/item/robotname" "$xmlfilename")
	robotresidence=$(xmlstarlet sel -t -v "/item/robotresidence" "$xmlfilename")
	robotbooktype=$(xmlstarlet sel -t -v "/item/robotbooktype" "$xmlfilename")
	robotcoverfont=$(xmlstarlet sel -t -v "/item/robotcoverfont" "$xmlfilename")
	robotcovercolor=$(xmlstarlet sel -t -v "/item/robotcovercolor" "$xmlfilename")
	robotbio=$(xmlstarlet sel -t -v "/item/robotbio" "$xmlfilename")
	robotrows=$(xmlstarlet sel -t -v "/item/robotrows" "$xmlfilename")
	robotlanguage=$(xmlstarlet sel -t -v "/item/robotlanguage" "$xmlfilename")
{'fraction_non_alphanumeric': 0.12735205890373602, 'fraction_numerical': 0.005317698391055358, 'mean_word_length': 4.482062780269058, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 80}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3786560', 'n_tokens_mistral': 2515, 'n_tokens_neox': 2423, 'n_words': 796}