src/depot.py
author Tom Mueller <Tom.Mueller@sun.com>
Mon, 11 Aug 2008 15:49:58 -0500
changeset 468 20250d58c2ab
parent 466 7cfb6502ff1b
child 589 2480ab0274d1
permissions -rwxr-xr-x
2309 pkg.depotd fails when -d argument is a relative pathname
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
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 452
diff changeset
    66
# Not in mirror mode by default
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 452
diff changeset
    67
MIRROR_DEFAULT = False
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    68
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 25
diff changeset
    69
import getopt
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
    70
import logging
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    71
import os
468
20250d58c2ab 2309 pkg.depotd fails when -d argument is a relative pathname
Tom Mueller <Tom.Mueller@sun.com>
parents: 466
diff changeset
    72
import os.path
52
d7c452ef7ae1 Sanitize getopt exception handling
Danek Duvall <danek.duvall@sun.com>
parents: 50
diff changeset
    73
import sys
451
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
    74
import urlparse
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    75
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    76
try:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    77
        import cherrypy
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    78
        version = cherrypy.__version__.split('.')
452
01f53c6381af 2714 image-update failure during update phase
Shawn Walker <shawn.walker@sun.com>
parents: 451
diff changeset
    79
        if map(int, version) < [3, 1, 0]:
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    80
                raise ImportError
452
01f53c6381af 2714 image-update failure during update phase
Shawn Walker <shawn.walker@sun.com>
parents: 451
diff changeset
    81
        elif map(int, version) >= [3, 2, 0]:
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    82
                raise ImportError
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    83
except ImportError:
452
01f53c6381af 2714 image-update failure during update phase
Shawn Walker <shawn.walker@sun.com>
parents: 451
diff changeset
    84
        print """cherrypy 3.1.0 or greater (but less than 3.2.0) is """ \
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    85
            """required to use this program."""
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    86
        sys.exit(2)
22
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 21
diff changeset
    87
114
e21e9aa690ad draft manual pages, index page cleanup
Stephen Hahn <sch@sun.com>
parents: 106
diff changeset
    88
import pkg.server.face as face
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 25
diff changeset
    89
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
    90
import pkg.server.depot as depot
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    91
import pkg.server.repository as repo
428
e011e45fe2cd 2239 repository attribute system needed
Shawn Walker <shawn.walker@sun.com>
parents: 409
diff changeset
    92
import pkg.server.repositoryconfig as rc
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
    93
from pkg.misc import port_available, msg, emsg
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
    94
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
    95
class LogSink(object):
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
    96
        """This is a dummy object that we can use to discard log entries
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
    97
        without relying on non-portable interfaces such as /dev/null."""
23
51b8b48fea32 begin server source reorganization
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    98
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
    99
        def write(self, *args, **kwargs):
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   100
                """Discard the bits."""
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   101
                pass
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   102
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   103
        def flush(self, *args, **kwargs):
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   104
                """Discard the bits."""
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   105
                pass
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   106
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   107
def usage(text):
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   108
        if text:
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   109
                emsg(text)
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   110
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 25
diff changeset
   111
        print """\
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 452
diff changeset
   112
Usage: /usr/lib/pkg.depotd [--readonly] [--rebuild] [--mirror] [--proxy-base url]
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   113
           [--log-access dest] [--log-errors dest] [-d repo_dir] [-p port]
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   114
           [-s threads] [-t socket_timeout]
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   115
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
   116
        --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
   117
        --rebuild       Re-build the catalog from pkgs in depot
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 452
diff changeset
   118
                        Cannot be used with --readonly or --mirror
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 452
diff changeset
   119
        --mirror        Content mirror mode. Publishing and metadata operations
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 452
diff changeset
   120
                        disabled
451
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   121
        --proxy-base    The url to use as the base for generating internal
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   122
                        redirects and content.
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   123
        --log-access    The destination for any access related information
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   124
                        logged by the depot process.  Possible values are:
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   125
                        stderr, stdout, none, or an absolute pathname.  The
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   126
                        default value is stdout if stdout is a tty; otherwise
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   127
                        the default value is none.
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   128
        --log-errors    The destination for any errors or other information
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   129
                        logged by the depot process.  Possible values are:
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   130
                        stderr, stdout, none, or an absolute pathname.  The
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   131
                        default value is stderr.
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 25
diff changeset
   132
"""
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
   133
        sys.exit(2)
14
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents: 3
diff changeset
   134
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   135
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
   136
        """Option exception. """
14
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents: 3
diff changeset
   137
404
e5329e84b9a8 2331 depot command-line parsing errors cause traceback
Shawn Walker <swalker@opensolaris.org>
parents: 386
diff changeset
   138
        def __init__(self, *args):
e5329e84b9a8 2331 depot command-line parsing errors cause traceback
Shawn Walker <swalker@opensolaris.org>
parents: 386
diff changeset
   139
                Exception.__init__(self, *args)
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   140
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   141
if __name__ == "__main__":
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   142
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   143
        port = PORT_DEFAULT
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   144
        threads = THREADS_DEFAULT
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   145
        socket_timeout = SOCKET_TIMEOUT_DEFAULT
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   146
        readonly = READONLY_DEFAULT
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   147
        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
   148
        reindex = REINDEX_DEFAULT
451
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   149
        proxy_base = None
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 452
diff changeset
   150
        mirror = MIRROR_DEFAULT
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 239
diff changeset
   151
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   152
        if "PKG_REPO" in os.environ:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   153
                repo_path = os.environ["PKG_REPO"]
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   154
        else:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   155
                repo_path = REPO_PATH_DEFAULT
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   156
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   157
        # By default, if the destination for a particular log type is not
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   158
        # specified, this is where we will send the output.
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   159
        log_routes = {
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   160
            "access": "none",
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   161
            "errors": "stderr"
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   162
        }
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   163
        log_opts = ["--log-%s" % log_type for log_type in log_routes]
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   164
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   165
        # If stdout is a tty, then send access output there by default instead
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   166
        # of discarding it.
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   167
        if os.isatty(sys.stdout.fileno()):
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   168
                log_routes["access"] = "stdout"
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   169
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   170
        opt = None
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
   171
        try:
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   172
                long_opts = ["readonly", "rebuild", "mirror", "refresh-index",
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   173
                    "proxy-base="]
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   174
                for opt in log_opts:
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   175
                        long_opts.append("%s=" % opt.lstrip('--'))
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   176
                opts, pargs = getopt.getopt(sys.argv[1:], "d:np:s:t:",
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   177
                    long_opts)
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
   178
                for opt, arg in opts:
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 119
diff changeset
   179
                        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
   180
                                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
   181
                        elif opt == "-d":
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   182
                                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
   183
                        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
   184
                                port = int(arg)
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   185
                        elif opt == "-s":
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   186
                                threads = int(arg)
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   187
                                if threads < THREADS_MIN:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   188
                                        raise OptionError, \
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   189
                                            "minimum value is %d" % THREADS_MIN
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   190
                                if threads > THREADS_MAX:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   191
                                        raise OptionError, \
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   192
                                            "maximum value is %d" % THREADS_MAX
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   193
                        elif opt == "-t":
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   194
                                socket_timeout = int(arg)
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   195
                        elif opt in log_opts:
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   196
                                if arg is None or arg == "":
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   197
                                        raise OptionError, \
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   198
                                            "You must specify a log " \
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   199
                                            "destination."
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   200
                                log_routes[opt.lstrip("--log-")] = 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
   201
                        elif opt == "--readonly":
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   202
                                readonly = True
157
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
   203
                        elif opt == "--rebuild":
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   204
                                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
   205
                        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
   206
                                # 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
   207
                                # 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
   208
                                # 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
   209
                                # 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
   210
                                # 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
   211
                                # 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
   212
                                # 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
   213
                                # 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
   214
                                # 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
   215
                                reindex = True
451
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   216
                        elif opt == "--proxy-base":
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   217
                                # Attempt to decompose the url provided into
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   218
                                # its base parts.  This is done so we can
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   219
                                # remove any scheme information since we
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   220
                                # don't need it.
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   221
                                scheme, netloc, path, params, query, \
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   222
                                    fragment = urlparse.urlparse(arg,
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   223
                                    allow_fragments=0)
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   224
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   225
                                # Rebuild the url without the scheme and
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   226
                                # remove the leading // urlunparse adds.
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   227
                                proxy_base = urlparse.urlunparse(("", netloc,
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   228
                                    path, params, query, fragment)
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   229
                                    ).lstrip("//")
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   230
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 452
diff changeset
   231
                        elif opt == "--mirror":
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 452
diff changeset
   232
                                mirror = 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
   233
        except getopt.GetoptError, e:
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   234
                usage("pkg.depotd: %s" % e.msg)
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   235
        except OptionError, e:
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   236
                usage("pkg.depotd: option: %s -- %s" % (opt, e))
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   237
        except (ArithmeticError, ValueError):
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   238
                usage("pkg.depotd: illegal option value: %s specified " \
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   239
                    "for option: %s" % (arg, opt))
451
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   240
445
76b03dd5a4ac 2693 Indexing code and catalog code should respect --read-only
Brock Pytlik <bpytlik@sun.com>
parents: 429
diff changeset
   241
        if rebuild and reindex:
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   242
                usage("--refresh-index cannot be used with --rebuild")
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 452
diff changeset
   243
        if rebuild and (readonly or mirror):
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   244
                usage("--readonly and --mirror cannot be used with --rebuild")
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 452
diff changeset
   245
        if reindex and (readonly or mirror):
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   246
                usage("--readonly and --mirror cannot be used with " \
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   247
                    "--refresh-index")
451
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   248
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   249
        # 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
   250
        # 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
   251
        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
   252
                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
   253
                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
   254
                        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
   255
                            "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
   256
                        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
   257
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   258
        try:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   259
                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
   260
        except KeyError:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   261
                pass
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   262
468
20250d58c2ab 2309 pkg.depotd fails when -d argument is a relative pathname
Tom Mueller <Tom.Mueller@sun.com>
parents: 466
diff changeset
   263
        scfg = config.SvrConfig(os.path.abspath(repo_path), AUTH_DEFAULT)
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   264
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   265
        if rebuild:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   266
                scfg.destroy_catalog()
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   267
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   268
        if readonly:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   269
                scfg.set_read_only()
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   270
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 452
diff changeset
   271
        if mirror:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 452
diff changeset
   272
                scfg.set_mirror()
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 452
diff changeset
   273
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   274
        try:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   275
                scfg.init_dirs()
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   276
        except EnvironmentError, e:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   277
                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
   278
                    "initialize the depot repository directory " \
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   279
                    "structures:\n%s" % e
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   280
                sys.exit(1)
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   281
452
01f53c6381af 2714 image-update failure during update phase
Shawn Walker <shawn.walker@sun.com>
parents: 451
diff changeset
   282
        # Setup our global configuration.
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   283
        # Global cherrypy configuration
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   284
        gconf = {
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   285
            "environment": "production",
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   286
            "checker.on": True,
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   287
            "log.screen": False,
452
01f53c6381af 2714 image-update failure during update phase
Shawn Walker <shawn.walker@sun.com>
parents: 451
diff changeset
   288
            "server.socket_host": "0.0.0.0",
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   289
            "server.socket_port": port,
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   290
            "server.thread_pool": threads,
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   291
            "server.socket_timeout": socket_timeout,
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   292
            "tools.log_headers.on": True
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   293
        }
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   294
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   295
        log_type_map = {
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   296
            "errors": {
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   297
                "param": "log.error_file",
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   298
                "attr": "error_log"
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   299
            },
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   300
            "access": {
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   301
                "param": "log.access_file",
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   302
                "attr": "access_log"
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   303
            }
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   304
        }
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   305
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   306
        for log_type in log_type_map:
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   307
                dest = log_routes[log_type]
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   308
                if dest in ("stdout", "stderr", "none"):
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   309
                        if dest == "none":
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   310
                                h = logging.StreamHandler(LogSink())
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   311
                        else:
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   312
                                h = logging.StreamHandler(eval("sys.%s" % \
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   313
                                    dest))
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   314
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   315
                        h.setLevel(logging.DEBUG)
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   316
                        h.setFormatter(cherrypy._cplogging.logfmt)
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   317
                        log_obj = eval("cherrypy.log.%s" % \
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   318
                            log_type_map[log_type]["attr"])
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   319
                        log_obj.addHandler(h)
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   320
                        # Since we've replaced cherrypy's log handler with our
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   321
                        # own, we don't want the output directed to a file.
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   322
                        dest = ""
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   323
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   324
                gconf[log_type_map[log_type]["param"]] = dest
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   325
451
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   326
        # Now build our site configuration.
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   327
        conf = {
452
01f53c6381af 2714 image-update failure during update phase
Shawn Walker <shawn.walker@sun.com>
parents: 451
diff changeset
   328
            "/": {
01f53c6381af 2714 image-update failure during update phase
Shawn Walker <shawn.walker@sun.com>
parents: 451
diff changeset
   329
                # We have to override cherrypy's default response_class so that
01f53c6381af 2714 image-update failure during update phase
Shawn Walker <shawn.walker@sun.com>
parents: 451
diff changeset
   330
                # we have access to the write() callable to stream data
01f53c6381af 2714 image-update failure during update phase
Shawn Walker <shawn.walker@sun.com>
parents: 451
diff changeset
   331
                # directly to the client.
01f53c6381af 2714 image-update failure during update phase
Shawn Walker <shawn.walker@sun.com>
parents: 451
diff changeset
   332
                "wsgi.response_class": depot.DepotResponse,
01f53c6381af 2714 image-update failure during update phase
Shawn Walker <shawn.walker@sun.com>
parents: 451
diff changeset
   333
            },
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   334
            "/robots.txt": {
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   335
                "tools.staticfile.on": True,
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   336
                "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
   337
                    "robots.txt")
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   338
            },
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   339
            "/static": {
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   340
                "tools.staticdir.on": True,
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   341
                "tools.staticdir.root": face.content_root,
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   342
                "tools.staticdir.dir": ""
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   343
            }
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   344
        }
145
08bee7fd13f6 Add versioning to the protocols
Danek Duvall <danek.duvall@sun.com>
parents: 135
diff changeset
   345
451
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   346
        if proxy_base:
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   347
                # This changes the base URL for our server, and is primarily
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   348
                # intended to allow our depot process to operate behind Apache
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   349
                # or some other webserver process.
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   350
                #
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   351
                # Visit the following URL for more information:
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   352
                #    http://cherrypy.org/wiki/BuiltinTools#tools.proxy
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   353
                proxy_conf = {
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   354
                        "tools.proxy.on": True,
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   355
                        "tools.proxy.local": "",
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   356
                        "tools.proxy.base": proxy_base
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   357
                }
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   358
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   359
                if "/" not in conf:
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   360
                        conf["/"] = {}
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   361
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   362
                # Now merge or add our proxy configuration information into the
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   363
                # existing configuration.
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   364
                for entry in proxy_conf:
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   365
                        conf["/"][entry] = proxy_conf[entry]
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   366
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   367
        cherrypy.config.update(gconf)
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   368
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   369
        # Now that our logging, etc. has been setup, it's safe to perform any
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   370
        # remaining preparation.
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   371
        if reindex:
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   372
                scfg.acquire_catalog(rebuild=False)
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   373
                scfg.catalog.run_update_index()
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   374
                sys.exit(0)
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   375
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   376
        scfg.acquire_in_flight()
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   377
        scfg.acquire_catalog()
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   378
217
a53bcf30c049 279 catalog_update should cope with HTTPError
johansen <johansen@sun.com>
parents: 215
diff changeset
   379
        try:
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   380
                root = cherrypy.Application(repo.Repository(scfg))
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   381
        except rc.InvalidAttributeValueError, e:
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   382
                emsg("pkg.depotd: repository.conf error: %s" % e)
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   383
                sys.exit(1)
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   384
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   385
        try:
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   386
                cherrypy.quickstart(root, config=conf)
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   387
        except:
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   388
                usage("pkg.depotd: unknown error starting depot, illegal " \
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   389
                    "option value specified?")
217
a53bcf30c049 279 catalog_update should cope with HTTPError
johansen <johansen@sun.com>
parents: 215
diff changeset
   390