Here's a command-line script wrote that creates and opens a new Komodo project in the current directory:
parser.add_option("-n",
"--name",
dest="name",
help="the name of the new project, eg .kpf.",
default="Foo"
)
(options, args) = parser.parse_args()
def makeProject(fileName):
xml_tpl = """<?xml version="1.0" encoding="UTF-8"?>
<!-- Komodo Project File - DO NOT EDIT -->
<project id="%id%" kpf_version="4" name="%name%.kpf">
<preference-set idref="%id%">
<boolean id="import_live">1</boolean>
</preference-set>
</project>"""
strId = str(uuid4())
projectStr = xml_tpl.replace('%id%', strId).replace('%name%', fileName)
open('./%s' % fileName, 'w').write(projectStr)
if __name__ == '__main__':
fileName = '%s.kpf' % options.name.lower()
root = os.getcwd()
filePath = join(root, fileName)
if exists(filePath):
raise "Error: project file already exists: %s" % fileName
else:
makeProject(fileName)
sh('ko5 %s' % fileName)
#!/usr/bin/python
import os, re
from os.path import join, exists
from uuid import uuid4
from commands import getstatusoutput as sh
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-n",
"--name",
dest="name",
help="the name of the new project, eg .kpf.",
default="Foo"
)
(options, args) = parser.parse_args()
def makeProject(fileName):
xml_tpl = """<?xml version="1.0" encoding="UTF-8"?>
<!-- Komodo Project File - DO NOT EDIT -->
<project id="%id%" kpf_version="4" name="%name%.kpf">
<preference-set idref="%id%">
<boolean id="import_live">1</boolean>
</preference-set>
</project>"""
strId = str(uuid4())
projectStr = xml_tpl.replace('%id%', strId).replace('%name%', fileName)
open('./%s' % fileName, 'w').write(projectStr)
if __name__ == '__main__':
fileName = '%s.kpf' % options.name.lower()
root = os.getcwd()
filePath = join(root, fileName)
if exists(filePath):
raise "Error: project file already exists: %s" % fileName
else:
makeProject(fileName)
sh('ko5 %s' % fileName)On my system I have a couple of additional pieces to help this along:
/Users/jeffg/bin/ko5 which is also on my PATHalias kop="/Users/jeffg/bin/kop.py -n "
here is a php derivative that does most of what i want. i struggled too much with basic python so I switched to php.
is there some way to force open a new window? I don't like my projects comingling in the project drawer :)
please fix the formatting by using a different input format if possible - this looks awful.
<?php
// @file Open folder in Komodo
// Useful as Quicksilver action. See http://www.davideisinger.com/article/custom-quicksilver-actions-in-ruby
$name = time();
$id = uniqid();
$dir = $GLOBALS['argv'][1];
$dirs = explode('/', $dir);
$lastdir = array_pop($dirs);
$kpf = <<<EOD
<?xml version="1.0" encoding="UTF-8"?>
<!-- Komodo Project File - DO NOT EDIT -->
<project id="$id" kpf_version="4" name="$lastdir">
<preference-set idref="$id">
<string id="import_dirname">$dir</string>
<boolean id="import_live">1</boolean>
</preference-set>
</projec>
EOD;
$file = '/tmp/' . "$name.kpf";
file_put_contents($file, $kpf);
$ko5 = '/Users/mw/apps/ko5';
exec("$ko5 $file");
Ok, formatting fixed. Looks good!
There is no command-line switch that I'm aware of that forces a new window, however I do think that's an excellent idea; I've logged this bug:
http://bugs.activestate.com/show_bug.cgi?id=84888
The Komodo team may have clever suggestions for a workaround as well.
--
JeffG
http://www.openkomodo.com/blogs/jeffg