Package entropy :: Module const

Module const

source code


Author: Fabio Erculiani <[email protected]>

Contact: [email protected]

Copyright: Fabio Erculiani

License: GPL-2

Entropy Framework constants module.

This module contains all the Entropy constants used all around the "entropy" package.

Some of the constants in this module are used as "default" for the SystemSettings interface. So, make sure to read the documentation of SystemSettings in the "entropy.core" module.

Even if possible, etpConst, etpUi, and etpSys objects *SHOULD* be never ever modified manually. This freedom could change in future, so, if you want to produce a stable code, DON'T do that at all!

Basic Entropy constants handling functions are available in this module and are all prefixed with "const_*" or "initconfig_*". If you are writing a third party application, you should always try to avoid to deal directly with functions here unless specified otherwise. In fact, usually these here are wrapper in upper-level modules (entropy.client, entropy.server, entropy.services).

Functions
 
debug_signal(signum, frame) source code
 
dump_signal(signum, frame, extended=True, stderr=sys.stderr) source code
None
initconfig_entropy_constants(rootdir)
Main constants configurators, this is the only function that you should call from the outside, anytime you want.
source code
None
const_default_settings(rootdir)
Initialization of all the Entropy base settings.
source code
 
const_is_python3()
Return whether Python3 is interpreting this code.
source code
int
const_set_nice_level(nice_level=0)
Change current process scheduler "nice" level.
source code
None
const_read_entropy_release()
Read Entropy release file content and fill etpConst['entropyversion']
source code
int
const_pid_exists(pid)
Determine whether given pid exists.
source code
None
const_secure_config_file(config_file)
Setup entropy file needing strict permissions, no world readable.
source code
 
const_drop_privileges(unpriv_uid=None, unpriv_gid=None)
This function does its best to drop process privileges.
source code
 
const_regain_privileges()
This function should be called if, and only if, a previous const_drop_privileges() has been called.
source code
 
const_setup_run_directory()
Setup the Entropy /run directory with appropriate permissions.
source code
None
const_create_working_dirs()
Setup Entropy directory structure, as much automagically as possible.
source code
int
const_convert_log_level(entropy_log_level)
Converts Entropy log levels (0, 1, 2) to logging.ERROR, logging.INFO, logging.DEBUG.
source code
None
const_setup_perms(mydir, gid, f_perms=None, recursion=True, uid=-1)
Setup permissions and group id (GID) to a directory, recursively.
source code
 
const_setup_file(myfile, gid, chmod, uid=-1)
Setup file permissions and group id (GID).
source code
 
const_setup_directory(dirpath)
Setup Entropy directory, creating it if required, changing ownership and permissions as well.
source code
string
const_mkdtemp(dir=None, prefix=None, suffix=None)
mkdtemp() wrapper that creates a temporary directory inside etpConst['entropyunpackdir'] if dir is None.
source code
tuple
const_mkstemp(dir=None, prefix=None, suffix=None)
mkstemp() wrapper that creates a temporary file inside etpConst['entropyunpackdir'] if dir is None.
source code
integer(8) (octal)
const_get_chmod(myfile)
This function get the current permissions of the specified file.
source code
None
const_set_chmod(myfile, chmod)
This function sets specified permissions to a file.
source code
bool
const_file_readable(path)
Return whether path points to a readable file.
source code
bool
const_file_writable(path)
Return whether path points to a writable file.
source code
bool
const_dir_readable(dir_path)
Return whether path points to a readable directory.
source code
bool
const_dir_writable(dir_path)
Return whether path points to a writable directory.
source code
int
const_get_entropy_gid()
This function tries to retrieve the "entropy" user group GID.
source code
int
const_get_entropy_nopriv_gid()
This function tries to retrieve the "entropy-nopriv" user group GID.
source code
int
const_get_entropy_nopriv_uid()
This function tries to retrieve the "entropy-nopriv" user id (uid).
source code
int
const_get_fallback_nopriv_uid()
Fallback function that tries to retrieve the "nobody" user id (uid).
source code
int
const_get_lazy_nopriv_uid()
This function returns an unprivileged uid by first trying to call const_get_entropy_nopriv_uid() and then const_get_fallback_nopriv_uid()
source code
int
const_get_lazy_nopriv_gid()
This function returns an unprivileged gid by first trying to call const_get_entropy_nopriv_gid() and then const_get_fallback_nopriv_gid()
source code
int
const_get_fallback_nopriv_gid()
Fallback function that tries to retrieve the "nogroup" group id (gid).
source code
 
const_get_stringtype()
Return generic string type for usage in isinstance().
source code
bool
const_isstring(obj)
Return whether obj is a string (unicode or raw).
source code
bool
const_isunicode(obj)
Return whether obj is a unicode.
source code
 
const_israwstring(obj) source code
unicode object
const_convert_to_unicode(obj, enctype='raw_unicode_escape')
Convert generic string to unicode format, this function supports both Python 2.x and Python 3.x unicode bullshit.
source code
bytes
const_convert_to_rawstring(obj, from_enctype='raw_unicode_escape')
Convert generic string to raw string (str for Python 2.x or bytes for Python 3.x).
source code
 
const_get_buffer()
Return generic buffer object (supporting both Python 2.x and Python 3.x)
source code
 
const_get_int()
Return generic int object (supporting both Python 2.x and Python 3.x).
source code
 
const_isfileobj(obj)
Return whether obj is a file object
source code
 
const_isnumber(obj)
Return whether obj is an int, long object.
source code
 
const_cmp(a, b)
cmp() is gone in Python 3.x provide our own implementation.
source code
bool
const_islive()
Live environments (Operating System running off a CD/DVD) must feature the "cdroot" parameter in kernel /proc/cmdline
source code
None
const_kill_threads(wait_seconds=120.0)
Entropy threads killer.
source code
bool
const_debug_enabled()
Return whether debug is enabled.
source code
None
const_debug_write(identifier, msg, force=False, stdout=None)
Entropy debugging output write functions.
source code
string
const_get_caller()
When called inside a function, return the caller function name.
source code
list
const_get_stack()
Return current function stack in form of list of tuples
source code
int
const_get_cpus()
Return the number of CPUs/Cores the Operating system exposes
source code
Variables
  ETP_ARCH_MAP = {('i386', 'i486', 'i586', 'i686'): 'x86', ('mip...
  ETP_ARCH_CONST = 'amd64'
  etpSys = {'api': '3', 'arch': 'amd64', 'archs': ['alpha', 'amd...
  etpConst = {'backed_up': {}, 'branch': '5', 'cachedumpext': '....
  __package__ = 'entropy'
  arch = 'amd64'
  arches = ('x86_64')
Function Details

initconfig_entropy_constants(rootdir)

source code 

Main constants configurators, this is the only function that you should call from the outside, anytime you want. it will reset all the variables excluding those backed up previously.

Parameters:
  • rootdir (string) - current root directory, if any, or ""
Returns: None
None
Raises:
  • AttributeError - when specified rootdir is not a directory

const_default_settings(rootdir)

source code 

Initialization of all the Entropy base settings.

Parameters:
  • rootdir (string) - current root directory, if any, or ""
Returns: None
None

const_set_nice_level(nice_level=0)

source code 

Change current process scheduler "nice" level.

Parameters:
  • nice_level (int) - new valid nice level
Returns: int
current_nice new nice level

const_read_entropy_release()

source code 

Read Entropy release file content and fill etpConst['entropyversion']

Returns: None
None

const_pid_exists(pid)

source code 

Determine whether given pid exists.

Parameters:
  • pid (int) - process id
Returns: int
pid exists? 1; pid does not exist? 0

const_secure_config_file(config_file)

source code 

Setup entropy file needing strict permissions, no world readable.

Parameters:
  • config_file (string) - valid config file path
Returns: None
None

const_drop_privileges(unpriv_uid=None, unpriv_gid=None)

source code 

This function does its best to drop process privileges. If it fails, an exception is raised. You can consider this function security-safe.

Parameters:
  • unpriv_uid (int) - override default unprivileged uid
  • unpriv_gid (int) - override default unprivileged gid
Raises:
  • entropy.exceptions.SecurityError - if unprivileged uid/gid cannot be retrieived.
  • ValueError - if program is already running as unprivileged user, but this differs from the usual entropy unprivileged user.
  • OSError - if privileges can't be dropped, the underlying syscall fails.

To Do: when Python 2.7, see os.setresuid()

const_regain_privileges()

source code 

This function should be called if, and only if, a previous const_drop_privileges() has been called. It makes the program able to get back privileges that were dropped previously.

Raises:

To Do: when Python 2.7, see os.getresuid()

const_create_working_dirs()

source code 

Setup Entropy directory structure, as much automagically as possible.

Returns: None
None

const_convert_log_level(entropy_log_level)

source code 

Converts Entropy log levels (0, 1, 2) to logging.ERROR, logging.INFO, logging.DEBUG.

Parameters:
  • entropy_log_level (int) - entropy log level id (0, 1, 2), bogus values are return logging.DEBUG
Returns: int
logging.{ERROR,INFO,DEBUG} value

const_setup_perms(mydir, gid, f_perms=None, recursion=True, uid=-1)

source code 

Setup permissions and group id (GID) to a directory, recursively.

Parameters:
  • mydir (string) - valid file path
  • gid (int) - valid group id (GID)
  • f_perms (octal) - file permissions in octal type
  • recursion (bool) - set permissions recursively?
  • uid (int) - usually this argument shouldn't be used, but in cae it sets the uid to the file
Returns: None
None

const_setup_file(myfile, gid, chmod, uid=-1)

source code 

Setup file permissions and group id (GID).

Parameters:
  • myfile (string) - valid file path
  • gid (int) - valid group id (GID)
  • chmod (integer representing an octal) - permissions
  • uid (int) - usually this argument shouldn't be used, but in cae it sets the uid to the file

const_setup_directory(dirpath)

source code 

Setup Entropy directory, creating it if required, changing ownership and permissions as well.

Parameters:
  • dirpath (string) - path to entropy directory
Raises:
  • OSError - if permissions are fucked up

const_mkdtemp(dir=None, prefix=None, suffix=None)

source code 

mkdtemp() wrapper that creates a temporary directory inside etpConst['entropyunpackdir'] if dir is None.

Parameters:
  • dir (string) - TMPDIR
  • prefix (string) - the mkdtemp prefix argument
  • suffix (string) - the mkdtemp suffix argument
Returns: string
the temporary directory path

const_mkstemp(dir=None, prefix=None, suffix=None)

source code 

mkstemp() wrapper that creates a temporary file inside etpConst['entropyunpackdir'] if dir is None.

Parameters:
  • dir (string) - TMPDIR
  • prefix (string) - the mkdtemp prefix argument
  • suffix (string) - the mkdtemp suffix argument
Returns: tuple
the temporary file fd and path tuple

const_get_chmod(myfile)

source code 

This function get the current permissions of the specified file. If you want to use the returning value with const_set_chmod you need to convert it back to int.

Parameters:
  • myfile (string) - valid file path
Returns: integer(8) (octal)
octal representing permissions

const_set_chmod(myfile, chmod)

source code 

This function sets specified permissions to a file. If they differ from the current ones.

Parameters:
  • myfile (string) - valid file path
  • chmod (integer representing an octal) - permissions
Returns: None
None

const_file_readable(path)

source code 

Return whether path points to a readable file.

Parameters:
  • path (string) - path to a file
Returns: bool
True, if file exists and is readable

const_file_writable(path)

source code 

Return whether path points to a writable file.

Parameters:
  • path (string) - path to a file
Returns: bool
True, if file exists and is writable

const_dir_readable(dir_path)

source code 

Return whether path points to a readable directory. Readable directory is one that you can read the content.

Parameters:
  • path (string) - path to a directory
Returns: bool
True, if directory exists and is readable

const_dir_writable(dir_path)

source code 

Return whether path points to a writable directory.

Parameters:
  • path (string) - path to a directory
Returns: bool
True, if directory exists and is writable

const_get_entropy_gid()

source code 

This function tries to retrieve the "entropy" user group GID.

Returns: int
entropy group id
Raises:
  • KeyError - when "entropy" system GID is not available

const_get_entropy_nopriv_gid()

source code 

This function tries to retrieve the "entropy-nopriv" user group GID. This is the unprivileged entropy users group.

Returns: int
entropy-nopriv group id
Raises:
  • KeyError - when "entropy-nopriv" system GID is not available

const_get_entropy_nopriv_uid()

source code 

This function tries to retrieve the "entropy-nopriv" user id (uid).

Returns: int
entropy-nopriv user id
Raises:
  • KeyError - when "entropy-nopriv" system UID is not available

const_get_fallback_nopriv_uid()

source code 

Fallback function that tries to retrieve the "nobody" user id (uid). It is used when const_get_entropy_nopriv_uid() fails.

Returns: int
nobody user id
Raises:
  • KeyError - when "nobody" system UID is not available

const_get_lazy_nopriv_uid()

source code 

This function returns an unprivileged uid by first trying to call const_get_entropy_nopriv_uid() and then const_get_fallback_nopriv_uid()

Returns: int
uid
Raises:

const_get_lazy_nopriv_gid()

source code 

This function returns an unprivileged gid by first trying to call const_get_entropy_nopriv_gid() and then const_get_fallback_nopriv_gid()

Returns: int
uid
Raises:

const_get_fallback_nopriv_gid()

source code 

Fallback function that tries to retrieve the "nogroup" group id (gid). It is used when const_get_entropy_nopriv_gid() fails.

Returns: int
nogroup user id
Raises:
  • KeyError - when "nogroup" system GID is not available

const_get_stringtype()

source code 

Return generic string type for usage in isinstance(). On Python 2.x, it returns basestring while on Python 3.x it returns (str, bytes,)

const_isstring(obj)

source code 

Return whether obj is a string (unicode or raw).

Parameters:
  • obj (Python object) - Python object
Returns: bool
True, if object is string

const_isunicode(obj)

source code 

Return whether obj is a unicode.

Parameters:
  • obj (Python object) - Python object
Returns: bool
True, if object is unicode

const_convert_to_unicode(obj, enctype='raw_unicode_escape')

source code 

Convert generic string to unicode format, this function supports both Python 2.x and Python 3.x unicode bullshit.

Parameters:
  • obj (string) - generic string object
Returns: unicode object
unicode string object

const_convert_to_rawstring(obj, from_enctype='raw_unicode_escape')

source code 

Convert generic string to raw string (str for Python 2.x or bytes for Python 3.x).

Parameters:
  • obj (string object) - input string
  • from_enctype (string) - encoding which string is using
Returns: bytes
raw string

const_get_int()

source code 

Return generic int object (supporting both Python 2.x and Python 3.x). For Python 2.x a (long, int) tuple is returned. For Python 3.x a (int,) tuple is returned.

const_islive()

source code 

Live environments (Operating System running off a CD/DVD) must feature the "cdroot" parameter in kernel /proc/cmdline

Sample code:

>>> from entropy.const import const_islive
>>> const_islive()
False
Returns: bool
determine wether this is a Live system or not

const_kill_threads(wait_seconds=120.0)

source code 

Entropy threads killer. Even if Python threads cannot be stopped or killed, TimeScheduled ones can, exporting the kill() method.

Sample code:

>>> from entropy.const import const_kill_threads
>>> const_kill_threads()
Parameters:
  • wait_seconds (int) - number of seconds thread.join() should wait
Returns: None
None

const_debug_enabled()

source code 

Return whether debug is enabled.

Returns: bool
True, if debug is enabled

const_debug_write(identifier, msg, force=False, stdout=None)

source code 

Entropy debugging output write functions.

Parameters:
  • identifier (string) - debug identifier
  • msg (string) - debugging message
  • force (bool) - force print even if debug mode is off
  • stdout (file object or None) - provide an alternative stdout file object
Returns: None
None

const_get_caller()

source code 

When called inside a function, return the caller function name.

Returns: string
caller function name

const_get_stack()

source code 

Return current function stack in form of list of tuples

Returns: list
current function stack

const_get_cpus()

source code 

Return the number of CPUs/Cores the Operating system exposes

Returns: int
number of CPUs/Cores available

Variables Details

ETP_ARCH_MAP

Value:
{('i386', 'i486', 'i586', 'i686'): 'x86',
 ('mips', 'mips64'): 'mips',
 ('x86_64'): 'amd64'}

etpSys

Value:
{'api': '3',
 'arch': 'amd64',
 'archs': ['alpha',
           'amd64',
           'amd64-fbsd',
           'arm',
           'hppa',
           'ia64',
...

etpConst

Value:
{'backed_up': {},
 'branch': '5',
 'cachedumpext': '.dmp',
 'changelog_date_format': '%a, %d %b %Y %X +0000',
 'changelog_filename': 'ChangeLog',
 'changelog_filename_compressed': 'ChangeLog.bz2',
 'client_gpg': True,
 'clientdbid': '__system__',
...