Package entropy :: Module tools

Module tools

source code

# DESCRIPTION: # generic tools for all the handlers applications

Copyright (C) 2007-2008 Fabio Erculiani

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Functions
 
is_root() source code
 
is_user_in_entropy_group(uid=None) source code
 
get_uid_from_user(username) source code
 
get_gid_from_group(groupname) source code
 
get_user_from_uid(uid) source code
 
get_group_from_gid(gid) source code
 
kill_threads() source code
 
print_traceback(f=None) source code
 
get_traceback() source code
 
print_exception(returndata=False) source code
 
get_remote_data(url) source code
 
is_png_file(path) source code
 
is_jpeg_file(path) source code
 
is_bmp_file(path) source code
 
is_gif_file(path) source code
 
is_supported_image_file(path) source code
 
is_april_first() source code
 
add_proxy_opener(module, data) source code
 
is_valid_ascii(string) source code
 
is_valid_unicode(string) source code
 
is_valid_email(email) source code
 
islive() source code
 
get_file_size(file_path) source code
 
sum_file_sizes(file_list) source code
 
check_required_space(mountpoint, bytes_required) source code
 
getstatusoutput(cmd)
Return (status, output) of executing cmd in a shell.
source code
 
movefile(src, dest, src_basedir=None) source code
 
ebeep(count=5) source code
 
application_lock_check(option=None, gentle=False) source code
 
get_random_number() source code
 
split_indexable_into_chunks(mystr, chunk_len) source code
 
countdown(secs=5, what='Counting...', back=False) source code
 
md5sum(filepath) source code
 
sha512(filepath) source code
 
sha256(filepath) source code
 
sha1(filepath) source code
 
md5sum_directory(directory) source code
 
md5obj_directory(directory) source code
 
getfd(filespec, readOnly=0) source code
 
uncompress_file(file_path, destination_path, opener) source code
 
compress_file(file_path, destination_path, opener, compress_level=None) source code
 
compress_files(dest_file, files_to_compress, compressor='bz2') source code
 
universal_uncompress(compressed_file, dest_path, catch_empty=False) source code
 
unpack_gzip(gzipfilepath) source code
 
unpack_bzip2(bzip2filepath) source code
 
backup_client_repository() source code
 
extract_xpak(tbz2file, tmpdir=None) source code
 
read_xpak(tbz2file) source code
 
unpack_xpak(xpakfile, tmpdir=None) source code
 
suck_xpak(tbz2file, outputpath) source code
 
append_xpak(tbz2file, atom) source code
 
aggregate_edb(tbz2file, dbfile) source code
 
extract_edb(tbz2file, dbpath=None) source code
 
locate_edb(fileobj) source code
 
remove_edb(tbz2file, savedir) source code
 
create_md5_file(filepath) source code
 
create_sha512_file(filepath) source code
 
create_sha256_file(filepath) source code
 
create_sha1_file(filepath) source code
 
compare_md5(filepath, checksum) source code
 
compare_sha512(filepath, checksum) source code
 
compare_sha256(filepath, checksum) source code
 
compare_sha1(filepath, checksum) source code
 
md5string(string) source code
 
sort_update_files(update_list) source code
 
generic_file_content_parser(filepath) source code
 
allocate_masked_file(file, fromfile) source code
 
extract_elog(file) source code
 
isjustpkgname(mypkg) source code
 
ververify(myverx, silent=1) source code
Integer
isvalidatom(myatom, allow_blockers=True)
Check to see if a depend atom is valid
source code
 
catsplit(mydep) source code
String
get_operator(mydep)
Return the operator used in a depstring.
source code
Integer
isjustname(mypkg)
Checks to see if the depstring is only the package name (no version parts)
source code
Integer
isspecific(mypkg)
Checks to see if a package is in category/package-version or package-version format, possibly returning a cached result.
source code
 
catpkgsplit(mydata, silent=1)
Takes a Category/Package-Version-Rev and returns a list of each.
source code
 
pkgsplit(mypkg, silent=1) source code
String
dep_getkey(mydepx)
Return the category/package-name of a depstring.
source code
String
dep_getcpv(mydep)
Return the category-package-version with any operators/slot specifications stripped off
source code
String
dep_getslot(mydep)
# Imported from portage.dep # $Id: dep.py 11281 2008-07-30 06:12:19Z zmedico $
source code
List
dep_getusedeps(depend)
# Imported from portage.dep # $Id: dep.py 11281 2008-07-30 06:12:19Z zmedico $
source code
 
remove_usedeps(depend) source code
 
remove_slot(mydep)
# Imported from portage.dep # $Id: dep.py 11281 2008-07-30 06:12:19Z zmedico $
source code
 
remove_revision(ver) source code
 
remove_tag(mydep) source code
 
remove_entropy_revision(mydep) source code
 
dep_get_entropy_revision(mydep) source code
 
dep_get_portage_revision(mydep) source code
 
dep_get_match_in_repos(mydep) source code
 
dep_gettag(dep)
Retrieve the slot on a depend.
source code
 
remove_package_operators(atom) source code
 
compare_versions(ver1, ver2) source code
 
entropy_compare_versions(listA, listB) source code
 
g_n_w_cmp(a, b) source code
 
get_newer_version(versions) source code
 
get_newer_version_stable(versions) source code
 
g_e_n_w_cmp(a, b) source code
 
get_entropy_newer_version(versions) source code
 
get_entropy_newer_version_stable(versions)
descendent order versions = [(version,tag,revision),(version,tag,revision)]
source code
 
isnumber(x) source code
 
istextfile(filename, blocksize=512) source code
 
istext(s) source code
 
filter_duplicated_entries(alist) source code
 
escape(*args) source code
 
escape_single(x) source code
 
unescape(val) source code
 
unescape_list(*args) source code
 
extract_ftp_host_from_uri(uri) source code
 
spliturl(url) source code
 
compress_tar_bz2(storepath, pathtocompress) source code
 
spawn_function(f, *args, **kwds) source code
 
uncompress_tar_bz2(filepath, extractPath=None, catchEmpty=False) source code
 
bytes_into_human(bytes) source code
 
hide_ftp_password(uri) source code
 
extract_ftp_data(ftpuri) source code
 
get_file_unix_mtime(path) source code
 
get_random_temp_file() source code
 
get_file_timestamp(path) source code
 
convert_unix_time_to_human_time(unixtime) source code
 
convert_unix_time_to_datetime(unixtime) source code
 
get_current_unix_time() source code
 
get_year() source code
 
convert_seconds_to_fancy_output(seconds) source code
 
cleanup(toCleanDirs=[]) source code
 
flatten(l, ltypes=(<type 'list'>, <type 'tuple'>)) source code
 
read_repositories_conf() source code
 
write_ordered_repositories_entries(ordered_repository_list) source code
 
save_repository_settings(repodata, remove=False, disable=False, enable=False) source code
 
write_parameter_to_file(config_file, name, data) source code
 
write_new_branch(branch) source code
 
is_entropy_package_file(tbz2file) source code
 
is_valid_string(string) source code
 
is_valid_path(path) source code
 
is_valid_md5(myhash) source code
 
open_buffer() source code
 
seek_till_newline(f) source code
 
read_elf_class(elf_file) source code
 
is_elf_file(elf_file) source code
string
resolve_dynamic_library(library, requiring_executable)
Resolve given library name (as contained into ELF metadata) to a library path.
source code
 
read_elf_dynamic_libraries(elf_file) source code
 
read_elf_broken_symbols(elf_file) source code
 
read_elf_linker_paths(elf_file) source code
 
xml_from_dict_extended(dictionary) source code
 
dict_from_xml_extended(xml_string) source code
 
xml_from_dict(dictionary) source code
 
dict_from_xml(xml_string) source code
 
create_package_filename(category, name, version, package_tag) source code
 
create_package_atom_string(category, name, version, package_tag) source code
 
extract_packages_from_set_file(filepath) source code
 
collect_linker_paths() source code
 
collect_paths() source code
 
list_to_utf8(mylist) source code
Variables
  ver_regexp = re.compile(r'^(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(...
  suffix_regexp = re.compile(r'^(alpha|beta|rc|pre|p)(\d*)$')
  suffix_value = {'alpha': -4, 'beta': -3, 'p': 0, 'pre': -2, 'r...
  endversion_keys = ['pre', 'p', 'alpha', 'beta', 'rc']
  valid_category = re.compile(r'^\w[\w-]*')
  invalid_atom_chars_regexp = re.compile(r'[\(\)\|@]')
  dep_revmatch = re.compile(r'^r[0-9]')
  mappings = {' ': '+', '"': '""', '\'': '\'\''}
  readelf_avail_check = False
  ldd_avail_check = False
  ETP_ARCH_MAP = {('i386', 'i486', 'i586', 'i686'): 'x86', ('ppc...
  arch = 'x86'
  arches = ('i386', 'i486', 'i586', 'i686')
Function Details

isvalidatom(myatom, allow_blockers=True)

source code 

Check to see if a depend atom is valid

Example usage:

>>> isvalidatom('media-libs/test-3.0')
0
>>> isvalidatom('>=media-libs/test-3.0')
1
Parameters:
  • atom (String) - The depend atom to check against
Returns: Integer
One of the following: 1) 0 if the atom is invalid 2) 1 if the atom is valid

get_operator(mydep)

source code 

Return the operator used in a depstring.

Example usage:

>>> from portage.dep import *
>>> get_operator(">=test-1.0")
'>='
Parameters:
  • mydep (String) - The dep string to check
Returns: String
The operator. One of: '~', '=', '>', '<', '=*', '>=', or '<='

isjustname(mypkg)

source code 

Checks to see if the depstring is only the package name (no version parts)

Example usage:

>>> isjustname('media-libs/test-3.0')
0
>>> isjustname('test')
1
>>> isjustname('media-libs/test')
1
Parameters:
  • mypkg - The package atom to check
  • mypkg - String
Returns: Integer
One of the following: 1) 0 if the package string is not just the package name 2) 1 if it is

isspecific(mypkg)

source code 

Checks to see if a package is in category/package-version or package-version format, possibly returning a cached result.

Example usage:

>>> isspecific('media-libs/test')
0
>>> isspecific('media-libs/test-3.0')
1
Parameters:
  • mypkg (String) - The package depstring to check against
Returns: Integer
One of the following: 1) 0 if the package string is not specific 2) 1 if it is

catpkgsplit(mydata, silent=1)

source code 

Takes a Category/Package-Version-Rev and returns a list of each.

Parameters:
  • mydata (string) - Data to split
  • silent (Boolean (integer)) - suppress error messages
Returns:
  1. If each exists, it returns [cat, pkgname, version, rev]
  2. If cat is not specificed in mydata, cat will be "null"
  3. if rev does not exist it will be '-r0'
  4. If cat is invalid (specified but has incorrect syntax) an InvalidData Exception will be thrown

dep_getkey(mydepx)

source code 

Return the category/package-name of a depstring.

Example usage:

>>> dep_getkey('media-libs/test-3.0')
'media-libs/test'
Parameters:
  • mydep (String) - The depstring to retrieve the category/package-name of
Returns: String
The package category/package-version

dep_getcpv(mydep)

source code 

Return the category-package-version with any operators/slot specifications stripped off

Example usage:

>>> dep_getcpv('>=media-libs/test-3.0')
'media-libs/test-3.0'
Parameters:
  • mydep (String) - The depstring
Returns: String
The depstring with the operator removed

dep_getslot(mydep)

source code 

# Imported from portage.dep # $Id: dep.py 11281 2008-07-30 06:12:19Z zmedico $

Retrieve the slot on a depend.

Example usage:

>>> dep_getslot('app-misc/test:3')
'3'
Parameters:
  • mydep (String) - The depstring to retrieve the slot of
Returns: String
The slot

dep_getusedeps(depend)

source code 

# Imported from portage.dep # $Id: dep.py 11281 2008-07-30 06:12:19Z zmedico $

Pull a listing of USE Dependencies out of a dep atom.

Example usage:

>>> dep_getusedeps('app-misc/test:3[foo,-bar]')
('foo','-bar')
Parameters:
  • depend (String) - The depstring to process
Returns: List
List of use flags ( or [] if no flags exist )

remove_slot(mydep)

source code 


# Imported from portage.dep
# $Id: dep.py 11281 2008-07-30 06:12:19Z zmedico $

Removes dep components from the right side of an atom:
        * slot
        * use
        * repo

dep_gettag(dep)

source code 

Retrieve the slot on a depend.

Example usage:

>>> dep_gettag('app-misc/test#2.6.23-sabayon-r1')
'2.6.23-sabayon-r1'

resolve_dynamic_library(library, requiring_executable)

source code 

Resolve given library name (as contained into ELF metadata) to a library path.

Parameters:
  • library (string) - library name (as contained into ELF metadata)
  • requiring_executable (string) - path to ELF object that contains the given library name
Returns: string
resolved library path

Variables Details

ver_regexp

Value:
re.compile(r'^(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\\
d*)*)(-r(\d+))?$')

suffix_value

Value:
{'alpha': -4, 'beta': -3, 'p': 0, 'pre': -2, 'rc': -1}

ETP_ARCH_MAP

Value:
{('i386', 'i486', 'i586', 'i686'): 'x86',
 ('ppc'): None,
 ('sun4u'): None,
 ('x86_64'): 'amd64'}