#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
import os
import shlex
import signal
import six
import ssl
import sys
import time
self.__cfg_file = None
self.__debug_features = {}
self.__depot_handle = None
self.__depot_content_root = None
self.__disable_ops = None
self.__file_root = None
self.__writable_root = None
self.__sort_file_max_size = None
self.__ssl_dialog = None
self.__ssl_cert_file = None
self.__ssl_key_file = None
self.__wrapper_start = []
self.__nasty_sleep = None
if wrapper_start:
if env:
#
# Enable special unit-test depot mode in which it doesn't
# do its normal double-fork, providing us good control
# over the process.
#
return
self.__wrapper_start = []
return self.__depot_content_root
return self.__file_root
if auto_create:
try:
except sr.RepositoryExistsError:
# Already exists, nothing to do.
pass
self.__cfg_file = f
return self.__cfg_file
if ":" in host:
# Special syntax needed for IPv6 addresses.
else:
host = "localhost"
if self.__ssl_key_file:
scheme = "https"
else:
scheme = "http"
return self.__writable_root
return self.__sort_file_max_size
self.__disable_ops = None
"""Set the nastiness level of the depot. Also works on
running depots."""
if self.__depot_handle != None:
return self.__nasty_sleep
self.__ssl_key_file = None
self.__ssl_cert_file = None
self.__ssl_dialog = None
try:
"versions/0")
# Disable SSL peer verification, we just want to check
# if the depot is running.
except HTTPError as e:
# Server returns NOT_MODIFIED if catalog is up
# to date
return True
else:
return False
except URLError as e:
return False
return True
""" First, check that the depot process seems to be alive.
Then make a little HTTP request to see if the depot is
responsive to requests """
if self.__depot_handle == None:
return False
if status != None:
return False
return self.__network_ping()
""" Return a boolean value indicating whether a depot process
has been started using this depotcontroller. """
return self.__depot_handle != None
""" Return the equivalent command line invocation (as an
array) for the depot as currently configured. """
args = []
# The depot may fork off children of its own, so we place
# them all together in a process group. This allows us to
# nuke everything later on.
if self.__file_root != None:
if self.__readonly:
if self.__refresh_index:
if self.__add_content:
if self.__exit_ready:
if self.__cfg_file:
if self.__ssl_cert_file:
if self.__ssl_key_file:
if self.__ssl_dialog:
if self.__debug_features:
if self.__disable_ops:
if self.__nasty_sleep:
if self.__writable_root:
# Always log access and error information.
return args
"""'env_arg' can be a dictionary of additional os.environ
entries to use when starting the depot."""
raise DepotStateException("Depot already starting or "
"running")
# XXX what about stdin and stdout redirection?
if self.__network_ping():
raise DepotStateException("A depot (or some " +
"other network process) seems to be " +
# Unbuffer is only allowed in binary mode.
# Use shlex to re-parse args.
if self.__depot_handle == None:
raise DepotStateException("Could not start Depot")
try:
if self.__refresh_index:
return
sleeptime = 0.0
check_interval = 0.20
if rc is not None:
err = ""
errf:
raise DepotStateException("Depot exited "
"with exit code {0:d} unexpectedly "
"while starting. Output follows:\n"
break
raise DepotStateException("Depot did not respond to "
"repeated attempts to make contact")
except KeyboardInterrupt:
if self.__depot_handle:
raise
try:
sleeptime = 0.05
rc = None
while sleeptime <= 10.0:
if rc is not None:
break
sleeptime *= 2
return True
else:
return False
except KeyboardInterrupt:
if self.__depot_handle:
raise
if self.__depot_handle == None:
# XXX might want to remember and return saved
# exit status
return 0
"""kill the depot; letting it live for
a little while helps get reliable death"""
if self.__depot_handle == None:
# XXX might want to remember and return saved
# exit status
return 0
try:
finally:
# By sticking in this finally: block we ensure that
# even if the kill gets ctrl-c'd, we'll at least take
# a good final whack at the depot by killing -9 its
# process group.
try:
except OSError:
pass
self.__depot_handle = None
raise DepotStateException("Depot already stopped")
dc = DepotController()
try:
except OSError:
pass
print("{0:>4d}: Starting Depot... ({1})".format(
try:
pass
if status is None:
elif status == 0:
elif status < 0:
else:
print()
print(f.read())
f.close()
except KeyboardInterrupt:
print("\nKeyboard Interrupt: Cleaning up Depots...")
raise
if __name__ == "__main__":
try:
except KeyboardInterrupt:
pass
print("\nDone")