



I use the following Komodo JavaScript macro for kicking off a remote debugging session for a remote python file I have opened in Komodo, opened usually over SFTP or SCP. It will kick off the remote dbgp debugger and connect to your running Komodo.
Dependancies:
* Requires ssh on your local system
* Requires dbgp commands on your shell path (i.e. pydbgp).
Note: You need to set the hostname initially, as I could not find a good way to grab the local hostname from javascript.
var hostname = connection.server;
var username = connection.username;
var sshPart = "ssh " + username + "@" + hostname;
var filepath = komodo.document.file.path;
var dbgpManagerSvc = Components.classes["@activestate.com/koDBGPManager;1"].getService(Components.interfaces.koIDBGPManager);
// XXX - Customize your hostname below!
// Requires pydbgp setup in your remote path
var cmd = "pydbgp -d set_local_hostname:" + dbgpManagerSvc.port + ' ' + filepath;
// I needed to explicitly run my profile in order to setup the
// appropriate dbgp settings, example below:
//var cmd = ". ./.profile && pydbgp -d set_local_hostname:" + dbgpManagerSvc.port + ' ' + filepath;
// We have enough info, run the command
var userEnvSvc = Components.classes["@activestate.com/koUserEnviron;1"].
getService(Components.interfaces.koIUserEnviron);
var env = userEnvSvc.GetEncodedEnvironment();
ko.run.runCommand(window,
sshPart + ' "' + cmd + '"',
"", // cwd (%D == directory path of file)
env, // env
false, // insertOutput
false, // operateOnSelection
false, // doNotOpenOutputWindow
'command-output-window', // runIn
0, // parseOutput
'', // parseRegex
0, // showParsedOutputList
false, // Clear output window before starting
null); // termination callback js function
}
komodo.view.scintilla.focus();
runRemoteDebug();
function runRemoteDebug() {
// Bit of a hack to get the info we need
var RFService = Components.classes["@activestate.com/koRemoteConnectionService;1"].getService(Components.interfaces.koIRemoteConnectionService)
try {
var connection = RFService.getConnectionUsingUri(komodo.document.file.URI);
} catch (ex) {
alert("Currently opened file is not a supported remote file");
return;
}
var hostname = connection.server;
var username = connection.username;
var sshPart = "ssh " + username + "@" + hostname;
var filepath = komodo.document.file.path;
var dbgpManagerSvc = Components.classes["@activestate.com/koDBGPManager;1"].getService(Components.interfaces.koIDBGPManager);
// XXX - Customize your hostname below!
// Requires pydbgp setup in your remote path
var cmd = "pydbgp -d set_local_hostname:" + dbgpManagerSvc.port + ' ' + filepath;
// I needed to explicitly run my profile in order to setup the
// appropriate dbgp settings, example below:
//var cmd = ". ./.profile && pydbgp -d set_local_hostname:" + dbgpManagerSvc.port + ' ' + filepath;
// We have enough info, run the command
var userEnvSvc = Components.classes["@activestate.com/koUserEnviron;1"].
getService(Components.interfaces.koIUserEnviron);
var env = userEnvSvc.GetEncodedEnvironment();
ko.run.runCommand(window,
sshPart + ' "' + cmd + '"',
"", // cwd (%D == directory path of file)
env, // env
false, // insertOutput
false, // operateOnSelection
false, // doNotOpenOutputWindow
'command-output-window', // runIn
0, // parseOutput
'', // parseRegex
0, // showParsedOutputList
false, // Clear output window before starting
null); // termination callback js function
}
komodo.view.scintilla.focus();
runRemoteDebug();Cheers,
Todd
Works well, thanks!
I suppose this functionality may be rolled into the "normal" Debug menu eventually?
Feature requests:
A) Connection password manager integration
B) Allow arguments to the script
C) Ability to set 'default' file to run
Workarounds
A) (untested) Use passwordless ssh keys, not always as practical
B) hardcode it as part of the 'cmd' variable in the macro
C) Swap to the correct file before running macro each time
Thanks again.
~
Yes, this may eventually be rolled into the Komodo debug menu (likely after Komodo 4.2) and be integrated to use the existing Komodo connection manager. The ability is there currently for this, but the API's and architecture need work to make this easily accessible.
Cheers,
Todd
Things to look forward to. Thanks for the quick pick-me-up!
~