Package conduit :: Package utils
[hide private]

Package utils

source code

Utility Functions

Part of this code copied from from Listen (c) 2006 Mehdi Abaakouk (http://listengnome.free.fr/)

Copyright: John Stowers, 2006 License: GPLv2

Submodules [hide private]

Functions [hide private]
 
get_proportional_resize(desiredW, desiredH, currentW, currentH)
Returns proportionally resized co-ordinates for an image
source code
 
program_installed(app)
Check if the given app is installed.
source code
 
new_tempfile(contents, contentsAreText=True)
Returns a new File onject, which has been created in the system temporary directory, and that has been filled with contents
source code
 
new_tempdir()
Creates a new temporary directory
source code
 
unique_list(seq)
The fastes way to unique-ify a list while retaining its order, from http://www.peterbe.com/plog/uniqifiers-benchmark
source code
 
random_string(length=5)
returns a random string of length
source code
 
dataprovider_add_dir_to_path(dataproviderfile, directory="")
Adds directory to the python search path.
source code
 
dataprovider_glade_get_widget(dataproviderfile, gladefilename, widget)
Gets a single gtk widget from a glad file
source code
 
run_dialog(dialog, window=None)
Runs a given dialog, and makes it transient for the given window if any
source code
 
run_dialog_non_blocking(dialog, resp_cb, window=None)
Runs a given dialog, and makes it transient for the given window if any
source code
 
dialog_set_busy_cursor(dlg)
Sets the dialog to display the busy cursor
source code
 
dialog_reset_cursor(dlg)
Resets the dialog to display the plain Gtk cursor
source code
 
md5_string(string)
Returns the md5 of the supplied string in readable hexdigest string format
source code
 
uuid_string()
Returns a uuid string
source code
 
dbus_service_available(interface, bus=None)
Checks if a dbus service is available on the given bus
source code
 
get_user_string()
Makes a user and machine dependant string in the form username@hostname
source code
 
datetime_from_timestamp(t)
Makes a datetime object from a unix timestamp.
source code
 
datetime_get_timestamp(d)
Returns the unix timestamp for a datetime
source code
 
encode_conversion_args(args)
encodes an args dictionary to a url string in the form param=value&param2=val2
source code
 
decode_conversion_args(argString)
FIXME: dont import cgi for just one function.
source code
 
log_function_call(log)
A decorator that prints debug message showing the function name and argument types to the supplied logger instance.
source code
 
xml_extract_value_from_tag(tag, text)
Returns the contents of the xml tag or None.
source code
 
get_module_information(module, versionAttributeName)
Prints the name, location and version of the supplied module
source code
Variables [hide private]
  log = logging.getLogger("Utils")
Function Details [hide private]

new_tempfile(contents, contentsAreText=True)

source code 

Returns a new File onject, which has been created in the system temporary directory, and that has been filled with contents

The file is closed when it is returned
Parameters:
  • contents - The data to write into the file
  • contentsAreText - Indicates to the OS if the file is text (as opposed to a binary type file
  • contentsAreText - bool
Returns:
a conduit.datatypes.File

dataprovider_add_dir_to_path(dataproviderfile, directory="")

source code 

Adds directory to the python search path.

From within a dataprovider (FooModule.py) call with Utils.dataprovider_add_dir_to_path(__file__, some_dir):

run_dialog(dialog, window=None)

source code 
Runs a given dialog, and makes it transient for the given window if any
Parameters:
  • dialog - dialog
  • window - gtk window
Returns:
True if the user clicked OK to exit the dialog

run_dialog_non_blocking(dialog, resp_cb, window=None)

source code 
Runs a given dialog, and makes it transient for the given window if any
Parameters:
  • dialog - dialog
  • window - gtk window
Returns:
True if the user clicked OK to exit the dialog

dbus_service_available(interface, bus=None)

source code 
Checks if a dbus service is available on the given bus
Parameters:
  • interface - The interface to look for
  • bus - The bus to look on (optional)

datetime_from_timestamp(t)

source code 

Makes a datetime object from a unix timestamp.

Note: For the sake of consistancy always drop the fractional (microsecond) part of the timestamp

datetime_get_timestamp(d)

source code 

Returns the unix timestamp for a datetime

Note: For the sake of consistancy always drop the fractional (microsecond) part of the timestamp

decode_conversion_args(argString)

source code 
FIXME: dont import cgi for just one function. Also it doesnt even handle lists

log_function_call(log)

source code 

A decorator that prints debug message showing the function name and argument types to the supplied logger instance.

Adapted from the accepts/returns decorators at http://wiki.python.org/moin/PythonDecoratorLibrary

xml_extract_value_from_tag(tag, text)

source code 

Returns the contents of the xml tag or None. Uses a simple regex.

Taken from: http://immike.net/blog/2007/04/06/5-regular-expressions-every-web-programmer-should-know/