depot.py revision 445
#
# 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
#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# pkg.depotd - package repository daemon
# XXX The prototype pkg.depotd combines both the version management server that
# answers to pkgsend(1) sessions and the HTTP file server that answers to the
# various GET operations that a pkg(1) client makes. This split is expected to
# be made more explicit, by constraining the pkg(1) operations such that they
# operations, and must manipulate the various state files--catalogs, in
# particular--such that the pkg(1) pull client can operately accurately with
# XXX We should support simple "last-modified" operations via HEAD queries.
# XXX Although we pushed the evaluation of next-version, etc. to the pull
# client, we should probably provide a query API to do same on the server, for
# dumb clients (like a notification service).
# The default authority for the depot.
AUTH_DEFAULT = "opensolaris.org"
# The default repository path.
REPO_PATH_DEFAULT = "/var/pkg/repo"
# The default port to serve data from.
PORT_DEFAULT = 80
# The minimum number of threads allowed.
THREADS_MIN = 1
# The default number of threads to start.
THREADS_DEFAULT = 10
# The maximum number of threads that can be started.
THREADS_MAX = 100
# The default server socket timeout in seconds. We want this to be longer than
# the normal default of 10 seconds to accommodate clients with poor quality
# connections.
# Whether modify operations should be allowed.
# Whether the repository catalog should be rebuilt on startup.
# Whether the indexes should be rebuilt
import getopt
import os
import sys
try:
import cherrypy
raise ImportError
raise ImportError
except ImportError:
print """cherrypy 3.0.3 or greater (but less than 3.1.0) is """ \
"""required to use this program."""
def usage():
print """\
Usage: /usr/lib/pkg.depotd [--readonly] [--rebuild] [-d repo_dir] [-p port]
[-s threads] [-t socket_timeout]
--readonly Read-only operation; modifying operations disallowed
--rebuild Re-build the catalog from pkgs in depot
Cannot be used with --readonly
"""
class OptionError(Exception):
"""Option exception. """
if __name__ == "__main__":
else:
try:
["readonly", "rebuild", "refresh-index"])
raise OptionError, "Each option may only be " \
"specified once."
else:
if opt == "-n":
elif opt == "-d":
elif opt == "-p":
elif opt == "-s":
if threads < THREADS_MIN:
raise OptionError, \
"minimum value is %d" % THREADS_MIN
if threads > THREADS_MAX:
raise OptionError, \
"maximum value is %d" % THREADS_MAX
elif opt == "-t":
elif opt == "--readonly":
elif opt == "--rebuild":
elif opt == "--refresh-index":
# Note: This argument is for internal use
# only. It's used when pkg.depotd is reexecing
# itself and needs to know that's the case.
# This flag is purposefully omitted in usage.
# The supported way to forcefully reindex is to
# kill any pkg.depot using that directory,
# remove the index directory, and restart the
# pkg.depot process. The index will be rebuilt
# automatically on startup.
except getopt.GetoptError, e:
print "pkg.depotd: %s" % e.msg
usage()
except OptionError, e:
print "pkg.depotd: option: %s -- %s" % (opt, e)
usage()
except (ArithmeticError, ValueError):
print "pkg.depotd: illegal option value: %s specified " \
usage()
print "--refresh-index cannot be used with --rebuild"
usage()
print "--readonly cannot be used with --rebuild"
usage()
print "--readonly cannot be used with --refresh-index"
usage()
# If the program is going to reindex, the port is irrelevant since
# the program will not bind to a port.
if not reindex:
if not available:
print "pkg.depotd: unable to bind to the specified " \
try:
except KeyError:
pass
if rebuild:
if readonly:
try:
except EnvironmentError, e:
print "pkg.depotd: an error occurred while trying to " \
"initialize the depot repository directory " \
"structures:\n%s" % e
if reindex:
try:
except rc.InvalidAttributeValueError, e:
emsg("pkg.depotd: repository.conf error: %s" % e)
# We have to override cherrypy's default response_class so that we
# have access to the write() callable to stream data directly to the
# client.
"environment": "production",
"checker.on": True,
"log.screen": True,
"server.socket_port": port,
"server.thread_pool": threads,
"server.socket_timeout": socket_timeout
})
conf = {
"/robots.txt": {
"tools.staticfile.on": True,
"robots.txt")
},
"/static": {
"tools.staticdir.on": True,
"tools.staticdir.dir": ""
}
}
try:
except:
print "pkg.depotd: unknown error starting depot, illegal " \
"option value specified?"
usage()