Package flumotion :: Package common :: Module common
[show private | hide private]
[frames | no frames]

Module flumotion.common.common

small common functions used by all processes
Classes
InitMixin A mixin class to help with object initialization.

Function Summary
  addressGetHost(a)
Get the host name of an IPv4 address.
  addressGetPort(a)
Get the port number of an IPv4 address.
  argRepr(args, kwargs, max)
Return a string representing the given args.
  call_each_method(obj, method, *args, **kwargs)
Invoke all implementations of a method on an object.
  call_each_method_reversed(obj, method, *args, **kwargs)
Invoke all implementations of a method on an object.
  checkPidRunning(pid)
Check if the given pid is currently running.
int compareVersions(first, second)
Compares two version strings.
str componentId(parentName, componentName)
Create a componentId based on the parentName and componentName.
  componentPath(componentName, parentName)
Create a path string out of the name of a component and its parent.
  daemonize(stdin, stdout, stderr, directory)
This forks the current process into a daemon.
  daemonizeHelper(processType, daemonizeTo, processName)
Daemonize a process, writing log files and PID files to conventional locations.
str deletePidFile(type, name)
Delete the pid file in the run directory, using the given process type and process name for the filename.
  ensureDir(dir, description)
Ensure the given directory exists, creating it if not.
str feedId(componentName, feedName)
Create a feedId based on the componentName and feedName.
string formatStorage(units, precision)
Nicely formats a storage size using SI units.
string formatTime(seconds, fractional)
Nicely format time in a human-readable format.
str fullFeedId(flowName, componentName, feedName)
Create a fullFeedId based on the flowName, componentName and feedName.
  getLL()
Return the (at most) two-letter language code set for message translation.
  getPid(type, name)
Get the pid from the pid file in the run directory, using the given process type and process name for the filename.
  getPidPath(type, name)
Get the full path to the pid file for the given process type and name.
  gettexter(domain)
Returns a method you can use as _ to translate strings for the given domain.
  killPid(pid)
Send the given process a KILL signal.
  mergeImplements(*classes)
Merge the __implements__ tuples of the given classes into one tuple.
  objRepr(object)
Return a string giving the fully qualified class of the given object.
tuple of (str, str) parseComponentId(componentId)
Return tuple of (flowName, componentName)
tuple of (str, str) parseFeedId(feedId)
Return tuple of (componentName, feedName)
tuple of (str, str, str) parseFullFeedId(fullFeedId)
Return tuple of (flowName, componentName, feedName)
  pathToModuleName(path)
Convert the given (relative) path to the python module it would have to be imported as.
  startup(processType, processName, daemonize, daemonizeTo)
Prepare a process for starting, logging appropriate standarised messages.
  strToBool(string)
Return true if the string represents a value we interpret as true.
  termPid(pid)
Send the given process a TERM signal.
  version(binary)
Print a version block for the flumotion binaries.
str versionTupleToString(versionTuple)
Converts a version tuple to a string.
  waitForTerm()
Wait until we get killed by a TERM signal (from someone else).
  waitPidFile(type, name)
Wait for the given process type and name to have started and created a pid file.
str writePidFile(type, name)
Write a pid file in the run directory, using the given process type and process name for the filename.
  _call_each_method(obj, method, mro, args, kwargs)
  _uniq(l, key)
Filters out duplicate entries in a list.

Function Details

addressGetHost(a)

Get the host name of an IPv4 address.
Parameters:
a
           (type=twisted.internet.address.IPv4Address)

addressGetPort(a)

Get the port number of an IPv4 address.
Parameters:
a
           (type=twisted.internet.address.IPv4Address)

argRepr(args=(), kwargs={}, max=-1)

Return a string representing the given args.

call_each_method(obj, method, *args, **kwargs)

Invoke all implementations of a method on an object.

Searches for method implementations in the object's class and all of the class' superclasses. Calls the methods in method resolution order, which goes from subclasses to superclasses.

call_each_method_reversed(obj, method, *args, **kwargs)

Invoke all implementations of a method on an object.

Like call_each_method, but calls the methods in reverse method resolution order, from superclasses to subclasses.

checkPidRunning(pid)

Check if the given pid is currently running.
Returns:
whether or not a process with that pid is active.

compareVersions(first, second)

Compares two version strings. Returns -1, 0 or 1 if first is smaller than, equal to or larger than second.
Parameters:
first
           (type=str)
second
           (type=str)
Returns:
int

componentId(parentName, componentName)

Create a componentId based on the parentName and componentName.

A componentId uniquely identifies a component within a planet.
Returns:
str

Since: 0.3.1

componentPath(componentName, parentName)

Create a path string out of the name of a component and its parent.

Depreciated: Use @componentId instead

daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null', directory='/')

This forks the current process into a daemon. The stdin, stdout, and stderr arguments are file names that will be opened and be used to replace the standard file descriptors in sys.stdin, sys.stdout, and sys.stderr. These arguments are optional and default to /dev/null.

The fork will switch to the given directory.

daemonizeHelper(processType, daemonizeTo='/', processName=None)

Daemonize a process, writing log files and PID files to conventional locations.
Parameters:
processType - The process type, for example 'worker'. Used as part of the log file and PID file names.
           (type=str)
daemonizeTo - The directory that the daemon should run in.
           (type=str)
processName - The service name of the process. Used to disambiguate different instances of the same daemon.
           (type=str)

deletePidFile(type, name=None)

Delete the pid file in the run directory, using the given process type and process name for the filename.
Returns:
full path to the pid file that was written
           (type=str)

ensureDir(dir, description)

Ensure the given directory exists, creating it if not. Raises a SystemError if this fails, including the given description.

feedId(componentName, feedName)

Create a feedId based on the componentName and feedName.

A feedId uniquely identifies a feed within a flow or atmosphere. It identifies the feed from a feeder to an eater.
Returns:
str

Since: 0.3.1

formatStorage(units, precision=2)

Nicely formats a storage size using SI units. See Wikipedia and other sources for rationale. Prefixes are k, M, G, ... Sizes are powers of 10. Actual result should be suffixed with bit or byte, not b or B.
Parameters:
units - the unit size to format
           (type=int or float)
precision - the number of floating point digits to use
           (type=int)
Returns:
value of units, formatted using SI scale and the given precision
           (type=string)

formatTime(seconds, fractional=0)

Nicely format time in a human-readable format. Will chunks weeks, days, hours and minutes.
Parameters:
seconds - the time in seconds to format.
           (type=int or float)
fractional - how many digits to show for the fractional part.
           (type=int)
Returns:
a nicely formatted time string.
           (type=string)

fullFeedId(flowName, componentName, feedName)

Create a fullFeedId based on the flowName, componentName and feedName.

A fullFeedId uniquely identifies a feed within a planet.
Returns:
str

Since: 0.3.1

getLL()

Return the (at most) two-letter language code set for message translation.

getPid(type, name=None)

Get the pid from the pid file in the run directory, using the given process type and process name for the filename.
Returns:
pid of the process, or None if not running or file not found.

getPidPath(type, name=None)

Get the full path to the pid file for the given process type and name.

gettexter(domain)

Returns a method you can use as _ to translate strings for the given domain.

killPid(pid)

Send the given process a KILL signal.
Returns:
whether or not the process with the given pid was running

mergeImplements(*classes)

Merge the __implements__ tuples of the given classes into one tuple.

objRepr(object)

Return a string giving the fully qualified class of the given object.

parseComponentId(componentId)

Returns:
tuple of (flowName, componentName)
           (type=tuple of (str, str))

Since: 0.3.1

parseFeedId(feedId)

Returns:
tuple of (componentName, feedName)
           (type=tuple of (str, str))

Since: 0.3.1

parseFullFeedId(fullFeedId)

Returns:
tuple of (flowName, componentName, feedName)
           (type=tuple of (str, str, str))

Since: 0.3.1

pathToModuleName(path)

Convert the given (relative) path to the python module it would have to be imported as.

Return None if the path is not a valid python module

startup(processType, processName, daemonize=False, daemonizeTo='/')

Prepare a process for starting, logging appropriate standarised messages. First daemonizes the process, if daemonize is true.

strToBool(string)

Parameters:
string
           (type=str)
Returns:
True if the string represents a value we interpret as true.

termPid(pid)

Send the given process a TERM signal.
Returns:
whether or not the process with the given pid was running

version(binary)

Print a version block for the flumotion binaries.
Parameters:
binary - name of the binary
           (type=string)

versionTupleToString(versionTuple)

Converts a version tuple to a string. If the tuple has a zero nano number, it is dropped from the string.
Parameters:
versionTuple
           (type=tuple)
Returns:
str

Since: 0.4.1

waitForTerm()

Wait until we get killed by a TERM signal (from someone else).

waitPidFile(type, name=None)

Wait for the given process type and name to have started and created a pid file.

Return the pid.

writePidFile(type, name=None)

Write a pid file in the run directory, using the given process type and process name for the filename.
Returns:
full path to the pid file that was written
           (type=str)

_uniq(l, key=<function <lambda> at 0x40cd0e2c>)

Filters out duplicate entries in a list.

Generated by Epydoc 2.1 on Fri Apr 6 10:10:26 2007 http://epydoc.sf.net