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

Module flumotion.common.common

small common functions used by all processes
Function Summary
  addressGetHost(a)
Get the port number 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.
  checkPidRunning(pid)
Check if the given pid is currently running.
boolean checkPortFree(port)
Check if the given local port is free to accept on.
boolean checkRemotePort(host, port)
Check if the given remote host/port is accepting connections.
  componentPath(componentName, parentName)
Create a path string out of the name of a component and its parent.
  daemonize(stdin, stdout, stderr)
This forks the current process into a daemon.
  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.
string formatStorage(units, precision)
Nicely formats a storage size using SI units.
string formatTime(seconds)
Nicely format time in a human-readable format.
int getFirstFreePort(startPort)
Get the first free port, starting from the given port.
  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.
  killPid(pid)
Send the given process a KILL signal.
  mergeImplements(*classes)
Merge the __implements__ tuples of the given classes into one tuple.
  registerPackagePath(packagePath, prefix)
Register a given path as a path that can be imported from.
  termPid(pid)
Send the given process a TERM signal.
  version(binary)
Print a version block for the flumotion binaries.
  waitForKill()
Wait until we get killed by someone else.
  waitPidFile(type, name)
Wait for the given process type and name to have started.
  writePidFile(type, name)
Write a pid file in the run directory, using the given process type and process name for the filename.
  _findPackageCandidates(path, prefix)
I take a directory and return a list of candidate python packages.
  _listRecursively(path)
I'm similar to os.listdir, but I work recursively and only return directories containing python code.

Function Details

addressGetHost(a)

Get the port number 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.

checkPidRunning(pid)

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

checkPortFree(port)

Check if the given local port is free to accept on.
Parameters:
port
           (type=int)
Returns:
boolean

checkRemotePort(host, port)

Check if the given remote host/port is accepting connections.
Parameters:
port
           (type=int)
Returns:
boolean

componentPath(componentName, parentName)

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

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

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. Note that stderr is opened unbuffered, so if it shares a file with stdout then interleaved output may not appear in the order that you expect.

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. Raises a SystemError if this fails, including the given description.

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)

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)
Returns:
a nicely formatted time string.
           (type=string)

getFirstFreePort(startPort)

Get the first free port, starting from the given port.
Parameters:
startPort
           (type=int)
Returns:
int

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.
Returns:
pid of the process, or None.

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.

registerPackagePath(packagePath, prefix='flumotion')

Register a given path as a path that can be imported from. Used to support partition of bundled code or import code from various uninstalled location.
Parameters:
packagePath - path to add under which the module namespaces live.
           (type=string)
prefix - prefix of the packages to be considered
           (type=string)

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)

waitForKill()

Wait until we get killed by someone else.

waitPidFile(type, name)

Wait for the given process type and name to have started. Return the pid if it started successfully, or None if it didn't.

writePidFile(type, name)

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

_findPackageCandidates(path, prefix='flumotion.')

I take a directory and return a list of candidate python packages.
Parameters:
path - the path
           (type=string)

_listRecursively(path)

I'm similar to os.listdir, but I work recursively and only return directories containing python code.
Parameters:
path - the path
           (type=string)

Generated by Epydoc 2.1 on Wed Feb 16 07:22:59 2005 http://epydoc.sf.net