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])[source]

Bases: object

A simple progress status iterator class.

x2go.utils.compare_versions(version_a, op, version_b)[source]

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

  • 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='', preferred_port=None)[source]

Detect an unused IP socket.

  • bind_address (str) – IP address to bind to (Default value = ‘’)
  • preferred_port (str) – IP socket port that shall be tried first for availability (Default value = None)

free local IP socket port that can be used for binding

Return type:


x2go.utils.find_session_line_in_x2golistsessions(session_name, stdout)[source]

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

  • session_name (str) – name of a session
  • stdout (list) – raw output from the ,,x2golistsessions’’ command, as list of strings

the output line that contains <session_name>

Return type:

str or None


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')[source]

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

  • 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’)

Get the geometry of the current screen’s desktop.

Returns:a (<width>, <height>) tuple will be returned
Return type:tuple

Detect systems default character encoding.

Returns:The system’s local character encoding.
Return type:str

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

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)[source]

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

  • depth_session (int) – color depth of the session
  • depth_local (int) – color depth of local screen

Does the session color depth work with the local display?

Return type:



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

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


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)[source]

Merge sort two sorted lists

  • l1 (list) – first sorted list
  • l2 (list) – second sorted list

the merge result of both sorted lists

Return type:


x2go.utils.patiently_remove_file(dirname, filename)[source]

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

  • dirname (str) – directory name the file is in
  • filename (str) – name of the file to be removed

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

Parameters:session_window (obj) – session window instance

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 L{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)[source]

Set title of session window.

  • session_window (obj) – session window instance
  • session_title (str) – session title to be set for session_window

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')[source]

Imitates the behaviour of the GNU/touch command.

  • filename (str) – name of the file to touch
  • mode (str) – the file mode (as used for Python file objects) (Default value = ‘a’)

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

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

Wrapper for: xprop -root _XKB_RULES_NAMES

Returns:A Python dictionary that contains the current X11 keyboard rules.
Return type:dict