The configuration module
Tools for keeping track of system settings.
The configuration module provides a system for managing the general,
reusable settings for the software—both a collection of default settings and
some user-specific settings—including default file locations, graph colors,
graph update delays, and so on. It keeps track of these data in memory and saves
them to (and initially reads them from) a file on the disk.
The module defines some classes for the above-mentioned purposes, and it creates
an actual instance of the Configuration class, so that other modules can
access the configuration without having to create a new instance and, therefore
without having to re-read the file from the hard drive.
Classes
Configuration
-
class src.core.configuration.Configuration[source]
The Configuration class is a container for system-wide settings
concerning appearance of certain components, default file locations, and
helpful ways for letting users know that an experiment is finished or that
serious system errors (e.g. magnet quenches) have occurred.
Methods
-
addUser(username)[source]
Create a new user.
-
getCarrier()[source]
Return the carrier of the active user.
Returns : | str :
The carrier of the active user, or an empty string if there is no
active user or no carrier associated with the active user.
|
-
getCarrierStrings()[source]
Return a list of strings representing mobile carrier names.
-
getDataFile(user=True)[source]
Return the default filename.
If a user is active and not overridden, return the user’s default
file name. Otherwise, return the system default data file name.
-
getDataFolder(user=True)[source]
Return the data folder.
If a user is active and not overridden, return the user’s default
data folder. Otherwise, return the system default data folder.
-
getExperimentFolder(user=True)[source]
Return the experiment folder.
If a user is active and not overridden, return the user’s default
experiment folder. Otherwise, return the system default experiment
folder.
-
getGraphColors()[source]
Return the list of graph colors (a list of RGB tuples).
-
getGraphDelay()[source]
Return the time between successive updates of plots.
-
getPhone()[source]
Return the phone number of the active user.
Returns : | str :
The phone number of the active user, or an empty string if there
is no active user.
|
-
getPrependScan(user=True)[source]
Return whether to prepend filenames with a scan number by default.
If a user is active and not overridden, return whether the user wants
to prepend a scan number by default. Otherwise, return whether the
system default is to prepend a scan number.
-
getSmsError()[source]
Return whether to text the active user on a system error.
-
getSmsFinished()[source]
Return whether to text the active user on experiment completion.
-
getUserName()[source]
Return the name of the active user.
Returns : | str :
The name of the active user, or ‘None’ if no user has been loaded.
|
-
getUserNames()[source]
Return a list of usernames as strings.
-
loadUser(username)[source]
Change the active user.
Parameters : | username : str
The username of the user whose data should be loaded. If ‘None’
or None is supplied, or if the specified user does not exist,
the default settings will be loaded.
|
-
removeUser(username)[source]
Delete a user.
-
setCarrier(newValue)[source]
Set the carrier of the active user, or do nothing if none.
-
setDataFile(newValue, user=True)[source]
Set the default filename.
If a user is active and not overridden, set the user’s default filename.
Otherwise, set the system default filename, which will be used whenever
no user is active and will be the default for new users.
-
setDataFolder(newValue, user=True)[source]
Set the default data folder.
If a user is active and not overridden, set the user’s default data
folder. Otherwise, set the system default data folder, which will be
used whenever no user is active and will be the default for new users.
-
setExperimentFolder(newValue, user=True)[source]
Set the default experiment file folder.
If a user is active and not overridden, set the user’s experiment file
folder. Otherwise, set the system default experiment folder, which will
be used whenever no user is active and will be the default for new
users.
-
setGraphColors(newValue)[source]
Set the colors (a list of RGB tuples) to use for plots.
-
setGraphDelay(newValue)[source]
Set the time between successive updates of plots.
-
setPhone(newValue)[source]
Set the phone number of the active user.
Parameters : | newValue : str
The new phone number for the active user. If there is no active
user, nothing will happen.
|
-
setPrependScan(newValue, user=True)[source]
Set whether to prepend filenames with a scan number by default.
If a user is active and not overridden, set whether the user wants
to prepend a scan number by default. Otherwise, return whether the
system default is to prepend a scan number.
-
setSmsError(newValue)[source]
Set whether to text the active user on a system error.
-
setSmsFinished(newValue)[source]
Set whether to text the active user on experiment completion.
-
setUserName(newValue)[source]
Rename the active user.
Parameters : | newValue : str
The new value for the name of the current user, if one has been
loaded. If no user is active, nothing will happen.
|
User
-
class src.core.configuration.User(name)[source]
A class to assist Configuration by storing per-user settings
Methods
-
getCarrier()[source]
Return the user’s phone carrier.
-
getDataFile()[source]
Return the default filename for the user’s data.
-
getDataFolder()[source]
Return the user’s default data folder.
-
getExperimentFolder()[source]
Return the user’s default experiment file folder.
-
getPhone()[source]
Return the user’s telephone number as a string.
-
getPrependScan()[source]
Return whether the user wants to prepend scan numbers by default.
-
getSmsError()[source]
Return whether to text the user on critical system errors.
-
getSmsFinished()[source]
Return whether to text the user on experiment completion.
-
getUserName()[source]
Return the user’s name.
-
setCarrier(newValue)[source]
Set the user’s phone carrier.
-
setDataFile(newValue)[source]
Set the default filename for the user’s data.
-
setDataFolder(newValue)[source]
Set the user’s default data folder.
-
setExperimentFolder(newValue)[source]
Set the user’s default experiment file folder.
-
setPhone(newValue)[source]
Set the user’s telephone number.
-
setPrependScan(newValue)[source]
Set whether the user wants to prepend scan numbers by default.
-
setSmsError(newValue)[source]
Set whether to text the user on critical system errors.
-
setSmsFinished(newValue)[source]
Set whether to text the user on experiment completion.
-
setUserName(newValue)[source]
Set the user’s name, changing the configuration file accordingly.
Functions
-
src.core.configuration.which(program)[source]
Return the path to a specified program, or None if the path doesn’t work.
Parameters : | program : str
|
Returns : | The input path `program` if it refers to a file which exists and can :
be accessed by the Python interpreter. Otherwise, None.
|
Notes
If program does not refer to an absolute path, it will be appended to
the elements in the system path, and if any of those work, the absolute
path formed thereby will be returned.
-
src.core.configuration.getEditors()[source]
Return a list of text file editors.
Returns : | list of str :
A list of text editors which exist in the filesystem and can be accessed
by this software.
|
-
src.core.configuration.openEditor(defaultText='')[source]
Open a temporary file in a text editor.