Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: net/test/python_utils.cc

Issue 3366026: Add python_utils to append to python path (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/test/python_utils.h ('k') | net/test/python_utils_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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
OLDNEW
« no previous file with comments | « net/test/python_utils.h ('k') | net/test/python_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698