Package Gnumed :: Package pycommon :: Module gmTools
[frames] | no frames]

Module gmTools

source code

GNUmed general tools.


Author: K. Hilbert <Karsten.Hilbert@gmx.net>

License: GPL v2 or later (details at http://www.gnu.org)

Classes
  gmPaths
This class provides the following paths:
Functions
 
handle_uncaught_exception_console(t, v, tb) source code
 
mkdir(directory=None) source code
 
gpg_decrypt_file(filename=None, passphrase=None) source code
 
file2md5(filename=None, return_hex=True) source code
 
unicode2charset_encoder(unicode_csv_data, encoding='utf-8') source code
 
unicode_csv_reader(unicode_csv_data, dialect=<class csv.excel at 0xc4fc2fc>, encoding='utf-8', **kwargs) source code
 
fname_stem(filename) source code
 
get_unique_filename(prefix=None, suffix=None, tmp_dir=None)
This introduces a race condition between the file.close() and actually using the filename.
source code
 
import_module_from_directory(module_path=None, module_name=None, always_remove_path=False)
Import a module from any location.
source code
 
size2str(size=0, template=u'%s') source code
 
bool2subst(boolean=None, true_return=True, false_return=False, none_return=None) source code
 
bool2str(boolean=None, true_str='True', false_str='False') source code
 
none_if(value=None, none_equivalent=None, strip_string=False)
Modelled after the SQL NULLIF function.
source code
 
coalesce(initial=None, instead=None, template_initial=None, template_instead=None, none_equivalents=None, function_initial=None)
Modelled after the SQL coalesce function.
source code
 
capitalize(text=None, mode=4)
Capitalize the first character but leave the rest alone.
source code
 
input2decimal(initial=None) source code
 
input2int(initial=None, minval=None, maxval=None) source code
 
strip_leading_empty_lines(lines=None, text=None, eol=..., return_list=True) source code
 
strip_trailing_empty_lines(lines=None, text=None, eol=..., return_list=True) source code
 
wrap(text=None, width=None, initial_indent=u'', subsequent_indent=u'', eol=...)
A word-wrap function that preserves existing line breaks and most spaces in the text.
source code
 
unwrap(text=None, max_length=None, strip_whitespace=True, remove_empty_lines=True, line_separator=u' // ') source code
 
xml_escape_string(text=None)
check for special XML characters and transform them
source code
 
tex_escape_string(text=None, replace_known_unicode=True)
check for special TeX characters and transform them
source code
 
xetex_escape_string(text=None) source code
 
prompted_input(prompt=None, default=None)
Obtains entry from standard input.
source code
 
get_icon(wx=None) source code
Variables
  __doc__ = """GNUmed general tools."""
  u_currency_pound = u'£'
  u_currency_sign = u'¤'
  u_currency_yen = u'¥'
  u_right_double_angle_quote = u'«'
  u_registered_trademark = u'®'
  u_plus_minus = u'±'
  u_left_double_angle_quote = u'»'
  u_one_quarter = u'¼'
  u_one_half = u'½'
  u_three_quarters = u'¾'
  u_multiply = u'×'
  u_greek_ALPHA = u'Α'
  u_greek_alpha = u'α'
  u_greek_OMEGA = u'Ω'
  u_greek_omega = u'ω'
  u_triangular_bullet = u''
  u_ellipsis = u''
  u_euro = u''
  u_numero = u''
  u_down_left_arrow = u''
  u_left_arrow = u''
  u_right_arrow = u''
  u_left_arrow_with_tail = u''
  u_sum = u''
  u_almost_equal_to = u''
  u_corresponds_to = u''
  u_infinity = u''
  u_diameter = u''
  u_checkmark_crossed_out = u''
  u_box_horiz_single = u''
  u_box_horiz_4dashes = u''
  u_box_top_double = u''
  u_box_top_left_double_single = u''
  u_box_top_right_double_single = u''
  u_box_top_left_arc = u''
  u_box_bottom_right_arc = u''
  u_box_bottom_left_arc = u''
  u_box_horiz_light_heavy = u''
  u_box_horiz_heavy_light = u''
  u_skull_and_crossbones = u''
  u_frowning_face = u''
  u_smiling_face = u''
  u_black_heart = u''
  u_checkmark_thin = u''
  u_checkmark_thick = u''
  u_writing_hand = u''
  u_pencil_1 = u''
  u_pencil_2 = u''
  u_pencil_3 = u''
  u_latin_cross = u''
  u_kanji_yen = u''
  u_replacement_character = u''
  u_link_symbol = u'ὑ7'
  default_csv_reader_rest_key = u'list_of_values_of_unknown_fields'
  CAPS_ALLCAPS = 2
  CAPS_FIRST = 1
  CAPS_FIRST_ONLY = 5
  CAPS_NAMES = 4
  CAPS_NONE = 0
  CAPS_WORDS = 3
  __package__ = 'Gnumed.pycommon'

Imports: regex, sys, os, csv, tempfile, logging, hashlib, platform, subprocess, decimal, cPickle, zlib, xml_tools, gmBorg


Function Details

get_unique_filename(prefix=None, suffix=None, tmp_dir=None)

source code 

This introduces a race condition between the file.close() and actually using the filename.

The file will NOT exist after calling this function.

coalesce(initial=None, instead=None, template_initial=None, template_instead=None, none_equivalents=None, function_initial=None)

source code 
Modelled after the SQL coalesce function.

To be used to simplify constructs like:

        if initial is None (or in none_equivalents):
                real_value = (template_instead % instead) or instead
        else:
                real_value = (template_initial % initial) or initial
        print real_value

@param initial: the value to be tested for <None>
@type initial: any Python type, must have a __str__ method if template_initial is not None
@param instead: the value to be returned if <initial> is None
@type instead: any Python type, must have a __str__ method if template_instead is not None
@param template_initial: if <initial> is returned replace the value into this template, must contain one <%s> 
@type template_initial: string or None
@param template_instead: if <instead> is returned replace the value into this template, must contain one <%s> 
@type template_instead: string or None

example:
        function_initial = ('strftime', '%Y-%m-%d')

Ideas:
        - list of insteads: initial, [instead, template], [instead, template], [instead, template], template_initial, ...

capitalize(text=None, mode=4)

source code 

Capitalize the first character but leave the rest alone.

Note that we must be careful about the locale, this may have issues ! However, for UTF strings it should just work.

wrap(text=None, width=None, initial_indent=u'', subsequent_indent=u'', eol=...)

source code 
A word-wrap function that preserves existing line breaks
        and most spaces in the text. Expects that existing line
        breaks are posix newlines (
).
        

prompted_input(prompt=None, default=None)

source code 

Obtains entry from standard input.

prompt: Prompt text to display in standard output default: Default value (for user to press enter only) CTRL-C: aborts and returns None