Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install capn

How to install capn

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install capn
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.0.4 Failed View build log
1.0.2 Failed View build log
1.0rc1 Failed View build log
Windows (64-bit)
1.0.4 Available View build log
1.0.2 Available View build log
1.0rc1 Available View build log
Mac OS X (10.5+)
1.0.4 Available View build log
1.0.2 Available View build log
1.0rc1 Available View build log
Linux (32-bit)
1.0.4 Available View build log
1.0.2 Available View build log
1.0rc1 Available View build log
Linux (64-bit)
1.0.4 Available View build log
1.0.2 Available View build log
1.0rc1 Available View build log
 
Dependencies
Depended by
Imports
Lastest release
version 1.0.4 on Apr 7th, 2011

capn is a package that provides hooks when the current-working-directory changes.

### Installation

$ sudo pip install python-yaml $ sudo python setup.py install $ touch ~/.capnhooks

### Configuration

capn uses a simple YAML file for specifying paths and their hooks. As a quick example, consider the following:

settings:

default_type: path external_hooks:

System Message: ERROR/3 (<string>, line 20)

Unexpected indentation.
  • ~/.otherhooks
hooks:
  • path: /home type: tree enter:

    System Message: ERROR/3 (<string>, line 25)

    Unexpected indentation.

    • echo entering /home

    System Message: WARNING/2 (<string>, line 26)

    Block quote ends without a blank line; unexpected unindent.

    exit:
    • echo exiting /home
    • echo /home waves goodbye
  • path: ~/ enter:

    System Message: ERROR/3 (<string>, line 32)

    Unexpected indentation.

    • echo entering ~/

    System Message: WARNING/2 (<string>, line 33)

    Block quote ends without a blank line; unexpected unindent.

    exit:
    • echo exiting ~/

The above establish enter and exit hooks for the two listed directories. As you change directories you should see output indicating each hook's execution. You'll notice that the /home path has a type key with the value tree. There are two types of hooks; path, which is the default, only triggers for that absolute path. tree hooks will trigger when you enter or leave the tree below the specified path. Moving between child-paths below the tree does _not_ trigger the hooks. For example, moving from / -> /home would trigger the enter hook. Moving from /home -> ~/ would not trigger the exit hook.

Generally the commands specified in the hooks will be the names of shell scripts not single shell commands.

The first section of the configuration currently has two available settings:

  • default_type: either path or tree. If setting is not specified, path will be used.
  • external_hooks: a list of paths to other YAML files containing additional hooks. Such files should resemble the 'hooks' section of the above example configuration.

### Usage

After installing capn you will need to source:

$ source capn

If you no longer wish to have the hooks activated:

$ unhook

### API

add_external_hook(filename, path, hooktype=DEFAULT_TYPE,
enter=[], exit=[]):

Currently capn has a minimal API with a single function that is used to manage programmatically generated external hook files. See the example below:

>>>from capn.config import add_external_hook >>>filename = "~/.otherhooks" >>>path = ~/projects/foo/bar >>>hooktype = 'tree' >>>enter = ['source ~/projects/foo/bar/bin/activate'] >>>exit = ['deactivate'] >>>add_external_hook(filename, path, hooktype=hooktype, ... enter=enter, exit=exit) >>>

The above will add a hook to auto de/activate the python-virtualenv whenever the shell is inside the project directory to the file "~/.otherhooks". You will then need to add the filename to the external_hooks list in the "~/.capnhooks" configuration file.

Subscribe to package updates

Last updated Apr 7th, 2011

Download Stats

Last month:5

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.