BitKinex scripting is a powerful way to extend the built-in functionality. The current version supports the Python programming language (please see the online tutorial for details on how to write Python scripts). Your scripts can perform additinal tasks during the standard request processing and/or to filter the files being handled by your request. BitKinex passes all request-relevant information on to the script allowing you to define rules based on the file specific attributes. Furthermore, the standard output (see the Python "print" command) is redirected to the request log file. You can use the Request Info Window to view the script output (if any) as well as any error messages produced by the Python interpreter.
The processing of a single request can be devided into several processing phases. Your script may contain methods which will be called by BitKinex during the respective phase:
|Phase Name||Method Name||Description|
|SCRIPT_PREPROCESS||OnPreprocess()||The method is called only once during the request startup.|
|SCRIPT_PREPROCESS_ELEM||OnPreprocessElem()||The method is called before a single file or directory is being processed.|
|SCRIPT_POSTROCESS_ELEM||OnPostprocessElem()||The method is called after each file or directory has been processed.|
|SCRIPT_POSTROCESS||OnPostprocess()||The method is called once after the request processing has been completed.|
All bitkinex-related variables and methods are exposed via the "bitkinex" namespace. BitKinex dynamically updates the objects of this namespace with respect to the current processing phase and/or file being processed.
This boolean variable is defined only in the SCRIPT_PREPROCESS phase. Its value indicates whether or not a particular file/directory will be processed. Your script can use (set/clear) this varible to implement an advanced request filter.
In the following example only files larger than one kilobyte will be processed:
if not bitkinex.file.isDir:
bitkinex.isValid = (bitkinex.file.size > 1024)
These variables are defined only in the SCRIPT_PREPROCESS phase. They contain the source and the destination (if applicable) paths of the directory being processed.
This object is defined only in the SCRIPT_PREPROCESS phase. The "file" instance stores attributes of the file being processed (name, time, size, isDir).
These variables are defined only in the SCRIPT_PREPROCESS phase. They contain the source and the destination (if applicable) names of the file being processed. When copying files, your script can change the "bitkinex.fileNameDst" variable ("bitkinex.fileName" is always read only).
These objects represent the source and destination data sources your request is operating on (the "dsDst" instance exists only if the request operates on two data sources - e.g. "copy" requests). The "ds" and "dsDst" instances are both of the same type. The data source class implements the following methods:
|store(dsSrc, pathSrc, pathDst)||copy the file(s) identified by the source path (pathSrc) from the source data source (dsSrc) to the destination location (pathDst)|
|remove(path)||delete the file(s) identified by the path|
|rename(pathSrc, pathDst)||rename/move the file identified by the source path to the destination path|
|mkdir(path)||create a new directory|
|list=readdir(dirName)||retrieve the content of a directory identified by dirName; the method returns a list of file objects (each file object has the following members: "name", "time", "size", "isDir")|
You can use these methods to perform additional tasks during the standard request processing.