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

Module gmTools

source code

GNUmed general tools.


Version: $Revision: 1.98 $

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

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

Classes
  gmPaths
This class provides the following paths:
Functions
 
check_for_update(url=None, current_branch=None, current_version=None, consider_latest_branch=False)
Check for new releases at <url>.
source code
 
handle_uncaught_exception_console(t, v, tb) source code
 
mkdir(directory=None) source code
 
send_mail(sender=None, receiver=None, message=None, server=None, auth=None, debug=False, subject=None, encoding='quoted-printable', attachments=None) source code
 
send_mail_old(sender=None, receiver=None, message=None, server=None, auth=None, debug=False, subject=None, encoding='latin1')
Send an E-Mail.
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 0x85de5fc>, encoding='utf-8', **kwargs) 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='%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)
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
 
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
 
tex_escape_string(text=None)
check for special latex-characters and transform them
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."""
  default_mail_sender = u'gnumed@gmx.net'
  default_mail_receiver = u'gnumed-devel@gnu.org'
  default_mail_server = u'mail.gmx.net'
  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_ellipsis = u''
  u_left_arrow = u''
  u_right_arrow = u''
  u_sum = u''
  u_corresponds_to = u''
  u_infinity = u''
  u_diameter = u''
  u_checkmark_crossed_out = 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_replacement_character = u''
  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

Imports: regex, sys, os, csv, tempfile, logging, hashlib, wget, decimal, StringIO, MimeWriter, mimetypes, mimetools, cPickle, zlib, gmBorg


Function Details

check_for_update(url=None, current_branch=None, current_version=None, consider_latest_branch=False)

source code 

Check for new releases at <url>.

Returns (bool, text). True: new release available False: up to date None: don't know

send_mail_old(sender=None, receiver=None, message=None, server=None, auth=None, debug=False, subject=None, encoding='latin1')

source code 

Send an E-Mail.

<debug>: see smtplib.set_debuglevel() <auth>: {'user': ..., 'password': ...} <receiver>: a list of email addresses

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

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