# Python X2Go (Client) API Documentation (v0.6.1.4)

## x2go.utils module

Python X2Go helper functions, constants etc.

class x2go.utils.ProgressStatus(progress_event, progress_func=[0, 10, 20, 30, 40, 50, 60, 70, 80, 90])

  Bases: `object`

  A simple progress status iterator class.

x2go.utils.compare_versions(version_a, op, version_b)

  Compare <version_a> with <version_b> using operator <op>. In the background `distutils.version.LooseVersion` is used for the comparison operation.

  Parameters:

    - version_a (`str`) – a version string

    - op (`str`) – an operator provide as string (e.g. ‘<’, ‘>’, ‘==’, ‘>=’ etc.)

    - version_b (`str`) – another version string that is to be compared with <version_a>

x2go.utils.detect_unused_port(bind_address='127.0.0.1', preferred_port=None)

  Detect an unused IP socket.

  Parameters:

    - bind_address (`str`) – IP address to bind to (Default value = ‘127.0.0.1’)

    - preferred_port (`str`) – IP socket port that shall be tried first for availability (Default value = None)

  Returns:

    free local IP socket port that can be used for binding

  Return type:

    `str`

x2go.utils.find_session_line_in_x2golistsessions(session_name, stdout)

  Return the X2Go session meta information as returned by the `x2golistsessions` server command for session `session_name`.

  Parameters:

    - session_name (`str`) – name of a session

    - stdout (`list`) – raw output from the ,,x2golistsessions’’ command, as list of strings

  Returns:

    the output line that contains `<session_name>`

  Return type:

    `str` or `None`

x2go.utils.find_session_window(session_name)

  Find a session window by its X2GO session ID.

  Parameters:

    session_name (`str`) – session name/ID of an X2Go session window

  Returns:

    the window object (or ID) of the searched for session window

  Return type:

    `obj` on Unix, `int` on Windows

x2go.utils.genkeypair(local_username, client_address, key_type='RSA')

  Generate an SSH pub/priv key pair without writing the private key to file.

  Parameters:

    - local_username (`unicode`) – the key is for this user

    - client_address (`unicode`) – the key is only valid for this client

    - key_type (`unicode`) – either of: RSA, DSA (Default value = ‘RSA’)

x2go.utils.get_desktop_geometry()

  Get the geometry of the current screen’s desktop.

  Returns:

    a (<width>, <height>) tuple will be returned

  Return type:

    `tuple`

x2go.utils.get_encoding()

  Detect systems default character encoding.

  Returns:

    The system’s local character encoding.

  Return type:

    `str`

x2go.utils.get_workarea_geometry()

  Get the geometry of the current screen’s work area by wrapping around:

      xprop -root '_NET_WORKAREA'

  Returns:

    a (<width>, <height>) tuple will be returned

  Return type:

    `tuple`

x2go.utils.is_abs_path(path)

  Test if a given path is an absolute path name.

  Parameters:

    path (`str`) – test this path for absolutism…

  Returns:

    Returns `True` if path is an absolute path name

  Return type:

    `bool`

x2go.utils.is_color_depth_ok(depth_session, depth_local)

  Test if color depth of this session is compatible with the local screen’s color depth.

  Parameters:

    - depth_session (`int`) – color depth of the session

    - depth_local (`int`) – color depth of local screen

  Returns:

    Does the session color depth work with the local display?

  Return type:

    `bool`

x2go.utils.is_in_nx3packmethods(method)

  Test if a given compression method is valid for NX3 Proxy.

  Parameters:

    method (`str`) – name of an NXv3 pack method

  Returns:

    `True` if `method` is in the hard-coded list of NX3 compression methods.

  Return type:

    `bool`

x2go.utils.known_encodings()

  Render a list of all-known-to-Python character encodings (including all known aliases)

x2go.utils.local_color_depth()

  Detect the current local screen’s color depth.

  Returns:

    the local color depth in bits

  Return type:

    `int`

x2go.utils.merge_ordered_lists(l1, l2)

  Merge sort two sorted lists

  Parameters:

    - l1 (`list`) – first sorted list

    - l2 (`list`) – second sorted list

  Returns:

    the merge result of both sorted lists

  Return type:

    `list`

x2go.utils.patiently_remove_file(dirname, filename)

  Try to remove a file, wait for unlocking, remove it once removing is possible…

  Parameters:

    - dirname (`str`) – directory name the file is in

    - filename (`str`) – name of the file to be removed

x2go.utils.raise_session_window(session_window)

  Raise session window. Not functional for Unix-like operating systems.

  Parameters:

    session_window (`obj`) – session window instance

x2go.utils.session_names_by_timestamp(session_infos)

  Sorts session profile names by their timestamp (as used in the file format’s section name).

  Parameters:

    session_infos (`dict`) – a dictionary of session infos as reported by `X2GoClient.list_sessions()`

  Returns:

    a timestamp-sorted list of session names found in `session_infos`

  Return type:

    `list`

x2go.utils.set_session_window_title(session_window, session_title)

  Set title of session window.

  Parameters:

    - session_window (`obj`) – session window instance

    - session_title (`str`) – session title to be set for `session_window`

x2go.utils.slugify(value)

  Normalizes string, converts to lowercase, removes non-alpha characters, converts spaces to hyphens and replaces round brackets by pointed brackets.

  Parameters:

    value (`str`) – a string that shall be sluggified

  Returns:

    the sluggified string

  Return type:

    `str`

x2go.utils.touch_file(filename, mode='a')

  Imitates the behaviour of the GNU/touch command.

  Parameters:

    - filename (`str`) – name of the file to touch

    - mode (`str`) – the file mode (as used for Python file objects) (Default value = ‘a’)

x2go.utils.unique(seq)

  Imitates the behaviour of the GNU/uniq command.

  Parameters:

    seq (`list`) – a list/sequence containing consecutive duplicates.

  Returns:

    list that has been clean up from the consecutive duplicates

  Return type:

    `list`

x2go.utils.which(basename)

  Python equivalent to the shell command “which”.

  Parameters:

    basename (`str`) – the basename of an application to be search for in $PATH

  Returns:

    full path to the application

  Return type:

    `str`

x2go.utils.xkb_rules_names()

  Wrapper for: xprop -root _XKB_RULES_NAMES

  Returns:

    A Python dictionary that contains the current X11 keyboard rules.

  Return type:

    `dict`