Package logilab :: Package common :: Module shellutils
[frames] | no frames]

Module shellutils

source code

shell/term utilities, useful to write some python scripts instead of shell
scripts.

:author:    Logilab
:copyright: 2000-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
:license: General Public License version 2 - http://www.gnu.org/licenses

Classes
  Execute
This is a deadlock safe version of popen2 (no stdin), that returns an object with errorlevel, out and err.
  ProgressBar
A simple text progression bar.
  RawInput
Functions
 
acquire_lock(lock_file, max_try=10, delay=10, max_delay=3600)
Acquire a lock represented by a file on the file system
source code
 
chown(path, login=None, group=None)
Same as `os.chown` function but accepting user login or group name as argument.
source code
 
cp(source, destination)
A shell-like cp, supporting wildcards.
source code
 
find(directory, exts, exclude=False, blacklist=('CVS', '.svn', '.hg', 'debian', 'dist', 'build'))
Recursively find files ending with the given extensions from the directory.
source code
 
getlogin()
avoid using os.getlogin() because of strange tty / stdin problems...
source code
 
globfind(directory, pattern, blacklist=('CVS', '.svn', '.hg', 'debian', 'dist', 'build'))
Recursively finds files matching glob `pattern` under `directory`.
source code
 
mv(source, destination, _action=<function move at 0x40767fb4>)
A shell-like mv, supporting wildcards.
source code
 
release_lock(lock_file)
Release a lock represented by a file on the file system.
source code
 
rm(*files)
A shell-like rm, supporting wildcards.
source code
 
unzip(archive, destdir) source code
Variables
  ASK = <logilab.common.shellutils.RawInput object at 0x86f902c>
  STD_BLACKLIST = ('CVS', '.svn', '.hg', 'debian', 'dist', 'build')
  __package__ = 'logilab.common'
Function Details

acquire_lock(lock_file, max_try=10, delay=10, max_delay=3600)

source code 
Acquire a lock represented by a file on the file system

If the process written in lock file doesn't exist anymore, we remove the
lock file immediately
If age of the lock_file is greater than max_delay, then we raise a UserWarning

chown(path, login=None, group=None)

source code 
Same as `os.chown` function but accepting user login or group name as
argument. If login or group is omitted, it's left unchanged.

Note: you must own the file to chown it (or be root). Otherwise OSError is raised.

find(directory, exts, exclude=False, blacklist=('CVS', '.svn', '.hg', 'debian', 'dist', 'build'))

source code 
Recursively find files ending with the given extensions from the directory.

:type directory: str
:param directory:
  directory where the search should start

:type exts: basestring or list or tuple
:param exts:
  extensions or lists or extensions to search

:type exclude: boolean
:param exts:
  if this argument is True, returning files NOT ending with the given
  extensions

:type blacklist: list or tuple
:param blacklist:
  optional list of files or directory to ignore, default to the value of
  `logilab.common.STD_BLACKLIST`

:rtype: list
:return:
  the list of all matching files

getlogin()

source code 
avoid using os.getlogin() because of strange tty / stdin problems
(man 3 getlogin)
Another solution would be to use $LOGNAME, $USER or $USERNAME

globfind(directory, pattern, blacklist=('CVS', '.svn', '.hg', 'debian', 'dist', 'build'))

source code 
Recursively finds files matching glob `pattern` under `directory`.

This is an alternative to `logilab.common.shellutils.find`.

:type directory: str
:param directory:
  directory where the search should start

:type pattern: basestring
:param pattern:
  the glob pattern (e.g *.py, foo*.py, etc.)

:type blacklist: list or tuple
:param blacklist:
  optional list of files or directory to ignore, default to the value of
  `logilab.common.STD_BLACKLIST`

:rtype: iterator
:return:
  iterator over the list of all matching files