src/depot.py
author Brock Pytlik <bpytlik@sun.com>
Fri, 25 Jul 2008 13:56:38 -0700
changeset 429 6c9cbb6e6600
parent 428 e011e45fe2cd
child 445 76b03dd5a4ac
permissions -rwxr-xr-x
983 pkg search returns just one action per package/token-type combo 1949 pkg search is inordinately slow 2122 catalog file update needs to be atomic with respect to both other updates and reads
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
409
713e20963dc2 2314 shebang lines should use minimum python version
Shawn Walker <swalker@opensolaris.org>
parents: 404
diff changeset
     1
#!/usr/bin/python2.4
20
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
     2
#
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
     3
# CDDL HEADER START
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
     4
#
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
     5
# The contents of this file are subject to the terms of the
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
     6
# Common Development and Distribution License (the "License").
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
     7
# You may not use this file except in compliance with the License.
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
     8
#
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    11
# See the License for the specific language governing permissions
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    12
# and limitations under the License.
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    13
#
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    19
#
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    20
# CDDL HEADER END
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    21
#
260
a1b77322abb2 255 Symbolic HTTP response codes should be used
Shawn Walker <swalker@opensolaris.org>
parents: 258
diff changeset
    22
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
20
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    23
# Use is subject to license terms.
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    24
#
e5e53bc1c4d1 Cleaned up the build and install process. Turn the pkg directory into a
Danek Duvall <danek.duvall@sun.com>
parents: 14
diff changeset
    25
22
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 21
diff changeset
    26
# pkg.depotd - package repository daemon
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    27
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    28
# XXX The prototype pkg.depotd combines both the version management server that
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    29
# answers to pkgsend(1) sessions and the HTTP file server that answers to the
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    30
# various GET operations that a pkg(1) client makes.  This split is expected to
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    31
# be made more explicit, by constraining the pkg(1) operations such that they
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    32
# can be served as a typical HTTP/HTTPS session.  Thus, pkg.depotd will reduce
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    33
# to a special purpose HTTP/HTTPS server explicitly for the version management
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    34
# operations, and must manipulate the various state files--catalogs, in
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    35
# particular--such that the pkg(1) pull client can operately accurately with
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    36
# only a basic HTTP/HTTPS server in place.
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    37
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    38
# XXX We should support simple "last-modified" operations via HEAD queries.
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    39
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    40
# XXX Although we pushed the evaluation of next-version, etc. to the pull
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    41
# client, we should probably provide a query API to do same on the server, for
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    42
# dumb clients (like a notification service).
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    43
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    44
# The default authority for the depot.
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    45
AUTH_DEFAULT = "opensolaris.org"
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    46
# The default repository path.
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    47
REPO_PATH_DEFAULT = "/var/pkg/repo"
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    48
# The default port to serve data from.
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    49
PORT_DEFAULT = 80
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    50
# The minimum number of threads allowed.
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    51
THREADS_MIN = 1
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    52
# The default number of threads to start.
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    53
THREADS_DEFAULT = 10
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    54
# The maximum number of threads that can be started.
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    55
THREADS_MAX = 100
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    56
# The default server socket timeout in seconds. We want this to be longer than
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    57
# the normal default of 10 seconds to accommodate clients with poor quality
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    58
# connections.
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    59
SOCKET_TIMEOUT_DEFAULT = 60
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    60
# Whether modify operations should be allowed.
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    61
READONLY_DEFAULT = False
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    62
# Whether the repository catalog should be rebuilt on startup.
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    63
REBUILD_DEFAULT = False
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
    64
# Whether the indexes should be rebuilt
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
    65
REINDEX_DEFAULT = False
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    66
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 25
diff changeset
    67
import getopt
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    68
import os
52
d7c452ef7ae1 Sanitize getopt exception handling
Danek Duvall <danek.duvall@sun.com>
parents: 50
diff changeset
    69
import sys
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    70
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    71
try:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    72
        import cherrypy
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    73
        version = cherrypy.__version__.split('.')
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    74
        if map(int, version) < [3, 0, 3]:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    75
                raise ImportError
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    76
        elif map(int, version) >= [3, 1, 0]:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    77
                raise ImportError
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    78
except ImportError:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    79
        print """cherrypy 3.0.3 or greater (but less than 3.1.0) is """ \
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    80
            """required to use this program."""
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    81
        sys.exit(2)
22
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 21
diff changeset
    82
114
e21e9aa690ad draft manual pages, index page cleanup
Stephen Hahn <sch@sun.com>
parents: 106
diff changeset
    83
import pkg.server.face as face
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 25
diff changeset
    84
import pkg.server.config as config
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    85
import pkg.server.depot as depot
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    86
import pkg.server.repository as repo
428
e011e45fe2cd 2239 repository attribute system needed
Shawn Walker <shawn.walker@sun.com>
parents: 409
diff changeset
    87
import pkg.server.repositoryconfig as rc
e011e45fe2cd 2239 repository attribute system needed
Shawn Walker <shawn.walker@sun.com>
parents: 409
diff changeset
    88
from pkg.misc import port_available, emsg
23
51b8b48fea32 begin server source reorganization
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    89
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 25
diff changeset
    90
def usage():
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 25
diff changeset
    91
        print """\
157
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
    92
Usage: /usr/lib/pkg.depotd [--readonly] [--rebuild] [-d repo_dir] [-p port]
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    93
           [-s threads] [-t socket_timeout]
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    94
135
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 119
diff changeset
    95
        --readonly      Read-only operation; modifying operations disallowed
157
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
    96
        --rebuild       Re-build the catalog from pkgs in depot
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 25
diff changeset
    97
"""
135
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 119
diff changeset
    98
        sys.exit(2)
14
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents: 3
diff changeset
    99
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   100
class OptionError(Exception):
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   101
        """Option exception. """
14
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents: 3
diff changeset
   102
404
e5329e84b9a8 2331 depot command-line parsing errors cause traceback
Shawn Walker <swalker@opensolaris.org>
parents: 386
diff changeset
   103
        def __init__(self, *args):
e5329e84b9a8 2331 depot command-line parsing errors cause traceback
Shawn Walker <swalker@opensolaris.org>
parents: 386
diff changeset
   104
                Exception.__init__(self, *args)
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   105
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   106
if __name__ == "__main__":
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   107
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   108
        port = PORT_DEFAULT
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   109
        threads = THREADS_DEFAULT
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   110
        socket_timeout = SOCKET_TIMEOUT_DEFAULT
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   111
        readonly = READONLY_DEFAULT
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   112
        rebuild = REBUILD_DEFAULT
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   113
        reindex = REINDEX_DEFAULT
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 239
diff changeset
   114
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   115
        if "PKG_REPO" in os.environ:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   116
                repo_path = os.environ["PKG_REPO"]
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   117
        else:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   118
                repo_path = REPO_PATH_DEFAULT
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   119
54
a0c517c20618 Don't throw an exception if the depot can't find a file
Danek Duvall <danek.duvall@sun.com>
parents: 52
diff changeset
   120
        try:
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   121
                parsed = set()
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   122
                opts, pargs = getopt.getopt(sys.argv[1:], "d:np:s:t:",
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   123
                    ["readonly", "rebuild", "refresh-index"])
135
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 119
diff changeset
   124
                for opt, arg in opts:
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   125
                        if opt in parsed:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   126
                                raise OptionError, "Each option may only be " \
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   127
                                    "specified once."
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   128
                        else:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   129
                                parsed.add(opt)
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   130
135
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 119
diff changeset
   131
                        if opt == "-n":
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 119
diff changeset
   132
                                sys.exit(0)
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 119
diff changeset
   133
                        elif opt == "-d":
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   134
                                repo_path = arg
135
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 119
diff changeset
   135
                        elif opt == "-p":
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 119
diff changeset
   136
                                port = int(arg)
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   137
                        elif opt == "-s":
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   138
                                threads = int(arg)
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   139
                                if threads < THREADS_MIN:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   140
                                        raise OptionError, \
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   141
                                            "minimum value is %d" % THREADS_MIN
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   142
                                if threads > THREADS_MAX:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   143
                                        raise OptionError, \
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   144
                                            "maximum value is %d" % THREADS_MAX
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   145
                        elif opt == "-t":
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   146
                                socket_timeout = int(arg)
135
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 119
diff changeset
   147
                        elif opt == "--readonly":
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   148
                                readonly = True
157
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
   149
                        elif opt == "--rebuild":
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   150
                                rebuild = True
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   151
                        elif opt == "--refresh-index":
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   152
                                # Note: This argument is for internal use
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   153
                                # only. It's used when pkg.depotd is reexecing
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   154
                                # itself and needs to know that's the case.
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   155
                                # This flag is purposefully omitted in usage.
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   156
                                # The supported way to forcefully reindex is to
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   157
                                # kill any pkg.depot using that directory,
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   158
                                # remove the index directory, and restart the
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   159
                                # pkg.depot process. The index will be rebuilt
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   160
                                # automatically on startup.
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   161
                                reindex = True
135
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 119
diff changeset
   162
        except getopt.GetoptError, e:
404
e5329e84b9a8 2331 depot command-line parsing errors cause traceback
Shawn Walker <swalker@opensolaris.org>
parents: 386
diff changeset
   163
                print "pkg.depotd: %s" % e.msg
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   164
                usage()
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   165
        except OptionError, e:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   166
                print "pkg.depotd: option: %s -- %s" % (opt, e)
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   167
                usage()
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   168
        except (ArithmeticError, ValueError):
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   169
                print "pkg.depotd: illegal option value: %s specified " \
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   170
                    "for option: %s" % (arg, opt)
135
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 119
diff changeset
   171
                usage()
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   172
        # If the program is going to reindex, the port is irrelevant since
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   173
        # the program will not bind to a port.
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   174
        if not reindex:
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   175
                available, msg = port_available(None, port)
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   176
                if not available:
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   177
                        print "pkg.depotd: unable to bind to the specified " \
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   178
                            "port: %d. Reason: %s" % (port, msg)
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   179
                        sys.exit(1)
386
5cd680466abe 2147 depot should check port instead of showing traceback if port binding fails
Shawn Walker <swalker@opensolaris.org>
parents: 382
diff changeset
   180
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   181
        try:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   182
                face.set_content_root(os.environ["PKG_DEPOT_CONTENT"])
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   183
        except KeyError:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   184
                pass
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   185
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   186
        scfg = config.SvrConfig(repo_path, AUTH_DEFAULT)
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   187
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   188
        if rebuild:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   189
                scfg.destroy_catalog()
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   190
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   191
        if readonly:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   192
                scfg.set_read_only()
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   193
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   194
        try:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   195
                scfg.init_dirs()
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   196
        except EnvironmentError, e:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   197
                print "pkg.depotd: an error occurred while trying to " \
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   198
                    "initialize the depot repository directory " \
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   199
                    "structures:\n%s" % e
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   200
                sys.exit(1)
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   201
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   202
        if reindex:
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   203
                scfg.acquire_catalog(rebuild = False)
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   204
                scfg.catalog.run_update_index()
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   205
                sys.exit(0)
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   206
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 25
diff changeset
   207
        scfg.acquire_in_flight()
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 25
diff changeset
   208
        scfg.acquire_catalog()
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 25
diff changeset
   209
428
e011e45fe2cd 2239 repository attribute system needed
Shawn Walker <shawn.walker@sun.com>
parents: 409
diff changeset
   210
        try:
e011e45fe2cd 2239 repository attribute system needed
Shawn Walker <shawn.walker@sun.com>
parents: 409
diff changeset
   211
                root = cherrypy.Application(repo.Repository(scfg))
e011e45fe2cd 2239 repository attribute system needed
Shawn Walker <shawn.walker@sun.com>
parents: 409
diff changeset
   212
        except rc.InvalidAttributeValueError, e:
e011e45fe2cd 2239 repository attribute system needed
Shawn Walker <shawn.walker@sun.com>
parents: 409
diff changeset
   213
                emsg("pkg.depotd: repository.conf error: %s" % e)
e011e45fe2cd 2239 repository attribute system needed
Shawn Walker <shawn.walker@sun.com>
parents: 409
diff changeset
   214
                sys.exit(1)
e011e45fe2cd 2239 repository attribute system needed
Shawn Walker <shawn.walker@sun.com>
parents: 409
diff changeset
   215
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   216
        # We have to override cherrypy's default response_class so that we
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   217
        # have access to the write() callable to stream data directly to the
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   218
        # client.
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   219
        root.wsgiapp.response_class = depot.DepotResponse
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   220
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   221
        cherrypy.config.update({
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   222
            "environment": "production",
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   223
            "checker.on": True,
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   224
            "log.screen": True,
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   225
            "server.socket_port": port,
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   226
            "server.thread_pool": threads,
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   227
            "server.socket_timeout": socket_timeout
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   228
        })
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   229
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   230
        conf = {
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   231
            "/robots.txt": {
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   232
                "tools.staticfile.on": True,
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   233
                "tools.staticfile.filename": os.path.join(face.content_root,
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   234
                    "robots.txt")
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   235
            },
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   236
            "/static": {
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   237
                "tools.staticdir.on": True,
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   238
                "tools.staticdir.root": face.content_root,
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   239
                "tools.staticdir.dir": ""
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   240
            }
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   241
        }
145
08bee7fd13f6 Add versioning to the protocols
Danek Duvall <danek.duvall@sun.com>
parents: 135
diff changeset
   242
217
a53bcf30c049 279 catalog_update should cope with HTTPError
johansen <johansen@sun.com>
parents: 215
diff changeset
   243
        try:
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   244
                cherrypy.quickstart(root, config = conf)
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   245
        except:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   246
                print "pkg.depotd: unknown error starting depot, illegal " \
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   247
                    "option value specified?"
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   248
                usage()
217
a53bcf30c049 279 catalog_update should cope with HTTPError
johansen <johansen@sun.com>
parents: 215
diff changeset
   249