![]() |
![]() |
![]() |
![]() |
Perhaps the single greatest opportunity for customization of Razor lies in the ability to attach shell scripts to run both before and after many of the actions. Scripts which run before Razor performs an action have the ability to veto the pending action by returning a non-zero exit code.
There are dozens of unique locations where scripts can be attached to the actions of the versions and threads operations. These extensions are enabled by editing the Actions file in the related Tables directory. Each line in the file represents a different button on the related interface to which scripts can be attached.
The following two tables show not only where scripts can be attached, but also what arguments will be passed to the scripts when they are executed.
Button | When | $1 | $2 | $3 | $4 | $5 |
---|---|---|---|---|---|---|
branch | Before | filename | orig version | |||
After | filename | new version | ||||
checkin.apply | Before | filename | orig version | fullpath | flag | |
After | filename | new version | dirname | flag | ||
checkout.apply | Before | filename | version | fullpath | ||
After | filename | version | dirname | |||
double_click1 | Before | filename | version | incl version2 | flag3 | |
After4 | ||||||
file_props.apply | Before | filename | version | |||
After | filename | version | ||||
introduce.apply | Before | filename | version (1.1) | fullpath | flag | bflg5 |
After | filename | version (1.1) | dirname | flag | ||
merge_checkin.apply6 | Before | filename | orig version | fullpath | ||
After | filename | new version | ||||
new_folder | Before | foldername | ||||
After | foldername | |||||
promote.apply | Before | filename | version | new state | ||
After | filename | version | new state | |||
readonly.apply7 | Before | filename | version | fullpath | ||
After | filename | version | dirname | |||
remove | Before | filename | ||||
After | filename | |||||
remove_folder | Before | folder | ||||
After | folder | |||||
rename | Before | filename | new name | |||
After | new name | orig name | ||||
terminate | Before | filename | version | |||
After | filename | version | ||||
uncheckout | Before | filename | orig version | button8 | ||
After | filename | version | dir | "N/A" | flag | ||
utilities.revert | Before | filename | orig version | |||
After | filename | new version |
In the tables above, the first argument supplied to the script is always the name of the file or thread itself. The second argument is the affected version number of the related file or thread. Note that in some cases, the before and after scripts will be provided different version numbers. Specifically, in the versions program, the checkin.apply before script is told the original version number, and the after script is told the version number of what the check-in effort produced.
The third and fourth arguments to the scripts are optional, and vary in purpose. In the above table, "fullpath" indicates that $3 is the full path name to where the file is coming from or going to. The term "dirname" is simply the directory part of "fullpath".
Both the introduce and check-in operations of the versions program provide the related after script a fourth argument. This flag indicates whether or not an imbedded operation took place, i.e.
0 - files were taken during the operation
1 - readonly copies of the files were left behind
2 - the files were immediately checked back out again
Note that for cases 1 and 2 above, the associated before and after scripts for the check-out readonly or check-out operation are also performed. For example, if someone introduced a file and arranged such that a readonly copy be left behind, the following sequence of scripts will be executed...
introduce.apply before script
readonly.apply before script1
readonly.apply after script
introduce.apply after script
For the uncheck-out operation, the attached scripts are passed the version number that the file would have gone to, if the edits had been completed by a check-in. Also note that the uncheck-out operation allows the user the option of leaving readonly copies of the files behind. If this is chosen, then the related readonly.apply scripts will be run, and the 3rd argument to the uncheck-out after script will have the directory the readonly copy was placed into (otherwise $3 would be "N/A").
In addition to the information available to the scripts via the command line, they are also provided a number of shell environment variables, as outlined below:
The <operation> part of the setting of RAZOR_ACTION is based on both which program was involved, and the action the user selected, as shown below...
Whether or not a before or after script takes advantage of all this information is a completely different story.
Let's look at a quick example to illustrate some of the above concepts. Suppose that the user dick was a junior engineer, and was not to be given the same level of trust or latitude as the rest of the engineers. Specifically, when checking out a file for edit, he must associate the activity with one or more issues in the database. The following script, when attached as a checkout.apply before action, will do the necessary screening.
#!/bin/sh if [ $USER = "dick" -a "$RAZOR_ISSUES" = "" ] ; then echo "Sorry Dick... Please associate this action " echo "with one or more issues from the Razor database." exit 1 else exit 0 fi
It should be remembered that if multiple files are being acted upon, the attached scripts will be executed for each file selected. In other words, if the user is checking out 3 files for edit in one operation, the related before and after scripts will be invoked 3 times each; once for each file. For example, if a user were checking out the three files "apple", "grape", and "peach", then (if attached) the following sequence would occur...
- run before.apply script for apple
<Razor would process apple, and update database>
run after.apply script for apple
- run before.apply script for grape
<Razor would process grape, and update database>
run after.apply script for grape
- run before.apply script for peach
<Razor would process peach, and update database>
run after.apply script for peach
This pattern of `run before script - do processing - run after script' holds true for all of the multi-file operations with one exception; introducing files. In this case, if we were introducing the files "barney", "fred", and "wilma", then the sequence would be...
As with the versions and threads programs, scripts can be attached to run both before and after edits are done to the issues database.
The same on-screen form is used for both the creation and modification of issue information. It's occasionally useful though to treat the two events differently. The arguments supplied to the scripts are shown in the following table.2
The filename points to a readonly copy of an ASCII file containing all of the information on the issue form. The file resides in RAZOR_TMP, and will have a name that is the concatenation of the issue number and the process id of the issues program itself. Please note that this file has been generated and provided to the scripts for information only. Any changes made to the file by the script are ignored.
The second argument provided to the issue_create.apply and issue_modify.apply scripts is a space separated list of e-mail addresses that will be notified. This list comes straight from the related state change in the Permissions file, and is again provided for the sake of completeness.
Also, as outlined in the table on page 239, scripts attached to buttons in the Razor program are provided a number of environment variables which give extra information.
As with scripts attached to buttons in the versions or threads programs, the before script has the ability to veto the pending razor operation by returning a non-zero return code. For example, if we wish to prevent the user `joe' from creating an issue with the Priority field set to High, we could attach the following script as the create.apply before action.
#!/bin/sh N=`egrep -c "ATTR.*Priority.*High" $1` if [ $N -gt 0 -a "$USER" = "joe" ] ; then echo "Sorry, but you're not allowed to set" echo "an issue to be high priority." exit 1 else exit 0 fi
If Joe were to try and create such an issue, the output from the script will be captured and shown to him.
![]() |
![]() |
![]() |
![]() |
(Part 9 of 13 for this section) (Generated 09/13/99 at 18:14:47) |
Copyright Tower Concepts http://www.tower.com Voice: 315-363-8000 Fax: 315-363-7488 support@tower.com sales@tower.com |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |