Infinityd.FilesystemStorage

g GObject.GInterface GObject.GInterface Infinityd.Storage Infinityd.Storage GObject.GInterface->Infinityd.Storage GObject.Object GObject.Object Infinityd.FilesystemStorage Infinityd.FilesystemStorage GObject.Object->Infinityd.FilesystemStorage Infinityd.Storage->Infinityd.FilesystemStorage

Subclasses:

None

Methods

Inherited:

GObject.Object (37), Infinityd.Storage (5)

Structs:

GObject.ObjectClass (5)

class

new (root_directory)

class

stream_close (file)

class

stream_read (file)

class

stream_write (file, buffer, len)

get_path (identifier, path)

open (identifier, path, mode)

write_xml_file (identifier, path, doc)

Virtual Methods

Inherited:

GObject.Object (7), Infinityd.Storage (5)

Properties

Name

Type

Flags

Short Description

root-directory

str

r/w/co

The directory in which the storage stores its content

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent

GObject.Object

r

Class Details

class Infinityd.FilesystemStorage(**kwargs)
Bases:

GObject.Object, Infinityd.Storage

Abstract:

No

Structure:

Infinityd.FilesystemStorageClass

classmethod new(root_directory)
Parameters:

root_directory (str) – A directory name in UTF-8.

Returns:

A new Infinityd.FilesystemStorage.

Return type:

Infinityd.FilesystemStorage

Creates a new Infinityd.FilesystemStorage that stores its nodes in the given directory on the file system. The directory is created if it does not exist.

classmethod stream_close(file)
Parameters:

file (object or None) – A #FILE opened with Infinityd.FilesystemStorage.open().

Returns:

The return value of fclose().

Return type:

int

This is a thin wrapper around fclose(). Use this function instead of fclose() if you have opened the file with Infinityd.FilesystemStorage.open(), to make sure that the same C runtime is closing the file that has opened it.

classmethod stream_read(file)
Parameters:

file (object or None) – A #FILE opened with Infinityd.FilesystemStorage.open().

Returns:

The return value of fread().

buffer:

A buffer into which to read data.

Return type:

(int, buffer: bytes)

This is a thin wrapper around fread(). Use this function instead of fread() if you have opened the file with Infinityd.FilesystemStorage.open(), to make sure that the same C runtime is closing the file that has opened it.

classmethod stream_write(file, buffer, len)
Parameters:
Returns:

The return value of fwrite().

Return type:

int

This is a thin wrapper around fwrite(). Use this function instead of fwrite() if you have opened the file with Infinityd.FilesystemStorage.open(), to make sure that the same C runtime is closing the file that has opened it.

get_path(identifier, path)
Parameters:
  • identifier (str) – The type of node to open.

  • path (str) – The path to open, in UTF-8.

Raises:

GLib.Error

Returns:

An absolute filename path to be freed with GLib.free(), or None.

Return type:

str or None

Returns the full file name to the given path within the storage’s root directory. The function might fail if path contains invalid characters. If the function fails, None is returned and error is set.

Only if identifier starts with “Inf”, the file will show up in the directory listing of Infinityd.Storage.read_subdirectory(). Other identifiers can be used to store custom data in the filesystem, linked to this Infinityd.FilesystemStorage object.

open(identifier, path, mode)
Parameters:
  • identifier (str) – The type of node to open.

  • path (str) – The path to open, in UTF-8.

  • mode (str) – Either “r” for reading or “w” for writing.

Raises:

GLib.Error

Returns:

A stream for the open file. Close with Infinityd.FilesystemStorage.stream_close().

full_path:

Return location of the full filename, or None.

Return type:

(object or None, full_path: str)

Opens a file in the given path within the storage’s root directory. If the file exists already, and mode is set to “w”, the file is overwritten.

If full_path is not None, then it will be set to a newly allocated string which contains the full name of the opened file, in the Glib file name encoding. Note that full_path will also be set if the function fails.

Only if identifier starts with “Inf”, the file will show up in the directory listing of Infinityd.Storage.read_subdirectory(). Other identifiers can be used to store custom data in the filesystem, linked to this Infinityd.FilesystemStorage object.

write_xml_file(identifier, path, doc)
Parameters:
  • identifier (str) – The type of node to write.

  • path (str) – The path to write to, in UTF-8.

  • doc (libxml2.DocPtr) – The XML document to write.

Raises:

GLib.Error

Returns:

True on success or False on error.

Return type:

bool

Writes the XML doument in doc into a file in the filesystem indicated by identifier and path. See Infinityd.FilesystemStorage.open() for how identifier and path should be interpreted.

Property Details

Infinityd.FilesystemStorage.props.root_directory
Name:

root-directory

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The directory in which the storage stores its content