NAME

WeBWorK::PG::IO - Functions used by WeBWorK::PG::Translator for file IO.

DESCRIPTION

This module defines several functions to be shared with a safe compartment by the PG translator. All exported methods are shared.

FUNCTIONS

includePGtext

This is used in processing some of the sample CAPA files and in creating aliases to redirect calls to duplicate problems so that they go to the original problem instead. It is called by includePGproblem.

Usage: includePGtext($str)

Note that the $str parameter may be a string or a reference to a string.

It reads and evaluates the string in the same way that the Translator evaluates the string in a PG file.

read_whole_problem_file

Read the contents of a pg file.

Usage: read_whole_problem_file($filePath)

Don't use for huge files. The file name will have .pg appended to it if it doesn't already end in .pg. This is used in importing additional .pg files as is done in the sample problems translated from CAPA. Returns a reference to a string containing the contents of the file.

read_whole_file

Read the contents of a file. Don't use for huge files.

Usage: read_whole_file($filePath)

fileFromPath

Usage: fileFromPath($path)

Returns the last segment of the path (i.e. the text after the last forward slash).

directoryFromPath

Usage: directoryFromPath($path)

Returns the initial segments of the of the path (i.e. the text up to the last forward slash).

createFile

Usage: createFile($fileName, $permission, $numgid)

Creates a file with the given name, permission bits, and group ID.

saveDataToFile

saveDataToFile($data, $filePath)

Saves $data to the file specified by $filePath. The $filePath may be an absolute path or may be specified relative to the html temporary directory specified in the PG environment. If the $filePath is not contained in the html temporary directory specified in the PG environment, then an exception is thrown and no file is written.

Nothing that is shared to the safe compartment should directly write to a file. Instead it should call this method to save data to a file.

createDirectory

Usage: createDirectory($dirName, $permission, $numgid)

Creates a directory with the given name, permission bits, and group ID.

remove_tree

Usage: remove_tree($dir)

Remove a directory and its contents.

pg_tmp_dir

Returns the temporary directory set in the WeBWorK::PG::Environment.

externalCommand

Usage: externalCommand($command)

Returns the path to a requested external command that is defined in the WeBWorK::PG::Environment.

AskSage

Usage: AskSage($python, $args)

Executes a sage cell server query via curl and returns the result.