Difference between revisions of "Logical tests"

From WPKG | Open Source Software Deployment and Distribution
Jump to: navigation, search
m (Other examples)
m (Other examples)
Line 20: Line 20:
 
= Other examples =
 
= Other examples =
  
 +
== two alternative entries in "Software Add/Remove" ==
 
Firefox can have a different entry in "Software Add/Remove":
 
Firefox can have a different entry in "Software Add/Remove":
 
* if version 2.0 was installed first, and then updated to 2.0.0.2, version shown will be still 2.0
 
* if version 2.0 was installed first, and then updated to 2.0.0.2, version shown will be still 2.0
Line 29: Line 30:
 
  </check>
 
  </check>
  
 +
== checking for a non existing file ==
 +
Sometimes, it might be useful to use WPKG to actually remove the things (i.e., some addon/ads installed by the PC vendor).
 +
 +
We only want to run the script/program only if the files are still on the drive.
 +
 +
<pre>
 +
<check type='logical' condition='not' >
 +
  <check type='file' condition='exists' path='c:\foo\bar' />
 +
</check>
 +
</pre>
  
 
[[category:Documentation]]
 
[[category:Documentation]]

Revision as of 11:52, 24 September 2007

Logical tests feature (implemented in WPKG 0.9.6) allows nested checks:

<check type="logical" condition="or">
 <check type="file" condition="exists" path="c:\fileA"/>
 <check type="file" condition="exists" path="c:\fileB"/>
</check> 

I.e. the outer check will return 'true' if either c:\fileA or c:\fileB exist. Nests within nests are acceptable.

New tests which have been added:

  • not - returns the inverse of the nested check. Fails with an error if the number of nested checks is not one.
  • and - returns the logical 'and' of all the nested checks. (See note below about lazy execution.)
  • or - returns the logical 'or' of all the nested checks. (See note below about lazy execution.)
  • atleast - returns true if at least value of the nested checks are true. (See note below about lazy execution.)
  • atmost - returns true if no more than value of the nested checks are true. (See note below about lazy execution.)

N.B - this test uses 'lazy execution' meaning that if the logical condition is already determined by one of the sub-checks, the other sub-checks will not be performed. For example, we might want to check that c:\Program Files\Application exists and that c:\Program Files\Application\App.exe also exists. If a test finds that the directory doesn't exist, there's no way that the result of the logical 'and' can be true so it returns false immediately. In the above example (c:\fileA, c:\fileB), if c:\fileA exists no test is performed for c:\fileB. Likewise, if an 'at least' test requires four of eight tests to pass, the routine returns 'true' as soon as it finds a fourth true check whether or not it has attempted all of them.

Other examples

two alternative entries in "Software Add/Remove"

Firefox can have a different entry in "Software Add/Remove":

  • if version 2.0 was installed first, and then updated to 2.0.0.2, version shown will be still 2.0
  • if version 2.0.0.2 was installed first, version shown will be 2.0.0.2
<check type="logical" condition="or">
  <check type="uninstall" condition="exists" path="Mozilla Firefox (2.0)" />
  <check type="uninstall" condition="exists" path="Mozilla Firefox (2.0.0.2)" />
</check>

checking for a non existing file

Sometimes, it might be useful to use WPKG to actually remove the things (i.e., some addon/ads installed by the PC vendor).

We only want to run the script/program only if the files are still on the drive.

<check type='logical' condition='not' >
   <check type='file' condition='exists' path='c:\foo\bar' />
</check>