# This is copied from <python/mozperftest/mozperftest/utils.py>. It's copied # instead of imported since mozperfest is Python 3, and this file is # (currently) Python 2. def _install_package(virtualenv_manager, package): from pip._internal.req.constructors import install_req_from_line
req = install_req_from_line(package)
req.check_if_exists(use_user_site=False) # already installed, check if it's in our venv if req.satisfied_by isnotNone:
venv_site_lib = os.path.abspath(
os.path.join(virtualenv_manager.bin_path, "..", "lib")
)
site_packages = os.path.abspath(req.satisfied_by.location) if site_packages.startswith(venv_site_lib): # already installed in this venv, we can skip return
class OutputHandler(object): def __init__(self):
self.port = None
self.port_event = threading.Event()
def __call__(self, line):
line = line.rstrip(b"\r\n") ifnot line.strip(): return
line = line.decode("utf-8", errors="replace") # Print the output we received so we have useful logs if a test fails.
print(line)
try:
data = json.loads(line) except ValueError: return
if isinstance(data, dict) and"action"in data: # Retrieve the port number for the proxy server from the logs of # our subprocess.
m = re.match(r"Proxy running on port (\d+)", data.get("message", "")) if m:
self.port = m.group(1)
self.port_event.set()
for line in p.stdout:
output_handler(line) if output_handler.port_event.is_set(): break
output_handler.finished() # The first time we run mozproxy, we need to fetch mitmproxy, which can # take a while... assert output_handler.port_event.wait(120) isTrue # Give mitmproxy a bit of time to start up so we can verify that it's # actually running before we kill mozproxy.
time.sleep(5)
_kill_mozproxy(p.pid)
for line in p.stdout:
output_handler(line) if output_handler.port_event.is_set(): break
output_handler.finished() # The first time we run mozproxy, we need to fetch mitmproxy, which can # take a while... assert output_handler.port_event.wait(120) isTrue # Give mitmproxy a bit of time to start up so we can verify that it's # actually running before we kill mozproxy.
time.sleep(5)
_kill_mozproxy(p.pid)
for line in p.stdout:
output_handler(line) if output_handler.port_event.is_set(): break
output_handler.finished() try: # The first time we run mozproxy, we need to fetch mitmproxy, which can # take a while... assert output_handler.port_event.wait(120) isTrue # Give mitmproxy a bit of time to start up so we can verify that it's # actually running before we kill mozproxy.
time.sleep(5)
_kill_mozproxy(p.pid)
for line in p.stdout:
output_handler(line) if output_handler.port_event.is_set(): break
output_handler.finished() # The first time we run mozproxy, we need to fetch mitmproxy, which can # take a while... assert output_handler.port_event.wait(120) isTrue # Give mitmproxy a bit of time to start up so we can verify that it's # actually running before we kill mozproxy.
time.sleep(5)
_kill_mozproxy(p.pid)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.