Dear Monks,
Thanks for the quick responses. :)
Now I understand that I am not clear. Please let me explain the problem in detail.
Also, I am sorry if this explaination goes a bit detail or lengthy.
Pictiorilly:
Installation Script <----> Perl Script(Automation Script) <---- Configuration File (storing question and their answers)
I have an installation script that installs a software on UNIX.
This script while in execution prompts for many (more than 200) questions and the user has to answer them.
All the questions are not asked in a linear/serial way such that, say if a question asks for: "which database to use?" (supported are Oracle, DB2, MySql), and if the user selects MySql, the questions that follow are different than those that would have been asked for Oracle DB selection.
In Programming's terms, it is like:
if (DB == 'ORACLE')
{
ask Oracle set of questions
}
else if (DB == 'MySql')
{
ask another set of questions related to MySql DB.
(These questions are different than those asked by Oracle's select
+ion)
}
Hence, in short, there are multiple code paths to follow, based upon the selection of database, OS (Linux, Solaris, AIX ...) and so on...
So, if I write the Perl automation script in a way that all the prompts (more than 200) are literally written to expect the prompts, my automation perl script would go beyond 5000 lines and would be cumbersome/hard to modify and maintain.
Also all the questions/prompts are not literal.
For example:
----------------------------------------------------------------------------
If I respond to a question:
What is the Unix username? [root]
as: "deepblue"
the following question(s) would have this "deepblue" into its text as:
What is the home directory for deepblue? [/users/deepblue]
------------------------------------------------------------
and if I send the response as "deepfritz"
the question would have "deepfritz" into it's text as:
What is the home directory for deepfritz? [/users/deepfritz]
----------------------------------------------------------------------------
So I cannot expect on literal strings here. This is another limitation that I cannot do a simple:
$object->Expect(<Some Text>);
in my Perl Automation script. Hence, I must do a Regular Expression matching.
So I thought of organising this whole perl automation program such that:
1. All the generic prompts/question are written into a single file like:
PROMPT 1 = DEFAULT_Answer1
PROMPT 2 = DEFAULT_Answer2
PROMPT 3 = DEFAULT_Answer3
PROMPT 4 = DEFAULT_Answer4
PROMPT 5 = DEFAULT_Answer5
By generic prompts I mean: The fixed text in a prompt/question.
2. The Perl automation script would read this file and load it into the memory.
3. Then this perl automation script would scan/extract the question using Expect's RegEx facility from the installer script using $object->Expect() and do a reqular expression matching with the PROMPTs loaded into memory and then send the corresponding DEFAULT_Answer to the installer script (invoked using $object->Spawn())
This would make the Perl script quite small and easy to understand, modify and maintain.
Also, all the data would be clubbed together into one place (in the Prompt's file) and the code in the Perl Automation script.
So, a pseudo code for the script would now look like:
--------------------------------------------------------------
Spawn(Install Script);
Load the PROMPT's file into memory;
while (Install Script does not complete execution) {
Read the questions from the install script;
Do a regular matching with the PROMPTs stored;
Send the corresponding ANSWER to the Install Script;
}
Instead of many consecutive prompts for each and every question like:
--------------------------------------------------------------
Spawn(Install Script);
Load the PROMPT's file into memory;
expect (Prompt 1);
send (Answer to Prompt 1);
...
...
if (expect (Prompt 100))
send (Answer to Prompt 100);
# And follow a different code path.
if (expect (Prompt 150))
send (Answer to Prompt 150);
# And follow a different code path.
expect (Prompt 200);
send (Answer to Prompt 5);
END;
--------------------------------------------------------------
Also, all the prompts are always in the last line of the multiple line text from the install script.
To summarise:
1. The prompts/questions are not literally/exactly the same always. Questions contain some variable text that is formed at runtime.
2. Expecting on literal strings would make the Perl Automation Script un-necessarily very lengthy, hard to understand, modify and maintain.
Does this make sense to all of the Monks there ?
If there is some other efficient way to handle this, suggestions are a great WELCOME!!!
Please help me in solving this.
Eagerly waiting for your replies... :)
Regards,
~DeepBlue
|