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

Side by Side Diff: third_party/typ/typ/host.py

Issue 664123005: Roll typ to v0.8.6 / re25b780b0b147580ef248c212b238446264d9d78 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « third_party/typ/typ/fakes/host_fake.py ('k') | third_party/typ/typ/runner.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 Dirk Pranke. All rights reserved. 1 # Copyright 2014 Dirk Pranke. All rights reserved.
2 # 2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); 3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License. 4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at 5 # You may obtain a copy of the License at
6 # 6 #
7 # http://www.apache.org/licenses/LICENSE-2.0 7 # http://www.apache.org/licenses/LICENSE-2.0
8 # 8 #
9 # Unless required by applicable law or agreed to in writing, software 9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, 10 # distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 17 matching lines...) Expand all
28 else: # pragma: python3 28 else: # pragma: python3
29 # pylint: disable=E0611 29 # pylint: disable=E0611
30 assert sys.version_info.major == 3 30 assert sys.version_info.major == 3
31 from urllib.request import urlopen, Request # pylint: disable=F0401,E0611 31 from urllib.request import urlopen, Request # pylint: disable=F0401,E0611
32 32
33 33
34 class Host(object): 34 class Host(object):
35 python_interpreter = sys.executable 35 python_interpreter = sys.executable
36 is_python3 = bool(sys.version_info.major == 3) 36 is_python3 = bool(sys.version_info.major == 3)
37 37
38 pathsep = os.pathsep
38 sep = os.sep 39 sep = os.sep
39 env = os.environ 40 env = os.environ
40 41
41 _orig_stdout = sys.stdout 42 _orig_stdout = sys.stdout
42 _orig_stderr = sys.stderr 43 _orig_stderr = sys.stderr
43 44
44 def __init__(self): 45 def __init__(self):
45 self.logger = logging.getLogger() 46 self.logger = logging.getLogger()
46 self._orig_logging_handlers = None 47 self._orig_logging_handlers = None
47 self.stdout = sys.stdout 48 self.stdout = sys.stdout
(...skipping 22 matching lines...) Expand all
70 stderr=subprocess.PIPE, stdin=stdin_pipe, 71 stderr=subprocess.PIPE, stdin=stdin_pipe,
71 env=env) 72 env=env)
72 if stdin_pipe: 73 if stdin_pipe:
73 proc.stdin.write(stdin.encode('utf-8')) 74 proc.stdin.write(stdin.encode('utf-8'))
74 stdout, stderr = proc.communicate() 75 stdout, stderr = proc.communicate()
75 76
76 # pylint type checking bug - pylint: disable=E1103 77 # pylint type checking bug - pylint: disable=E1103
77 return proc.returncode, stdout.decode('utf-8'), stderr.decode('utf-8') 78 return proc.returncode, stdout.decode('utf-8'), stderr.decode('utf-8')
78 79
79 def call_inline(self, argv, env=None): 80 def call_inline(self, argv, env=None):
81 if isinstance(self.stdout, _TeedStream): # pragma: no cover
82 ret, out, err = self.call(argv, env)
83 self.print_(out, end='')
84 self.print_(err, end='', stream=self.stderr)
85 return ret
80 return subprocess.call(argv, stdin=self.stdin, stdout=self.stdout, 86 return subprocess.call(argv, stdin=self.stdin, stdout=self.stdout,
81 stderr=self.stderr, env=env) 87 stderr=self.stderr, env=env)
82 88
83 def chdir(self, *comps): 89 def chdir(self, *comps):
84 return os.chdir(self.join(*comps)) 90 return os.chdir(self.join(*comps))
85 91
86 def cpu_count(self): 92 def cpu_count(self):
87 return multiprocessing.cpu_count() 93 return multiprocessing.cpu_count()
88 94
89 def dirname(self, *comps): 95 def dirname(self, *comps):
(...skipping 29 matching lines...) Expand all
119 return os.path.isfile(os.path.join(*comps)) 125 return os.path.isfile(os.path.join(*comps))
120 126
121 def join(self, *comps): 127 def join(self, *comps):
122 return os.path.join(*comps) 128 return os.path.join(*comps)
123 129
124 def maybe_mkdir(self, *comps): 130 def maybe_mkdir(self, *comps):
125 path = self.abspath(self.join(*comps)) 131 path = self.abspath(self.join(*comps))
126 if not self.exists(path): 132 if not self.exists(path):
127 os.makedirs(path) 133 os.makedirs(path)
128 134
135 def mktempfile(self, delete=True):
136 return tempfile.NamedTemporaryFile(delete=delete)
137
129 def mkdtemp(self, **kwargs): 138 def mkdtemp(self, **kwargs):
130 return tempfile.mkdtemp(**kwargs) 139 return tempfile.mkdtemp(**kwargs)
131 140
132 def mtime(self, *comps): 141 def mtime(self, *comps):
133 return os.stat(self.join(*comps)).st_mtime 142 return os.stat(self.join(*comps)).st_mtime
134 143
135 def print_(self, msg='', end='\n', stream=None): 144 def print_(self, msg='', end='\n', stream=None):
136 stream = stream or self.stdout 145 stream = stream or self.stdout
137 stream.write(str(msg) + end) 146 stream.write(str(msg) + end)
138 stream.flush() 147 stream.flush()
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 self.truncate(0) 277 self.truncate(0)
269 self.capturing = True 278 self.capturing = True
270 self.diverting = divert 279 self.diverting = divert
271 280
272 def restore(self): 281 def restore(self):
273 msg = self.getvalue() 282 msg = self.getvalue()
274 self.truncate(0) 283 self.truncate(0)
275 self.capturing = False 284 self.capturing = False
276 self.diverting = False 285 self.diverting = False
277 return msg 286 return msg
OLDNEW
« no previous file with comments | « third_party/typ/typ/fakes/host_fake.py ('k') | third_party/typ/typ/runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698