// Copyright (c) 2014 The Axiom Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import AxiomError from 'axiom/core/error';

import environment from 'axiom_shell/environment';

import PnaclCommand from 'axiom_pnacl/pnacl_command';

// @note ExecuteContext from 'axiom/bindings/fs/execute_context'

var createCommand = function(commandName, sourceUrl, tarFilename) {
  var command = new PnaclCommand(commandName, sourceUrl, tarFilename);
  return command.run.bind(command);
};

export var executables = function(sourceUrl) {
  return {
    'curl(@)': createCommand('curl', sourceUrl),
    'nano(@)': createCommand('nano', sourceUrl, 'nano.tar'),
    'nethack(@)': createCommand('nethack', sourceUrl, 'nethack.tar'),
    'python(@)': createCommand('python', sourceUrl, 'pydata_pnacl.tar'),
    'unzip(@)': createCommand('unzip', sourceUrl),
    'vim(@)': createCommand('vim', sourceUrl, 'vim.tar'),
  };
};

export default executables;

@@ -406,24 +406,17 @@
 unction(
-commandN
+n
 ame, sou
@@ -415,32 +415,36 @@
 ame, sourceUrl, 
+opt_
 tarFilename) %7B%0A 
@@ -438,16 +438,25 @@
 Filename
+, opt_env
 ) %7B%0A  va
@@ -488,16 +488,9 @@
 and(
-commandN
+n
 ame,
@@ -501,16 +501,20 @@
 rceUrl, 
+opt_
 tarFilen
@@ -516,16 +516,25 @@
 Filename
+, opt_env
 );%0A  ret
@@ -818,24 +818,413 @@
 'python(@)':
+%0A        // Note: We set PYTHONHOME to '/' so that the python library files%0A        // are loaded from '/lib/python2.7', which is the prefix path used in%0A        // 'pydata_pnacl.tar'. By default, python set PYTHONHOME to be the%0A        // prefix of the executable from arg%5B0%5D. This conflicts with the way%0A        // we set arg%5B0%5D to tell pnacl to where to load the .tar file from.%0A       
  createComma
@@ -1261,24 +1261,66 @@
 a_pnacl.tar'
+, %7B%0A          '$PYTHONHOME': '/'%0A        %7D
 ),%0A    'unzi

Fix running python by setting PYTHONHOME to '/'.