Created
July 2, 2010 04:42
-
-
Save unbracketed/460939 to your computer and use it in GitHub Desktop.
Util for generating a Komodo project file that works with virtualenv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A sample utility for customizing virtualenv creation based | |
on the postmkvirtualenv hook provided by virtualenvwrapper. | |
This script will generate a Komodo project file suitable for | |
use in Komodo Edit (and presumably Komodo IDE). The project preferences | |
are automatically customized so that the Python path contains the | |
new virtualenv's site-packages directory. | |
(Project Properties -> Languages -> Python in the GUI) | |
Since Komodo keeps track of which open files belong to which projects, | |
you can keep multiple projects open and the autocomplete should work | |
appropriately for each file (appropriately meaning using the correct | |
virtualenv paths) | |
This tool also creates a blank default project directory to go with | |
the virtualenv. An alternative could be to run django-admin startproject | |
at this point. | |
This tool can be integrated with virtualenvwrapper by dropping something | |
like the following into your postmkvirtualenv file: | |
python /path/to/this/file.py | |
""" | |
import os | |
from uuid import uuid4 | |
PROJECT_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?> | |
<!-- Komodo Project File - DO NOT EDIT --> | |
<project id="%(proj_uuid)s" kpf_version="4" name="%(proj_name)s.kpf"> | |
<livefolder id="%(folder_uuid)s" idref="%(proj_uuid)s" name="%(proj_name)s" url="file://%(proj_path)s"> | |
</livefolder> | |
<preference-set idref="%(proj_uuid)s"> | |
<boolean id="import_live">0</boolean> | |
<string id="pythonExtraPaths">%(site_pkgs_path)s</string> | |
</preference-set> | |
</project>""" | |
#create the project UUID | |
proj_uuid = str(uuid4()) | |
folder_uuid = str(uuid4()) | |
site_pkgs_path = os.path.join(os.environ['VIRTUAL_ENV'], 'lib', 'python2.6', 'site-packages') | |
_, proj_name = os.path.split(os.environ['VIRTUAL_ENV']) | |
proj_root = '/home/brian/proj/' | |
proj_path = os.path.join(proj_root, proj_name) | |
os.mkdir(proj_path) | |
with open('%s.kpf' % proj_name, 'w') as f: | |
f.write(PROJECT_TEMPLATE % {'proj_uuid':proj_uuid, | |
'folder_uuid': folder_uuid, | |
'site_pkgs_path':site_pkgs_path, | |
'proj_name': proj_name, | |
'proj_path': proj_path}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment