Package x2go :: Module utils

[frames] | no frames]

# Module utils

source code

Python X2Go helper functions, constants etc.

Classes
| ProgressStatus A simple progress status iterator class.

Functions

`bool`

is_in_nx3packmethods(method) Test if a given compression method is valid for NX3 Proxy. | source code

`str` or `None`

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`. | source code

`str`

slugify(value) Normalizes string, converts to lowercase, removes non-alpha characters, converts spaces to hyphens and replaces round brackets by pointed brackets. | source code

`list`

session_names_by_timestamp(session_infos) Sorts session profile names by their timestamp (as used in the file format's section name). | source code

touch_file(filename, mode=`'``a``'`) Imitates the behaviour of the GNU/touch command. | source code

`list`

unique(seq) Imitates the behaviour of the GNU/uniq command. | source code

known_encodings() Render a list of all-known-to-Python character encodings (including all known aliases) | source code

patiently_remove_file(dirname, filename) Try to remove a file, wait for unlocking, remove it once removing is possible... | source code

`str`

detect_unused_port(bind_address=`'``127.0.0.1``'`, preferred_port=None) Detect an unused IP socket. | source code

`str`

get_encoding() Detect systems default character encoding. | source code

`bool`

is_abs_path(path) Test if a given path is an absolute path name. | source code

`dict`

xkb_rules_names() Wrapper for: xprop -root _XKB_RULES_NAMES | source code

`int`

local_color_depth() Detect the current local screen's color depth. | source code

`bool`

is_color_depth_ok(depth_session, depth_local) Test if color depth of this session is compatible with the local screen's color depth. | source code

`obj` on Unix, `int` on Windows

find_session_window(session_name) Find a session window by its X2GO session ID. | source code

`tuple`

get_desktop_geometry() Get the geometry of the current screen's desktop. | source code

`tuple`

get_workarea_geometry() Get the geometry of the current screen's work area by wrapping around: | source code

set_session_window_title(session_window, session_title) Set title of session window. | source code

raise_session_window(session_window) Raise session window. | source code

`list`

merge_ordered_lists(l1, l2) Merge sort two sorted lists | source code

compare_versions(version_a, op, version_b) Compare <version_a> with <version_b> using operator <op>. | source code

genkeypair(local_username, client_address, key_type=`'``RSA``'`) Generate an SSH pub/priv key pair without writing the private key to file. | source code

`str`

which(basename) Python equivalent to the shell command "which". | source code

Variables
| __NAME__ = ``'``x2goutils-pylib``'``
| __package__ = ``'``x2go``'``

Function Details

### is_in_nx3packmethods(method)

source code

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

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

### find_session_line_in_x2golistsessions(session_name, stdout)

source code

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: `str` or `None`
  the output line that contains `<session_name>`

### slugify(value)

source code

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: `str`
  the sluggified string

### session_names_by_timestamp(session_infos)

source code

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: `list`
  a timestamp-sorted list of session names found in `session_infos`

### touch_file(filename, mode=`'``a``'`)

source code

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)

### unique(seq)

source code

Imitates the behaviour of the GNU/uniq command.

Parameters:
  - `seq` (`list`) - a list/sequence containing consecutive duplicates.
Returns: `list`
  list that has been clean up from the consecutive duplicates

### patiently_remove_file(dirname, filename)

source code

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

### detect_unused_port(bind_address=`'``127.0.0.1``'`, preferred_port=None)

source code

Detect an unused IP socket.

Parameters:
  - `bind_address` (`str`) - IP address to bind to
  - `preferred_port` (`str`) - IP socket port that shall be tried first for availability
Returns: `str`
  free local IP socket port that can be used for binding

### get_encoding()

source code

Detect systems default character encoding.

Returns: `str`
  The system's local character encoding.

### is_abs_path(path)

source code

Test if a given path is an absolute path name.

Parameters:
  - `path` (`str`) - test this path for absolutism...
Returns: `bool`
  Returns `True` if path is an absolute path name

### xkb_rules_names()

source code

Wrapper for: xprop -root _XKB_RULES_NAMES

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

### local_color_depth()

source code

Detect the current local screen's color depth.

Returns: `int`
  the local color depth in bits

### is_color_depth_ok(depth_session, depth_local)

source code

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: `bool`
  Does the session color depth work with the local display?

### find_session_window(session_name)

source code

Find a session window by its X2GO session ID.

Parameters:
  - `session_name` (`str`) - session name/ID of an X2Go session window
Returns: `obj` on Unix, `int` on Windows
  the window object (or ID) of the searched for session window

### get_desktop_geometry()

source code

Get the geometry of the current screen's desktop.

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

### get_workarea_geometry()

source code

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

       xprop -root '_NET_WORKAREA'

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

### set_session_window_title(session_window, session_title)

source code

Set title of session window.

Parameters:
  - `session_window` (`obj`) - session window instance
  - `session_title` (`str`) - session title to be set for `session_window`

### raise_session_window(session_window)

source code

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

Parameters:
  - `session_window` (`obj`) - session window instance

### merge_ordered_lists(l1, l2)

source code

Merge sort two sorted lists

Parameters:
  - `l1` (`list`) - first sorted list
  - `l2` (`list`) - second sorted list
Returns: `list`
  the merge result of both sorted lists

### compare_versions(version_a, op, version_b)

source code

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>

### genkeypair(local_username, client_address, key_type=`'``RSA``'`)

source code

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

### which(basename)

source code

Python equivalent to the shell command "which".

Parameters:
  - `basename` (`str`) - the basename of an application to be search for in $PATH
Returns: `str`
  full path to the application