OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/test/python_utils.h" |
| 6 |
| 7 #include "base/base_paths.h" |
| 8 #include "base/environment.h" |
| 9 #include "base/file_path.h" |
| 10 #include "base/path_service.h" |
| 11 #include "base/scoped_ptr.h" |
| 12 #include "base/utf_string_conversions.h" |
| 13 |
| 14 const char kPythonPathEnv[] = "PYTHONPATH"; |
| 15 |
| 16 void AppendToPythonPath(const FilePath& dir) { |
| 17 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 18 std::string old_path; |
| 19 std::string dir_path; |
| 20 #if defined(OS_WIN) |
| 21 dir_path = WideToUTF8(dir.value()); |
| 22 #elif defined(OS_POSIX) |
| 23 dir_path = dir.value(); |
| 24 #endif |
| 25 if (!env->GetVar(kPythonPathEnv, &old_path)) { |
| 26 env->SetVar(kPythonPathEnv, dir_path.c_str()); |
| 27 } else if (old_path.find(dir_path) == std::string::npos) { |
| 28 std::string new_path(old_path); |
| 29 #if defined(OS_WIN) |
| 30 new_path.append(";"); |
| 31 #elif defined(OS_POSIX) |
| 32 new_path.append(":"); |
| 33 #endif |
| 34 new_path.append(dir_path.c_str()); |
| 35 env->SetVar(kPythonPathEnv, new_path); |
| 36 } |
| 37 } |
| 38 |
| 39 bool GetPythonRunTime(FilePath* dir) { |
| 40 #if defined(OS_WIN) |
| 41 if (!PathService::Get(base::DIR_SOURCE_ROOT, dir)) |
| 42 return false; |
| 43 *dir = FilePath(FILE_PATH_LITERAL("third_party")) |
| 44 .Append(FILE_PATH_LITERAL("python_24")) |
| 45 .Append(FILE_PATH_LITERAL("python.exe")); |
| 46 #elif defined(OS_POSIX) |
| 47 *dir = FilePath("python"); |
| 48 #endif |
| 49 return true; |
| 50 } |
| 51 |
OLD | NEW |