Module Contents

class noc.lib.database_storage.DatabaseStorage(option)


Database File Storage (PostgreSQL) Stores files in database table. Table must have at least following columns:

File Name (Character Type) - contains full virtual path Binary Data (BYTEA) - File content Size (Integer Type) - File size (in octets) Modification Time (Timestamp) - Last modification time

Table name and field names must be set up via “option” variable. “option” is a hash with following keys:

db_table name_field data_field size field mtime_field
_open(self, name, mode='rb')

Internal implementation of the open()

  • name – Full path
  • mode – File mode (ignored)

File object or None

_save(self, name, content)
  • name – Full path
  • content – File object

File name

exists(self, name)

Check file exists :param name: Full path :return: True if file exists

path(self, name)

Returns full filesystem path as specified in Storage API. Raises NotImplementedError because Storage is not related to filesystem

size(self, name)

Get file size :param name: Full name :return: File size

url(self, name)
delete(self, name)

Deletes file :param name: Full path :return:

get_available_name(self, name)

Returns converted file name (Required by Storage API) :param name: :return:

listdir(self, name)

Returns a directory listing

Parameters:name – Full path of directory
Returns:List of file names
stat(self, name)

Get file stats. Stats is a hash of: * name - full path * size - file size * mtime - last modification time :param name: :return:

set_mtime(self, name, mtime)

Set file’s mtime :param name: :param mtime: :return: