virtualenvwrapper / virtualenvwrapper / project.py

#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
#
"""virtualenvwrapper.project
"""

import logging
import os

import pkg_resources

from virtualenvwrapper.user_scripts import make_hook, run_global

log = logging.getLogger(__name__)

GLOBAL_HOOKS = [
    # mkproject
    ("premkproject",
     "This hook is run after a new project is created and before it is activated."),
    ("postmkproject",
     "This hook is run after a new project is activated."),

    # rmproject
    ("prermproject",
     "This hook is run before a project is deleted."),
    ("postrmproject",
     "This hook is run after a project is deleted."),
    ]

def initialize(args):
    """Set up user hooks
    """
    for filename, comment in GLOBAL_HOOKS:
        make_hook(os.path.join('$VIRTUALENVWRAPPER_HOOK_DIR', filename), comment)
    return


def pre_mkproject(args):
    log.debug('pre_mkproject %s', str(args))
    envname=args[0]
    run_global('premkproject', *args)
    return

def post_mkproject_source(args):
    return """
#
# Run user-provided scripts
#
[ -f "$WORKON_HOME/postmkproject" ] && source "$WORKON_HOME/postmkproject"
"""

def post_activate_source(args):
    return """
#
# Change to the project directory
#
[ -f "$VIRTUAL_ENV/.project" ] && cd "$(cat \"$VIRTUAL_ENV/.project\")"
"""
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.