Package flumotion :: Package common :: Module common
[hide private]

Module common

source code

small common functions used by all processes

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

formatStorage(units, precision=2)

source code 

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 (int or float) - the unit size to format
  • precision (int) - the number of floating point digits to use
Returns: string
value of units, formatted using SI scale and the given precision

formatTime(seconds, fractional=0)

source code 

Nicely format time in a human-readable format. Will chunks weeks, days, hours and minutes.

Parameters:
  • seconds (int or float) - the time in seconds to format.
  • fractional (int) - how many digits to show for the fractional part.
Returns: string
a nicely formatted time string.

version(binary)

source code 

Print a version block for the flumotion binaries.

Parameters:
  • binary (string) - name of the binary

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

source code 

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.

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

source code 

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

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

source code 

Daemonize a process, writing log files and PID files to conventional locations.

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

ensureDir(dir, description)

source code 

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

writePidFile(type, name=None)

source code 

Write a pid file in the run directory, using the given process type and process name for the filename.

Returns: str
full path to the pid file that was written

deletePidFile(type, name=None)

source code 

Delete the pid file in the run directory, using the given process type and process name for the filename.

Returns: str
full path to the pid file that was written

getPid(type, name=None)

source code 

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.

termPid(pid)

source code 

Send the given process a TERM signal.

Returns:
whether or not the process with the given pid was running

killPid(pid)

source code 

Send the given process a KILL signal.

Returns:
whether or not the process with the given pid was running

checkPidRunning(pid)

source code 

Check if the given pid is currently running.

Returns:
whether or not a process with that pid is active.

waitPidFile(type, name=None)

source code 

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

Return the pid.

addressGetHost(a)

source code 

Get the host name of an IPv4 address.

Parameters:
  • a (twisted.internet.address.IPv4Address)

addressGetPort(a)

source code 

Get the port number of an IPv4 address.

Parameters:
  • a (twisted.internet.address.IPv4Address)

componentPath(componentName, parentName)

source code 

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

Deprecated: Use @componentId instead

componentId(parentName, componentName)

source code 

Create a componentId based on the parentName and componentName.

A componentId uniquely identifies a component within a planet.

Returns: str

Since: 0.3.1

parseComponentId(componentId)

source code 
Returns: tuple of (str, str)
tuple of (flowName, componentName)

Since: 0.3.1

feedId(componentName, feedName)

source code 

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

parseFeedId(feedId)

source code 
Returns: tuple of (str, str)
tuple of (componentName, feedName)

Since: 0.3.1

fullFeedId(flowName, componentName, feedName)

source code 

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

parseFullFeedId(fullFeedId)

source code 
Returns: tuple of (str, str, str)
tuple of (flowName, componentName, feedName)

Since: 0.3.1

pathToModuleName(path)

source code 

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

compareVersions(first, second)

source code 

Compares two version strings. Returns -1, 0 or 1 if first is smaller than, equal to or larger than second.

Parameters:
  • second (str)
  • first (str)
Returns: int

versionTupleToString(versionTuple)

source code 

Converts a version tuple to a string. If the tuple has a zero nano number, it is dropped from the string.

Parameters:
  • versionTuple (tuple)
Returns: str

Since: 0.4.1

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

source code 

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)

source code 

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.

strToBool(string)

source code 
Parameters:
  • string (str)
Returns:
True if the string represents a value we interpret as true.