ChartDirector 7.0 (Python Edition)

BaseChart.makeTmpFile


Usage

makeTmpFile(dirname [, imageFormat [, lifeTime ]])

Description

Generates the chart as an image and save it to a temporary file, and automatically remove old files.

The makeTmpFile method creates the temporary file in the directory specified by dirname. To avoid building up of too many temporary files, it will automatically remove files older than a certain life time (default 600 seconds) in that directory.

Note that makeTmpFile expects dirname be a file system path, not a URL path. For example, the directory "/tmp/tmpcharts" means a directory at the root of the hard disk, not the root of the web document directory. Also, a relative path like "tmpcharts" or "../tmpcharts" is relative to the "current working directory" of the file system, which may not be the same as the "current script directory". It depends on the brand and configuration of the web server. To avoid uncertainties, it is not suggested to use relative paths.

It is not uncommon to use a temporary directory not under the web document directory. For these cases, the image files cannot be loaded directly using URLs. To load the images, ChartDirector includes a utility script "getchart.py" that can load temporary files created by makeTmpFile in any directories. In a typical usage, the code is like:

url = "getchart.py?img=/tmp/tmpcharts/" + c.makeTmpFile("/tmp/tmpcharts")

In the above, the makeTmpFile method creates the chart as a temporary file in the "/tmp/tmpcharts" directory, and returns the filename. The "getchart.py?img=[full_path_name]" is then used to load the file.

If makeTmpFile is unsuccessful, an empty string will be returned. In this case, please check that the temporary directory exists, and is readable and writable by the web server anonymous user.

It is highly recommended you use a dedicated directory for storing temporary files created by ChartDirector. This is to avoid makeTmpFile from accidentally removing old files belonging to other applications.

Arguments

ArgumentDefaultDescription
dirname(Mandatory)The directory to store the temporary file and to remove old files.
imageFormatPNGA constant representing the format of the image. Must be one of the predefined constants PNG, JPG, GIF, BMP, WMP, SVG, SVGZ or PDF.
lifeTime600The life time of files in seconds. Older files will be deleted. A negative value disables automatic temporary file removal.

Return Value

The temporary file name (not including the path), or an empty string in case of failure.