ART-python’s code library

DatabaseManager

class DatabaseManager.DbMan(credentials, dB)[source]

The dbMan class represents a single database accessed across a specific MySQL connector. It is initialised by passing a set of credentials for opening a connection to a MySQL server; these credentials are passed as a dictionary which defines the values for the ‘user’, ‘password’, ‘host’, ‘port’ and ‘database’ variables to be used to access an existing database on a MySQL server and the value of the ‘raise_on_warnings’ flag to be used over the connection to that database. The class supports new table, query and update functions which operate on the database, and ‘serverInfo’ and ‘close’ functions which operate on the connection. Work ongoing!

close()[source]
createTable(tableName, tableColumns)[source]
dropTable(table)[source]
listTables()[source]
queryTable(sqlCode)[source]
singleupdateTable(sqlCode, data)[source]
updateTable(sqlCode, data)[source]
class DatabaseManager.SvrMan(credentials)[source]

The SvrMan class represents a single server accessed across a specific MySQL connector. It is initialised by passing a set of credentials for opening a connection to a MySQL server; these credentials are passed as a dictionary which defines the values for the ‘user’, ‘password’, ‘host’, and ‘port’ variables to be used to access an existing database on a MySQL server and the value of the ‘raise_on_warnings’ flag to be used over the connection to that database. The class supports new table, query and update functions which operate on the database, and ‘serverInfo’ and ‘close’ functions which operate on the connection. Work ongoing!

..todo: Really DbmMan should ‘inherit from’ SvrMan. Need to work out how inheritance works in python.

close()[source]
createDatabase(dB)[source]
dropDatabase(dB)[source]
listDatabases()[source]
serverInfo()[source]
class DatabaseManager.table(content)[source]

A Table class object contains the column definitions of the table that it has been instantiated to represent. The column structure has to be provided as a tuple of tuples, each individual tuple being constituted of three strings that specify the column name, datatype and datatype again expressed as a % term (mostly %s)

A table object includes a createSQL() function which returns the SQL code to create the table, and insertSQL which returns the SQL code to insert

Parameters:content (tuple of tuples of strs) – Set of options to be presented to the user, defaults to (no default option)
createSQL()[source]
insertSQL()[source]

Helper Functions:

A set of utilities that might be useful for other programmes, including: cls() - clears the screen; menu(options, title, prompt) - presents the users with a menu of options and returns the user’s choice; underline(text) - returns the text it received as a string including underlining.

helper_functions.cls()[source]

cls() will clear the screen. Works in linux or windows

helper_functions.datetag()[source]
helper_functions.mainloop()[source]

Just a test routine that will present the user with a list of the days of the week for selection IF the module is run in its own right rather than being called from another module.

helper_functions.menu(options, title='Your options are:', prompt='Select an option by number: ')[source]

The menu function numbers and presents a set of options to the user, expects the user to select the number that equates to the option to be selected and returns that option.

Parameters:
  • options (tuple of str) – Set of options to be presented to the user, defaults to (no default option)
  • title (str) – The title that will appear at the top of the set of options, defaults to “Your options are:”
  • prompt (str) – The text that will appear at the bottom of the set of options prompting the user to make a selection, defaults to “Select an option by number: “
Returns:

option selected by user

Return type:

str

helper_functions.mysql_backup(sdb, shost, username, password)[source]
helper_functions.underline(text)[source]

Underlines text (with equals signs).

Parameters:text (str) – The text to be underlined
Returns:Single string made up of the supplied text, a carriage return and the appropriate number of equals signs.
Return type:str

Data:

A repository for data that drives other programmes.

data.dataBaseName()[source]

Provides a name for a new database derived from today’s date

Returns:Suggested database name.
Return type:str
data.entity(entityName)[source]

Provides the set of data identified by the entity name received. Entities currently available are: tables; servers; files; sql.

Parameters:entityName (str) – The name of the entity to be returned.
Returns:The data set identified by the entity name received.
Return type:dict