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

Side by Side Diff: tools/gpu/gpu_tools/file_server.py

Issue 10916227: More polish in prep for CrOS support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for landing Created 8 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
OLDNEW
(Empty)
1 # Copyright (c) 2012 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 import os
5 import subprocess
6
7 class FileServer(object):
8 def __init__(self, path, port=8000):
9 self._server = None
10 self._devnull = None
11 self._path = path
12 self._port = port
13
14 assert os.path.exists(path)
15 assert os.path.isdir(path)
16
17 def __enter__(self):
18 self._devnull = open(os.devnull, 'w')
19 self._server = subprocess.Popen(
20 ['python', '-m', 'SimpleHTTPServer', str(self._port)],
21 cwd=self._path,
22 stdout=self._devnull, stderr=self._devnull)
23 return self
24
25 @property
26 def url(self):
27 return 'http://localhost:%d' % self._port
28
29 def __exit__(self, *args):
30 if self._server:
31 self._server.kill()
32 self._server = None
33 if self._devnull:
34 self._devnull.close()
35 self._devnull = None
36
37 def __del__(self):
38 if self._server:
39 self._server.kill()
40 if self._devnull:
41 self._devnull.close()
42 self._devnull = None
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698