Python libraries and code reusability
Python enables you to create libraries of commonly used functions within scripts. These libraries group common functions and can be used multiple times by many scripts. This section contains information about:
Create a Python script file which defines Python functions or objects. Copy the file to the <LanGuard main directory>\Library, example: C:\Program Files\GFI\LanGuard 12 Agent
Example library file
"""
Hello World Python library.
Copy this file to <LanGuard InstallDir>\Library.
"""
def EchoString(text):
"""Prints the given text."""
GlobalFunctions.echo(text)
print(text)
In order to use a previously created Python library, import that library using the standard Python import mechanism.
Example using the library above
"""
LibraryTester.py
Requires file EchoLibrary.py to be in directory <LanGuard InstallDir>\Library.
"""
def main():
"""Return values:
* 0 - false, failed
* 1 - true, success"""
result = 0
from EchoLibrary import EchoString
EchoString("Successfully run vulnerability check.")
result = 1
return(result)