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:
future.types.newobject.newobject
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.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>
- version_a (
-
x2go.utils.
detect_unused_port
(bind_address='127.0.0.1', preferred_port=None)[source]¶ 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
- bind_address (
-
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 sessionsession_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
orNone
- session_name (
-
x2go.utils.
find_session_window
(session_name)[source]¶ Find a session window by its X2GO session ID.
Parameters: session_name ( str
) – session name/ID of an X2Go session windowReturns: 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.
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’)
- local_username (
-
x2go.utils.
get_desktop_geometry
()[source]¶ Get the geometry of the current screen’s desktop.
Returns: a (<width>, <height>) tuple will be returned Return type: tuple
-
x2go.utils.
get_encoding
()[source]¶ Detect systems default character encoding.
Returns: The system’s local character encoding. Return type: str
-
x2go.utils.
get_workarea_geometry
()[source]¶ 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)[source]¶ 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 nameReturn 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.
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
- depth_session (
-
x2go.utils.
is_in_nx3packmethods
(method)[source]¶ Test if a given compression method is valid for NX3 Proxy.
Parameters: method ( str
) – name of an NXv3 pack methodReturns: True
ifmethod
is in the hard-coded list of NX3 compression methods.Return type: bool
-
x2go.utils.
known_encodings
()[source]¶ Render a list of all-known-to-Python character encodings (including all known aliases)
-
x2go.utils.
local_color_depth
()[source]¶ 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
Parameters: - l1 (
list
) – first sorted list - l2 (
list
) – second sorted list
Returns: the merge result of both sorted lists
Return type: list
- l1 (
-
x2go.utils.
patiently_remove_file
(dirname, filename)[source]¶ 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
- dirname (
-
x2go.utils.
raise_session_window
(session_window)[source]¶ 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)[source]¶ 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 byX2GoClient.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.
Parameters: - session_window (
obj
) – session window instance - session_title (
str
) – session title to be set forsession_window
- session_window (
-
x2go.utils.
slugify
(value)[source]¶ 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 sluggifiedReturns: the sluggified string Return type: str
-
x2go.utils.
touch_file
(filename, mode='a')[source]¶ 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’)
- filename (
-
x2go.utils.
unique
(seq)[source]¶ 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