Skip to content

Utility Methods

azcam.utils

azcam.console.utils contains general purpose support commands used throughout azcam.console.

add_searchfolder(search_folder='', include_subfolders=True)

Appends search_folder (and by default all its subfolders) to the current python search path. Default is current folder and its subfolders. Subfolders beginning with "_" are not included.

Parameters:

Name Type Description Default
search_folder str

Name of folder to add to sys.path

''
include_subfolders bool

True to include all subfolders in sys.path

True

check_keyboard(wait=False)

Checks keyboard for a key press. For Windows OS only.

Parameters:

Name Type Description Default
wait bool

True to wait until a key is pressed

False

Returns: key which was pressed or empty string.

curdir(folder='')

Gets and sets the working folder. If folder is not specified then just return the current working folder.

Parameters:

Name Type Description Default
folder str

name of folder set.

''

Returns: the current folder (after changing).

fix_path(path='', no_drive_letter=True)

Makes a nice absolute path, leaving only forward slashes.

Parameters:

Name Type Description Default
path str

name of path to cleanup.

''
no_drive_letter bool

Removes leading drive letter.

True

Returns: cleaned path name.

get_datafolder(datafolder=None)

Return the datafolder for this system. If not specified, root is /data on Windows or ~/data on Linux.

get_datatype(value)

Determine the data type for an object and set the type if possible. A string such as "1.23" will result in a type "float" and "2" will result in type "int".

Parameters:

Name Type Description Default
value any

object to be typed

required

Returns: list [type, value] of data type as a code and object with that type

make_image_filename(imagefile)

Returns the absolute file imagefile, with forward slashes. Appends ".fits" if no extension is included.

Parameters:

Name Type Description Default
imagefile str

image filename to be expanded

required

Returns: expanded image filename.

parse(string, set_type=False)

Parse a string into tokens using the standard azcam rules. If setType is true, try and set data data type for each token.

Parameters:

Name Type Description Default
string str

String to be parsed into tokens

required
set_type bool

True to try and set the type of each token ("1" to 1)

False

Returns: list of parsed tokens

prompt(prompt_message='Enter a string', default='')

Prints a message and waits for user input.

Parameters:

Name Type Description Default
prompt_message str

string to be printed

'Enter a string'
default any

string to be returned if no value is entered

''

Returns: string entered or default value

show_menu(configs)

Interative: Show a menu and wait for selection. "blank" may be used to display an empty line. print() is allowed here as this is for interactive use only.

Parameters:

Name Type Description Default
configs dict

Dictionary of strings which are menu items

required

Returns: string associated with item selected or empty string.