src/depot.py
author Yiteng Zhang <yiteng.zhang@oracle.com>
Tue, 03 Nov 2015 02:27:20 -0800
changeset 3274 e06a0700e218
parent 3273 776d569cd953
child 3339 c88573eb98ea
permissions -rwxr-xr-x
15768696 evaluate changes needed to upgrade to external python libraries
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3177
173c3b46334b 18735388 pkg utilities should switch to Python 2.7
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3171
diff changeset
     1
#!/usr/bin/python2.7
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
#
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
    22
# Copyright (c) 2007, 2015, Oracle and/or its affiliates. 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
#
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
3143
f6fac0617411 20097788 change print keyword usage for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3053
diff changeset
    25
from __future__ import print_function
f6fac0617411 20097788 change print keyword usage for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3053
diff changeset
    26
22
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 21
diff changeset
    27
# pkg.depotd - package repository daemon
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    28
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    29
# 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
    30
# 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
    31
# 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
    32
# 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
    33
# 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
    34
# 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
    35
# 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
    36
# 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
    37
# only a basic HTTP/HTTPS server in place.
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    38
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    39
# 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
    40
# 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
    41
# dumb clients (like a notification service).
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 46
diff changeset
    42
589
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
    43
# The default path for static and other web content.
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
    44
CONTENT_PATH_DEFAULT = "/usr/share/lib/pkg"
965
6efb5042a707 7552 depot aborts connection for add operations with payload greater than 100MB
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 916
diff changeset
    45
# cherrypy has a max_request_body_size parameter that determines whether the
6efb5042a707 7552 depot aborts connection for add operations with payload greater than 100MB
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 916
diff changeset
    46
# server should abort requests with REQUEST_ENTITY_TOO_LARGE when the request
6efb5042a707 7552 depot aborts connection for add operations with payload greater than 100MB
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 916
diff changeset
    47
# body is larger than the specified size (in bytes).  The maximum size supported
6efb5042a707 7552 depot aborts connection for add operations with payload greater than 100MB
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 916
diff changeset
    48
# by cherrypy is 2048 * 1024 * 1024 - 1 (just short of 2048MB), but the default
6efb5042a707 7552 depot aborts connection for add operations with payload greater than 100MB
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 916
diff changeset
    49
# here is purposefully conservative.
2951
e52b6ae3a4b2 15820285 support for files >128MB for pkg.depotd publication
saurabh.vyas@oracle.com
parents: 2816
diff changeset
    50
MAX_REQUEST_BODY_SIZE = 512 * 1024 * 1024
1836
33bccd66b8e2 5650 misc.port_available incorrectly returns true for ports in use only on localhost
Shawn Walker <shawn.walker@oracle.com>
parents: 1779
diff changeset
    51
# The default host/port(s) to serve data from.
33bccd66b8e2 5650 misc.port_available incorrectly returns true for ports in use only on localhost
Shawn Walker <shawn.walker@oracle.com>
parents: 1779
diff changeset
    52
HOST_DEFAULT = "0.0.0.0"
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    53
PORT_DEFAULT = 80
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
    54
SSL_PORT_DEFAULT = 443
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    55
# The minimum number of threads allowed.
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    56
THREADS_MIN = 1
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    57
# The default number of threads to start.
1963
085efeb8cb0c 16244 depot's MAX_THREADS is too low
johansen <johansen@opensolaris.org>
parents: 1937
diff changeset
    58
THREADS_DEFAULT = 60
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    59
# The maximum number of threads that can be started.
1963
085efeb8cb0c 16244 depot's MAX_THREADS is too low
johansen <johansen@opensolaris.org>
parents: 1937
diff changeset
    60
THREADS_MAX = 5000
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    61
# 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
    62
# 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
    63
# connections.
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    64
SOCKET_TIMEOUT_DEFAULT = 60
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    65
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 25
diff changeset
    66
import getopt
689
1cb7154e1592 4489 depot traceback for info operation due to changeset 660
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 617
diff changeset
    67
import gettext
1cb7154e1592 4489 depot traceback for info operation due to changeset 660
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 617
diff changeset
    68
import locale
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
    69
import logging
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    70
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
    71
import os.path
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
    72
import OpenSSL.crypto as crypto
3273
776d569cd953 17983590 problem in PYTHON-MOD/PKG
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 3234
diff changeset
    73
import shlex
3274
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
    74
import six
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
    75
import string
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
    76
import subprocess
52
d7c452ef7ae1 Sanitize getopt exception handling
Danek Duvall <danek.duvall@sun.com>
parents: 50
diff changeset
    77
import sys
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
    78
import tempfile
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    79
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
    80
from imp import reload
3234
3a90dc0b66c9 21188662 use six library for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3194
diff changeset
    81
from six.moves.urllib.parse import urlparse, urlunparse
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
    82
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    83
try:
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    84
        import cherrypy
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    85
        version = cherrypy.__version__.split('.')
3234
3a90dc0b66c9 21188662 use six library for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3194
diff changeset
    86
        # comparison requires same type, therefore list conversion is needed
3a90dc0b66c9 21188662 use six library for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3194
diff changeset
    87
        if list(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
    88
                raise ImportError
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    89
except ImportError:
3274
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
    90
        print("""cherrypy 3.1.0 or greater is required to use this program.""",
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
    91
            file=sys.stderr)
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
    92
        sys.exit(2)
22
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 21
diff changeset
    93
1836
33bccd66b8e2 5650 misc.port_available incorrectly returns true for ports in use only on localhost
Shawn Walker <shawn.walker@oracle.com>
parents: 1779
diff changeset
    94
import cherrypy.process.servers
2507
d2873152e497 15761 pkg/server is duration=child, foils SMF's fault detection
Shawn Walker <shawn.walker@oracle.com>
parents: 2230
diff changeset
    95
from cherrypy.process.plugins import Daemonizer
3274
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
    96
from cherrypy._cpdispatch import Dispatcher
1836
33bccd66b8e2 5650 misc.port_available incorrectly returns true for ports in use only on localhost
Shawn Walker <shawn.walker@oracle.com>
parents: 1779
diff changeset
    97
33bccd66b8e2 5650 misc.port_available incorrectly returns true for ports in use only on localhost
Shawn Walker <shawn.walker@oracle.com>
parents: 1779
diff changeset
    98
from pkg.misc import msg, emsg, setlocale
2962
ce8cd4c07986 15433013 content hash handling should handle different hash functions
Tim Foster <tim.s.foster@oracle.com>
parents: 2951
diff changeset
    99
from pkg.client.debugvalues import DebugValues
ce8cd4c07986 15433013 content hash handling should handle different hash functions
Tim Foster <tim.s.foster@oracle.com>
parents: 2951
diff changeset
   100
ce8cd4c07986 15433013 content hash handling should handle different hash functions
Tim Foster <tim.s.foster@oracle.com>
parents: 2951
diff changeset
   101
import pkg
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   102
import pkg.client.api_errors as api_errors
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   103
import pkg.config as cfg
873
b95d76c53b5e 2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 858
diff changeset
   104
import pkg.portable.util as os_util
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   105
import pkg.search_errors as search_errors
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   106
import pkg.server.depot as ds
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   107
import pkg.server.repository as sr
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   108
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   109
3274
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
   110
# Starting in CherryPy 3.2, its default dispatcher converts all punctuation to
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
   111
# underscore. Since publisher name can contain the hyphen symbol "-", in order
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
   112
# to let the dispatcher to find the correct page handler, we need to skip
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
   113
# converting the hyphen symbol.
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
   114
punc = string.punctuation.replace("-", "_")
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
   115
if six.PY2:
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
   116
        translate = string.maketrans(punc, "_" * len(string.punctuation))
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
   117
else:
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
   118
        translate = str.maketrans(punc, "_" * len(string.punctuation))
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
   119
class Pkg5Dispatcher(Dispatcher):
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
   120
        def __init__(self, **args):
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
   121
                Dispatcher.__init__(self, translate=translate)
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
   122
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
   123
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   124
class LogSink(object):
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   125
        """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
   126
        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
   127
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   128
        def write(self, *args, **kwargs):
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   129
                """Discard the bits."""
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   130
                pass
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   131
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   132
        def flush(self, *args, **kwargs):
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   133
                """Discard the bits."""
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   134
                pass
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   135
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   136
1633
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   137
def usage(text=None, retcode=2, full=False):
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   138
        """Optionally emit a usage message and then exit using the specified
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   139
        exit code."""
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   140
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   141
        if text:
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   142
                emsg(text)
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   143
1633
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   144
        if not full:
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   145
                # The full usage message isn't desired.
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   146
                emsg(_("Try `pkg.depotd --help or -?' for more "
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   147
                    "information."))
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   148
                sys.exit(retcode)
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   149
3143
f6fac0617411 20097788 change print keyword usage for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3053
diff changeset
   150
        print("""\
2230
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   151
Usage: /usr/lib/pkg.depotd [-a address] [-d inst_root] [-p port] [-s threads]
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   152
           [-t socket_timeout] [--cfg] [--content-root]
1633
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   153
           [--disable-ops op[/1][,...]] [--debug feature_list]
2515
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   154
           [--image-root dir] [--log-access dest] [--log-errors dest]
2816
17425ca1f195 7192183 nasty depot testing should be part of core testing
Dan Price <daniel.price@oracle.com>
parents: 2794
diff changeset
   155
           [--mirror] [--nasty] [--nasty-sleep] [--proxy-base url]
17425ca1f195 7192183 nasty depot testing should be part of core testing
Dan Price <daniel.price@oracle.com>
parents: 2794
diff changeset
   156
           [--readonly] [--ssl-cert-file] [--ssl-dialog] [--ssl-key-file]
1937
be8995c7bb8f 10924 Want ability to communicate over unix sockets
johansen <johansen@opensolaris.org>
parents: 1902
diff changeset
   157
           [--sort-file-max-size size] [--writable-root dir]
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   158
2230
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   159
        -a address      The IP address on which to listen for connections.  The
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   160
                        default value is 0.0.0.0 (INADDR_ANY) which will listen
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   161
                        on all active interfaces.  To listen on all active IPv6
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   162
                        interfaces, use '::'.
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   163
        -d inst_root    The file system path at which the server should find its
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   164
                        repository data.  Required unless PKG_REPO has been set
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   165
                        in the environment.
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   166
        -p port         The port number on which the instance should listen for
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   167
                        incoming package requests.  The default value is 80 if
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   168
                        ssl certificate and key information has not been
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   169
                        provided; otherwise, the default value is 443.
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   170
        -s threads      The number of threads that will be started to serve
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   171
                        requests.  The default value is 10.
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   172
        -t timeout      The maximum number of seconds the server should wait for
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   173
                        a response from a client before closing a connection.
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   174
                        The default value is 60.
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   175
        --cfg           The pathname of the file to use when reading and writing
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   176
                        depot configuration data, or a fully qualified service
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   177
                        fault management resource identifier (FMRI) of the SMF
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   178
                        service or instance to read configuration data from.
589
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   179
        --content-root  The file system path to the directory containing the
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   180
                        the static and other web content used by the depot's
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   181
                        browser user interface.  The default value is
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   182
                        '/usr/share/lib/pkg'.
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   183
        --disable-ops   A comma separated list of operations that the depot
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   184
                        should not configure.  If, for example, you wanted
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   185
                        to omit loading search v1, 'search/1' should be
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   186
                        provided as an argument, or to disable all search
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   187
                        operations, simply 'search'.
858
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   188
        --debug         The name of a debug feature to enable; or a whitespace
1633
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   189
                        or comma separated list of features to enable.
2962
ce8cd4c07986 15433013 content hash handling should handle different hash functions
Tim Foster <tim.s.foster@oracle.com>
parents: 2951
diff changeset
   190
                        Possible values are: headers, hash=sha1+sha256,
3053
7c1dfe878489 17478601 provide a pkg(5) private module to compute SHA512/256
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 2992
diff changeset
   191
                        hash=sha256, hash=sha1+sha512_256, hash=sha512_256
2515
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   192
        --image-root    The path to the image whose file information will be
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   193
                        used as a cache for file data.
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   194
        --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
   195
                        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
   196
                        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
   197
                        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
   198
                        the default value is none.
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   199
        --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
   200
                        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
   201
                        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
   202
                        default value is stderr.
589
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   203
        --mirror        Package mirror mode; publishing and metadata operations
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   204
                        disallowed.  Cannot be used with --readonly or
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   205
                        --rebuild.
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1020
diff changeset
   206
        --nasty         Instruct the server to misbehave.  At random intervals
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1020
diff changeset
   207
                        it will time-out, send bad responses, hang up on
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1020
diff changeset
   208
                        clients, and generally be hostile.  The option
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1020
diff changeset
   209
                        takes a value (1 to 100) for how nasty the server
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1020
diff changeset
   210
                        should be.
2816
17425ca1f195 7192183 nasty depot testing should be part of core testing
Dan Price <daniel.price@oracle.com>
parents: 2794
diff changeset
   211
        --nasty-sleep   In nasty mode (see --nasty), how many seconds to
17425ca1f195 7192183 nasty depot testing should be part of core testing
Dan Price <daniel.price@oracle.com>
parents: 2794
diff changeset
   212
                        randomly sleep when a random sleep occurs.
589
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   213
        --proxy-base    The url to use as the base for generating internal
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   214
                        redirects and content.
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   215
        --readonly      Read-only operation; modifying operations disallowed.
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   216
                        Cannot be used with --mirror or --rebuild.
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   217
        --ssl-cert-file The absolute pathname to a PEM-encoded Certificate file.
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   218
                        This option must be used with --ssl-key-file.  Usage of
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   219
                        this option will cause the depot to only respond to SSL
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   220
                        requests on the provided port.
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   221
        --ssl-dialog    Specifies what method should be used to obtain the
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   222
                        passphrase needed to decrypt the file specified by
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   223
                        --ssl-key-file.  Supported values are: builtin,
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   224
                        exec:/path/to/program, smf, or an SMF FMRI.  The
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   225
                        default value is builtin.  If smf is specified, an
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   226
                        SMF FMRI must be provided using the --cfg option.
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   227
        --ssl-key-file  The absolute pathname to a PEM-encoded Private Key file.
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   228
                        This option must be used with --ssl-cert-file.  Usage of
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   229
                        this option will cause the depot to only respond to SSL
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   230
                        requests on the provided port.
1475
a667a9efcae9 7360 indexing workfile size should be configurable
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 1433
diff changeset
   231
        --sort-file-max-size
a667a9efcae9 7360 indexing workfile size should be configurable
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 1433
diff changeset
   232
                        The maximum size of the indexer sort file. Used to
a667a9efcae9 7360 indexing workfile size should be configurable
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 1433
diff changeset
   233
                        limit the amount of RAM the depot uses for indexing,
a667a9efcae9 7360 indexing workfile size should be configurable
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 1433
diff changeset
   234
                        or increase it for speed.
975
346745ea94fe 2701 "scratch area" for depot
Brock Pytlik <bpytlik@sun.com>
parents: 965
diff changeset
   235
        --writable-root The path to a directory to which the program has write
346745ea94fe 2701 "scratch area" for depot
Brock Pytlik <bpytlik@sun.com>
parents: 965
diff changeset
   236
                        access.  Used with --readonly to allow server to
346745ea94fe 2701 "scratch area" for depot
Brock Pytlik <bpytlik@sun.com>
parents: 965
diff changeset
   237
                        create needed files, such as search indices, without
346745ea94fe 2701 "scratch area" for depot
Brock Pytlik <bpytlik@sun.com>
parents: 965
diff changeset
   238
                        needing write access to the package information.
1633
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   239
Options:
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   240
        --help or -?
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   241
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   242
Environment:
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   243
        PKG_REPO                Used as default inst_root if -d not provided.
1633
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   244
        PKG_DEPOT_CONTENT       Used as default content_root if --content-root
3143
f6fac0617411 20097788 change print keyword usage for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3053
diff changeset
   245
                                not provided.""")
1633
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   246
        sys.exit(retcode)
14
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents: 3
diff changeset
   247
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   248
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
   249
        """Option exception. """
14
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents: 3
diff changeset
   250
404
e5329e84b9a8 2331 depot command-line parsing errors cause traceback
Shawn Walker <swalker@opensolaris.org>
parents: 386
diff changeset
   251
        def __init__(self, *args):
e5329e84b9a8 2331 depot command-line parsing errors cause traceback
Shawn Walker <swalker@opensolaris.org>
parents: 386
diff changeset
   252
                Exception.__init__(self, *args)
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   253
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   254
if __name__ == "__main__":
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   255
791
123e9401e939 5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents: 775
diff changeset
   256
        setlocale(locale.LC_ALL, "")
2728
69903f3b722b 7166082 pkg command does not handle Japanese character encoding on Solaris 11
Abhinandan Ekande <abhinandan.ekande@oracle.com>
parents: 2515
diff changeset
   257
        gettext.install("pkg", "/usr/share/locale",
69903f3b722b 7166082 pkg command does not handle Japanese character encoding on Solaris 11
Abhinandan Ekande <abhinandan.ekande@oracle.com>
parents: 2515
diff changeset
   258
            codeset=locale.getpreferredencoding())
689
1cb7154e1592 4489 depot traceback for info operation due to changeset 660
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 617
diff changeset
   259
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   260
        add_content = False
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   261
        exit_ready = False
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   262
        rebuild = False
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   263
        reindex = False
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1020
diff changeset
   264
        nasty = False
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 239
diff changeset
   265
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   266
        # Track initial configuration values.
2816
17425ca1f195 7192183 nasty depot testing should be part of core testing
Dan Price <daniel.price@oracle.com>
parents: 2794
diff changeset
   267
        ivalues = { "pkg": {}, "nasty": {} }
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   268
        if "PKG_REPO" in os.environ:
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   269
                ivalues["pkg"]["inst_root"] = os.environ["PKG_REPO"]
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   270
589
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   271
        try:
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   272
                content_root = os.environ["PKG_DEPOT_CONTENT"]
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   273
                ivalues["pkg"]["content_root"] = content_root
589
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   274
        except KeyError:
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   275
                try:
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   276
                        content_root = os.path.join(os.environ['PKG_HOME'],
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   277
                            'share/lib/pkg')
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   278
                        ivalues["pkg"]["content_root"] = content_root
589
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   279
                except KeyError:
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   280
                        pass
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   281
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   282
        opt = None
2230
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   283
        addresses = set()
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   284
        debug_features = []
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   285
        disable_ops = []
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   286
        repo_props = {}
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   287
        socket_path = ""
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   288
        user_cfg = 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
   289
        try:
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   290
                long_opts = ["add-content", "cfg=", "cfg-file=",
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   291
                    "content-root=", "debug=", "disable-ops=", "exit-ready",
2515
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   292
                    "help", "image-root=", "log-access=", "log-errors=",
2816
17425ca1f195 7192183 nasty depot testing should be part of core testing
Dan Price <daniel.price@oracle.com>
parents: 2794
diff changeset
   293
                    "llmirror", "mirror", "nasty=", "nasty-sleep=",
17425ca1f195 7192183 nasty depot testing should be part of core testing
Dan Price <daniel.price@oracle.com>
parents: 2794
diff changeset
   294
                    "proxy-base=", "readonly", "rebuild", "refresh-index",
17425ca1f195 7192183 nasty depot testing should be part of core testing
Dan Price <daniel.price@oracle.com>
parents: 2794
diff changeset
   295
                    "set-property=", "ssl-cert-file=", "ssl-dialog=",
17425ca1f195 7192183 nasty depot testing should be part of core testing
Dan Price <daniel.price@oracle.com>
parents: 2794
diff changeset
   296
                    "ssl-key-file=", "sort-file-max-size=", "writable-root="]
1475
a667a9efcae9 7360 indexing workfile size should be configurable
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 1433
diff changeset
   297
2230
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   298
                opts, pargs = getopt.getopt(sys.argv[1:], "a:d:np:s:t:?",
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   299
                    long_opts)
1633
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   300
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   301
                show_usage = False
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
   302
                for opt, arg in opts:
2230
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   303
                        if opt == "-a":
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   304
                                addresses.add(arg)
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   305
                        elif opt == "-n":
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
   306
                                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
   307
                        elif opt == "-d":
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   308
                                ivalues["pkg"]["inst_root"] = 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
   309
                        elif opt == "-p":
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   310
                                ivalues["pkg"]["port"] = arg
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   311
                        elif opt == "-s":
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   312
                                threads = int(arg)
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   313
                                if threads < THREADS_MIN:
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   314
                                        raise OptionError(
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   315
                                            "minimum value is {0:d}".format(
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   316
                                            THREADS_MIN))
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   317
                                if threads > THREADS_MAX:
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   318
                                        raise OptionError(
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   319
                                            "maximum value is {0:d}".format(
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   320
                                            THREADS_MAX))
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   321
                                ivalues["pkg"]["threads"] = threads
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   322
                        elif opt == "-t":
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   323
                                ivalues["pkg"]["socket_timeout"] = arg
1542
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   324
                        elif opt == "--add-content":
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   325
                                add_content = True
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   326
                        elif opt == "--cfg":
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   327
                                user_cfg  = arg
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   328
                        elif opt == "--cfg-file":
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   329
                                ivalues["pkg"]["cfg_file"] = arg
589
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   330
                        elif opt == "--content-root":
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   331
                                ivalues["pkg"]["content_root"] = arg
858
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   332
                        elif opt == "--debug":
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   333
                                if arg is None or arg == "":
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   334
                                        continue
858
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   335
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   336
                                # A list of features can be specified using a
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   337
                                # "," or any whitespace character as separators.
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   338
                                if "," in arg:
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   339
                                        features = arg.split(",")
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   340
                                else:
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   341
                                        features = arg.split()
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   342
                                debug_features.extend(features)
2962
ce8cd4c07986 15433013 content hash handling should handle different hash functions
Tim Foster <tim.s.foster@oracle.com>
parents: 2951
diff changeset
   343
ce8cd4c07986 15433013 content hash handling should handle different hash functions
Tim Foster <tim.s.foster@oracle.com>
parents: 2951
diff changeset
   344
                                # We also allow key=value debug flags, which
ce8cd4c07986 15433013 content hash handling should handle different hash functions
Tim Foster <tim.s.foster@oracle.com>
parents: 2951
diff changeset
   345
                                # get set in pkg.client.debugvalues
ce8cd4c07986 15433013 content hash handling should handle different hash functions
Tim Foster <tim.s.foster@oracle.com>
parents: 2951
diff changeset
   346
                                for feature in features:
ce8cd4c07986 15433013 content hash handling should handle different hash functions
Tim Foster <tim.s.foster@oracle.com>
parents: 2951
diff changeset
   347
                                        try:
ce8cd4c07986 15433013 content hash handling should handle different hash functions
Tim Foster <tim.s.foster@oracle.com>
parents: 2951
diff changeset
   348
                                                key, val = feature.split("=", 1)
ce8cd4c07986 15433013 content hash handling should handle different hash functions
Tim Foster <tim.s.foster@oracle.com>
parents: 2951
diff changeset
   349
                                                DebugValues.set_value(key, val)
ce8cd4c07986 15433013 content hash handling should handle different hash functions
Tim Foster <tim.s.foster@oracle.com>
parents: 2951
diff changeset
   350
                                        except (AttributeError, ValueError):
ce8cd4c07986 15433013 content hash handling should handle different hash functions
Tim Foster <tim.s.foster@oracle.com>
parents: 2951
diff changeset
   351
                                                pass
ce8cd4c07986 15433013 content hash handling should handle different hash functions
Tim Foster <tim.s.foster@oracle.com>
parents: 2951
diff changeset
   352
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   353
                        elif opt == "--disable-ops":
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   354
                                if arg is None or arg == "":
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   355
                                        raise OptionError(
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   356
                                            "An argument must be specified.")
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   357
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   358
                                disableops = arg.split(",")
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   359
                                for s in disableops:
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   360
                                        if "/" in s:
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   361
                                                op, ver = s.rsplit("/", 1)
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   362
                                        else:
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   363
                                                op = s
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   364
                                                ver = "*"
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   365
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   366
                                        if op not in \
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   367
                                            ds.DepotHTTP.REPO_OPS_DEFAULT:
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   368
                                                raise OptionError(
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   369
                                                    "Invalid operation "
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   370
                                                    "'{0}'.".format(s))
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   371
                                        disable_ops.append(s)
1542
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   372
                        elif opt == "--exit-ready":
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   373
                                exit_ready = True
2515
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   374
                        elif opt == "--image-root":
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   375
                                ivalues["pkg"]["image_root"] = arg
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   376
                        elif opt.startswith("--log-"):
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   377
                                prop = "log_{0}".format(opt.lstrip("--log-"))
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   378
                                ivalues["pkg"][prop] = arg
1633
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   379
                        elif opt in ("--help", "-?"):
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   380
                                show_usage = True
589
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   381
                        elif opt == "--mirror":
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   382
                                ivalues["pkg"]["mirror"] = True
1902
59b7214232cb 6957 mDNS support for depot
johansen <johansen@opensolaris.org>
parents: 1895
diff changeset
   383
                        elif opt == "--llmirror":
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   384
                                ivalues["pkg"]["mirror"] = True
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   385
                                ivalues["pkg"]["ll_mirror"] = True
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   386
                                ivalues["pkg"]["readonly"] = True
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1020
diff changeset
   387
                        elif opt == "--nasty":
2816
17425ca1f195 7192183 nasty depot testing should be part of core testing
Dan Price <daniel.price@oracle.com>
parents: 2794
diff changeset
   388
                                # ValueError is caught by caller.
17425ca1f195 7192183 nasty depot testing should be part of core testing
Dan Price <daniel.price@oracle.com>
parents: 2794
diff changeset
   389
                                nasty_value = int(arg)
17425ca1f195 7192183 nasty depot testing should be part of core testing
Dan Price <daniel.price@oracle.com>
parents: 2794
diff changeset
   390
                                if (nasty_value > 100 or nasty_value < 1):
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   391
                                        raise OptionError("Invalid value "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   392
                                            "for nasty option.\n Please "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   393
                                            "choose a value between 1 and 100.")
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1020
diff changeset
   394
                                nasty = True
2816
17425ca1f195 7192183 nasty depot testing should be part of core testing
Dan Price <daniel.price@oracle.com>
parents: 2794
diff changeset
   395
                                ivalues["nasty"]["nasty_level"] = nasty_value
17425ca1f195 7192183 nasty depot testing should be part of core testing
Dan Price <daniel.price@oracle.com>
parents: 2794
diff changeset
   396
                        elif opt == "--nasty-sleep":
17425ca1f195 7192183 nasty depot testing should be part of core testing
Dan Price <daniel.price@oracle.com>
parents: 2794
diff changeset
   397
                                # ValueError is caught by caller.
17425ca1f195 7192183 nasty depot testing should be part of core testing
Dan Price <daniel.price@oracle.com>
parents: 2794
diff changeset
   398
                                sleep_value = int(arg)
17425ca1f195 7192183 nasty depot testing should be part of core testing
Dan Price <daniel.price@oracle.com>
parents: 2794
diff changeset
   399
                                ivalues["nasty"]["nasty_sleep"] = sleep_value
589
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   400
                        elif opt == "--proxy-base":
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   401
                                # Attempt to decompose the url provided into
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   402
                                # its base parts.  This is done so we can
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   403
                                # remove any scheme information since we
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   404
                                # don't need it.
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   405
                                scheme, netloc, path, params, query, \
3234
3a90dc0b66c9 21188662 use six library for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3194
diff changeset
   406
                                    fragment = urlparse(arg,
765
3cc1f2dff092 5668 proxy base should allow https
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 751
diff changeset
   407
                                    "http", allow_fragments=0)
3cc1f2dff092 5668 proxy base should allow https
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 751
diff changeset
   408
3cc1f2dff092 5668 proxy base should allow https
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 751
diff changeset
   409
                                if not netloc:
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   410
                                        raise OptionError("Unable to "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   411
                                            "determine the hostname from "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   412
                                            "the provided URL; please use a "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   413
                                            "fully qualified URL.")
589
2480ab0274d1 242 desire ability to set content root
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 468
diff changeset
   414
765
3cc1f2dff092 5668 proxy base should allow https
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 751
diff changeset
   415
                                scheme = scheme.lower()
3cc1f2dff092 5668 proxy base should allow https
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 751
diff changeset
   416
                                if scheme not in ("http", "https"):
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   417
                                        raise OptionError("Invalid URL; http "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   418
                                            "and https are the only supported "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   419
                                            "schemes.")
765
3cc1f2dff092 5668 proxy base should allow https
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 751
diff changeset
   420
3cc1f2dff092 5668 proxy base should allow https
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 751
diff changeset
   421
                                # Rebuild the url with the sanitized components.
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   422
                                ivalues["pkg"]["proxy_base"] = \
3234
3a90dc0b66c9 21188662 use six library for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3194
diff changeset
   423
                                    urlunparse((scheme, netloc, path,
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   424
                                    params, query, fragment))
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
   425
                        elif opt == "--readonly":
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   426
                                ivalues["pkg"]["readonly"] = True
157
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
   427
                        elif opt == "--rebuild":
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   428
                                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
   429
                        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
   430
                                # Note: This argument is for internal use
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   431
                                # only.
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   432
                                #
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   433
                                # 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
   434
                                # 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
   435
                                # 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
   436
                                # 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
   437
                                # 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
   438
                                # 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
   439
                                reindex = True
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   440
                                exit_ready = True
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   441
                        elif opt == "--set-property":
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   442
                                try:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   443
                                        prop, p_value = arg.split("=", 1)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   444
                                        p_sec, p_name = prop.split(".", 1)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   445
                                except ValueError:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   446
                                        usage(_("property arguments must be of "
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   447
                                            "the form '<section.property>="
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   448
                                            "<value>'."))
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   449
                                repo_props.setdefault(p_sec, {})
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   450
                                repo_props[p_sec][p_name] = p_value
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   451
                        elif opt == "--ssl-cert-file":
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   452
                                if arg == "none" or arg == "":
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   453
                                        # Assume this is an override to clear
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   454
                                        # the value.
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   455
                                        arg = ""
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   456
                                elif not os.path.isabs(arg):
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   457
                                        raise OptionError("The path to "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   458
                                           "the Certificate file must be "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   459
                                           "absolute.")
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   460
                                elif not os.path.exists(arg):
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   461
                                        raise OptionError("The specified "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   462
                                            "file does not exist.")
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   463
                                elif not os.path.isfile(arg):
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   464
                                        raise OptionError("The specified "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   465
                                            "pathname is not a file.")
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   466
                                ivalues["pkg"]["ssl_cert_file"] = arg
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   467
                        elif opt == "--ssl-key-file":
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   468
                                if arg == "none" or arg == "":
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   469
                                        # Assume this is an override to clear
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   470
                                        # the value.
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   471
                                        arg = ""
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   472
                                elif not os.path.isabs(arg):
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   473
                                        raise OptionError("The path to "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   474
                                           "the Private Key file must be "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   475
                                           "absolute.")
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   476
                                elif not os.path.exists(arg):
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   477
                                        raise OptionError("The specified "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   478
                                            "file does not exist.")
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   479
                                elif not os.path.isfile(arg):
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   480
                                        raise OptionError("The specified "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   481
                                            "pathname is not a file.")
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   482
                                ivalues["pkg"]["ssl_key_file"] = arg
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   483
                        elif opt == "--ssl-dialog":
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   484
                                if arg != "builtin" and \
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   485
                                    arg != "smf" and not \
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   486
                                    arg.startswith("exec:/") and not \
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   487
                                    arg.startswith("svc:"):
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   488
                                        raise OptionError("Invalid value "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   489
                                            "specified.  Expected: builtin, "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   490
                                            "exec:/path/to/program, smf, or "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   491
                                            "an SMF FMRI.")
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   492
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   493
                                if arg.startswith("exec:"):
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   494
                                        if os_util.get_canonical_os_type() != \
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   495
                                          "unix":
873
b95d76c53b5e 2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 858
diff changeset
   496
                                                # Don't allow a somewhat
b95d76c53b5e 2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 858
diff changeset
   497
                                                # insecure authentication method
b95d76c53b5e 2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 858
diff changeset
   498
                                                # on some platforms.
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   499
                                                raise OptionError("exec is "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   500
                                                    "not a supported dialog "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   501
                                                    "type for this operating "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   502
                                                    "system.")
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   503
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   504
                                        f = os.path.abspath(arg.split(
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   505
                                            "exec:")[1])
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   506
                                        if not os.path.isfile(f):
3194
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   507
                                                raise OptionError("Invalid "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   508
                                                    "file path specified for "
185fd0ebde38 20892465 convert Python 2 code more like Python 3
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3177
diff changeset
   509
                                                    "exec.")
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   510
                                ivalues["pkg"]["ssl_dialog"] = arg
1475
a667a9efcae9 7360 indexing workfile size should be configurable
John Sonnenschein <John.Sonnenschein@Sun.COM>
parents: 1433
diff changeset
   511
                        elif opt == "--sort-file-max-size":
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   512
                                ivalues["pkg"]["sort_file_max_size"] = arg
975
346745ea94fe 2701 "scratch area" for depot
Brock Pytlik <bpytlik@sun.com>
parents: 965
diff changeset
   513
                        elif opt == "--writable-root":
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   514
                                ivalues["pkg"]["writable_root"] = arg
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   515
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   516
                # Set accumulated values.
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   517
                if debug_features:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   518
                        ivalues["pkg"]["debug"] = debug_features
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   519
                if disable_ops:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   520
                        ivalues["pkg"]["disable_ops"] = disable_ops
2230
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   521
                if addresses:
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   522
                        ivalues["pkg"]["address"] = list(addresses)
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   523
2962
ce8cd4c07986 15433013 content hash handling should handle different hash functions
Tim Foster <tim.s.foster@oracle.com>
parents: 2951
diff changeset
   524
                if DebugValues:
ce8cd4c07986 15433013 content hash handling should handle different hash functions
Tim Foster <tim.s.foster@oracle.com>
parents: 2951
diff changeset
   525
                        reload(pkg.digest)
ce8cd4c07986 15433013 content hash handling should handle different hash functions
Tim Foster <tim.s.foster@oracle.com>
parents: 2951
diff changeset
   526
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   527
                # Build configuration object.
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   528
                dconf = ds.DepotConfig(target=user_cfg, overrides=ivalues)
3171
525f5bdb3f62 20434301 change exception handling syntax for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3158
diff changeset
   529
        except getopt.GetoptError as _e:
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   530
                usage("pkg.depotd: {0}".format(_e.msg))
3171
525f5bdb3f62 20434301 change exception handling syntax for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3158
diff changeset
   531
        except api_errors.ApiException as _e:
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   532
                usage("pkg.depotd: {0}".format(str(_e)))
3171
525f5bdb3f62 20434301 change exception handling syntax for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3158
diff changeset
   533
        except OptionError as _e:
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   534
                usage("pkg.depotd: option: {0} -- {1}".format(opt, _e))
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   535
        except (ArithmeticError, ValueError):
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   536
                usage("pkg.depotd: illegal option value: {0} specified " \
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   537
                    "for option: {1}".format(arg, opt))
451
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   538
1633
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   539
        if show_usage:
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   540
                usage(retcode=0, full=True)
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   541
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   542
        if not dconf.get_property("pkg", "log_errors"):
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   543
                dconf.set_property("pkg", "log_errors", "stderr")
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   544
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   545
        # If stdout is a tty, then send access output there by default instead
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   546
        # of discarding it.
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   547
        if not dconf.get_property("pkg", "log_access"):
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   548
                if os.isatty(sys.stdout.fileno()):
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   549
                        dconf.set_property("pkg", "log_access", "stdout")
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   550
                else:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   551
                        dconf.set_property("pkg", "log_access", "none")
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   552
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   553
        # Check for invalid option combinations.
2515
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   554
        image_root = dconf.get_property("pkg", "image_root")
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   555
        inst_root = dconf.get_property("pkg", "inst_root")
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   556
        mirror = dconf.get_property("pkg", "mirror")
2230
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   557
        ll_mirror = dconf.get_property("pkg", "ll_mirror")
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   558
        readonly = dconf.get_property("pkg", "readonly")
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   559
        writable_root = dconf.get_property("pkg", "writable_root")
1542
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   560
        if rebuild and add_content:
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   561
                usage("--add-content cannot be used with --rebuild")
445
76b03dd5a4ac 2693 Indexing code and catalog code should respect --read-only
Brock Pytlik <bpytlik@sun.com>
parents: 429
diff changeset
   562
        if rebuild and reindex:
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   563
                usage("--refresh-index cannot be used with --rebuild")
1542
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   564
        if (rebuild or add_content) and (readonly or mirror):
1633
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   565
                usage("--readonly and --mirror cannot be used with --rebuild "
927bff25c41c 6284 depot should support --help and -? options
Shawn Walker <srw@sun.com>
parents: 1542
diff changeset
   566
                    "or --add-content")
1020
765f4ea49070 7729 writable-root support doesn't allow depot contents to be read only
Brock Pytlik <bpytlik@sun.com>
parents: 975
diff changeset
   567
        if reindex and mirror:
765f4ea49070 7729 writable-root support doesn't allow depot contents to be read only
Brock Pytlik <bpytlik@sun.com>
parents: 975
diff changeset
   568
                usage("--mirror cannot be used with --refresh-index")
765f4ea49070 7729 writable-root support doesn't allow depot contents to be read only
Brock Pytlik <bpytlik@sun.com>
parents: 975
diff changeset
   569
        if reindex and readonly and not writable_root:
765f4ea49070 7729 writable-root support doesn't allow depot contents to be read only
Brock Pytlik <bpytlik@sun.com>
parents: 975
diff changeset
   570
                usage("--readonly can only be used with --refresh-index if "
765f4ea49070 7729 writable-root support doesn't allow depot contents to be read only
Brock Pytlik <bpytlik@sun.com>
parents: 975
diff changeset
   571
                    "--writable-root is used")
2515
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   572
        if image_root and not ll_mirror:
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   573
                usage("--image-root can only be used with --llmirror.")
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   574
        if image_root and writable_root:
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   575
                usage("--image_root and --writable-root cannot be used "
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   576
                    "together.")
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   577
        if image_root and inst_root:
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   578
                usage("--image-root and -d cannot be used together.")
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   579
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   580
        # If the image format changes this may need to be reexamined.
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   581
        if image_root:
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   582
                inst_root = os.path.join(image_root, "var", "pkg")
451
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   583
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   584
        # Set any values using defaults if they weren't provided.
2230
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   585
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   586
        # Only use the first value for now; multiple bind addresses may be
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   587
        # supported later.
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   588
        address = dconf.get_property("pkg", "address")
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   589
        if address:
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   590
                address = address[0]
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   591
        elif not address:
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   592
                dconf.set_property("pkg", "address", [HOST_DEFAULT])
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   593
                address = dconf.get_property("pkg", "address")[0]
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   594
2515
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   595
        if not inst_root:
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   596
                usage("Either PKG_REPO or -d must be provided")
1902
59b7214232cb 6957 mDNS support for depot
johansen <johansen@opensolaris.org>
parents: 1895
diff changeset
   597
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   598
        content_root = dconf.get_property("pkg", "content_root")
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   599
        if not content_root:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   600
                dconf.set_property("pkg", "content_root", CONTENT_PATH_DEFAULT)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   601
                content_root = dconf.get_property("pkg", "content_root")
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   602
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   603
        port = dconf.get_property("pkg", "port")
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   604
        ssl_cert_file = dconf.get_property("pkg", "ssl_cert_file")
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   605
        ssl_key_file = dconf.get_property("pkg", "ssl_key_file")
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   606
        if (ssl_cert_file and not ssl_key_file) or (ssl_key_file and not
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   607
            ssl_cert_file):
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   608
                usage("The --ssl-cert-file and --ssl-key-file options must "
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   609
                    "must both be provided when using either option.")
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   610
        elif not port:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   611
                if ssl_cert_file and ssl_key_file:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   612
                        dconf.set_property("pkg", "port", SSL_PORT_DEFAULT)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   613
                else:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   614
                        dconf.set_property("pkg", "port", PORT_DEFAULT)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   615
                port = dconf.get_property("pkg", "port")
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   616
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   617
        socket_timeout = dconf.get_property("pkg", "socket_timeout")
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   618
        if not socket_timeout:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   619
                dconf.set_property("pkg", "socket_timeout",
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   620
                    SOCKET_TIMEOUT_DEFAULT)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   621
                socket_timeout = dconf.get_property("pkg", "socket_timeout")
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   622
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   623
        threads = dconf.get_property("pkg", "threads")
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   624
        if not threads:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   625
                dconf.set_property("pkg", "threads", THREADS_DEFAULT)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   626
                threads = dconf.get_property("pkg", "threads")
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   627
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   628
        # 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
   629
        # the program will not bind to a port.
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   630
        if not exit_ready:
1836
33bccd66b8e2 5650 misc.port_available incorrectly returns true for ports in use only on localhost
Shawn Walker <shawn.walker@oracle.com>
parents: 1779
diff changeset
   631
                try:
2230
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   632
                        cherrypy.process.servers.check_port(address, port)
3171
525f5bdb3f62 20434301 change exception handling syntax for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3158
diff changeset
   633
                except Exception as e:
1836
33bccd66b8e2 5650 misc.port_available incorrectly returns true for ports in use only on localhost
Shawn Walker <shawn.walker@oracle.com>
parents: 1779
diff changeset
   634
                        emsg("pkg.depotd: unable to bind to the specified "
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   635
                            "port: {0:d}. Reason: {1}".format(port, e))
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 428
diff changeset
   636
                        sys.exit(1)
612
353fef98c569 4102 test suite fails if /usr/share/lib/pkg doesn't exist
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 589
diff changeset
   637
        else:
1542
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   638
                # Not applicable if we're not going to serve content
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   639
                dconf.set_property("pkg", "content_root", "")
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   640
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   641
        # Any relative paths should be made absolute using pkg_root.  'pkg_root'
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   642
        # is a special property that was added to enable internal deployment of
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   643
        # multiple disparate versions of the pkg.depotd software.
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   644
        pkg_root = dconf.get_property("pkg", "pkg_root")
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   645
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   646
        repo_config_file = dconf.get_property("pkg", "cfg_file")
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   647
        if repo_config_file and not os.path.isabs(repo_config_file):
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   648
                repo_config_file = os.path.join(pkg_root, repo_config_file)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   649
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   650
        if content_root and not os.path.isabs(content_root):
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   651
                content_root = os.path.join(pkg_root, content_root)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   652
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   653
        if inst_root and not os.path.isabs(inst_root):
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   654
                inst_root = os.path.join(pkg_root, inst_root)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   655
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   656
        if ssl_cert_file:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   657
                if ssl_cert_file == "none":
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   658
                        ssl_cert_file = None
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   659
                elif not os.path.isabs(ssl_cert_file):
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   660
                        ssl_cert_file = os.path.join(pkg_root, ssl_cert_file)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   661
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   662
        if ssl_key_file:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   663
                if ssl_key_file == "none":
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   664
                        ssl_key_file = None
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   665
                elif not os.path.isabs(ssl_key_file):
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   666
                        ssl_key_file = os.path.join(pkg_root, ssl_key_file)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   667
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   668
        if writable_root and not os.path.isabs(writable_root):
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   669
                writable_root = os.path.join(pkg_root, writable_root)
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   670
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   671
        # Setup SSL if requested.
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   672
        key_data = None
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   673
        ssl_dialog = dconf.get_property("pkg", "ssl_dialog")
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   674
        if not exit_ready and ssl_cert_file and ssl_key_file and \
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   675
            ssl_dialog != "builtin":
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   676
                cmdline = None
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   677
                def get_ssl_passphrase(*ignored):
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   678
                        p = None
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   679
                        try:
3273
776d569cd953 17983590 problem in PYTHON-MOD/PKG
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 3234
diff changeset
   680
                                if cmdline:
776d569cd953 17983590 problem in PYTHON-MOD/PKG
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 3234
diff changeset
   681
                                        cmdargs = shlex.split(cmdline)
776d569cd953 17983590 problem in PYTHON-MOD/PKG
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 3234
diff changeset
   682
                                else:
776d569cd953 17983590 problem in PYTHON-MOD/PKG
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 3234
diff changeset
   683
                                        cmdargs = []
776d569cd953 17983590 problem in PYTHON-MOD/PKG
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 3234
diff changeset
   684
                                p = subprocess.Popen(cmdargs,
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   685
                                        stdout=subprocess.PIPE,
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   686
                                        stderr=None)
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   687
                                p.wait()
3171
525f5bdb3f62 20434301 change exception handling syntax for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3158
diff changeset
   688
                        except Exception as __e:
1836
33bccd66b8e2 5650 misc.port_available incorrectly returns true for ports in use only on localhost
Shawn Walker <shawn.walker@oracle.com>
parents: 1779
diff changeset
   689
                                emsg("pkg.depotd: an error occurred while "
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   690
                                    "executing [{0}]; unable to obtain the "
1836
33bccd66b8e2 5650 misc.port_available incorrectly returns true for ports in use only on localhost
Shawn Walker <shawn.walker@oracle.com>
parents: 1779
diff changeset
   691
                                    "passphrase needed to decrypt the SSL "
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   692
                                    "private key file: {1}".format(cmdline,
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   693
                                    __e))
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   694
                                sys.exit(1)
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   695
                        return p.stdout.read().strip("\n")
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   696
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   697
                if ssl_dialog.startswith("exec:"):
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   698
                        exec_path = ssl_dialog.split("exec:")[1]
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   699
                        if not os.path.isabs(exec_path):
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   700
                                exec_path = os.path.join(pkg_root, exec_path)
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   701
                        cmdline = "{0} {1} {2:d}".format(exec_path, "''", port)
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   702
                elif ssl_dialog == "smf" or ssl_dialog.startswith("svc:"):
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   703
                        if ssl_dialog == "smf":
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   704
                                # Assume the configuration target was an SMF
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   705
                                # FMRI and let svcprop fail with an error if
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   706
                                # it wasn't.
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   707
                                svc_fmri = dconf.target
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   708
                        else:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   709
                                svc_fmri = ssl_dialog
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   710
                        cmdline = "/usr/bin/svcprop -p " \
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   711
                            "pkg_secure/ssl_key_passphrase {0}".format(svc_fmri)
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   712
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   713
                # The key file requires decryption, but the user has requested
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   714
                # exec-based authentication, so it will have to be decoded first
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   715
                # to an un-named temporary file.
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   716
                try:
3234
3a90dc0b66c9 21188662 use six library for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3194
diff changeset
   717
                        with open(ssl_key_file, "rb") as key_file:
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   718
                                pkey = crypto.load_privatekey(
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   719
                                    crypto.FILETYPE_PEM, key_file.read(),
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   720
                                    get_ssl_passphrase)
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   721
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   722
                        key_data = tempfile.TemporaryFile()
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   723
                        key_data.write(crypto.dump_privatekey(
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   724
                            crypto.FILETYPE_PEM, pkey))
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   725
                        key_data.seek(0)
3171
525f5bdb3f62 20434301 change exception handling syntax for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3158
diff changeset
   726
                except EnvironmentError as _e:
1836
33bccd66b8e2 5650 misc.port_available incorrectly returns true for ports in use only on localhost
Shawn Walker <shawn.walker@oracle.com>
parents: 1779
diff changeset
   727
                        emsg("pkg.depotd: unable to read the SSL private key "
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   728
                            "file: {0}".format(_e))
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   729
                        sys.exit(1)
3171
525f5bdb3f62 20434301 change exception handling syntax for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3158
diff changeset
   730
                except crypto.Error as _e:
1836
33bccd66b8e2 5650 misc.port_available incorrectly returns true for ports in use only on localhost
Shawn Walker <shawn.walker@oracle.com>
parents: 1779
diff changeset
   731
                        emsg("pkg.depotd: authentication or cryptography "
33bccd66b8e2 5650 misc.port_available incorrectly returns true for ports in use only on localhost
Shawn Walker <shawn.walker@oracle.com>
parents: 1779
diff changeset
   732
                            "failure while attempting to decode\nthe SSL "
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   733
                            "private key file: {0}".format(_e))
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   734
                        sys.exit(1)
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   735
                else:
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   736
                        # Redirect the server to the decrypted key file.
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   737
                        ssl_key_file = "/dev/fd/{0:d}".format(key_data.fileno())
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   738
452
01f53c6381af 2714 image-update failure during update phase
Shawn Walker <shawn.walker@sun.com>
parents: 451
diff changeset
   739
        # Setup our global configuration.
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   740
        gconf = {
858
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   741
            "checker.on": True,
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   742
            "environment": "production",
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   743
            "log.screen": False,
965
6efb5042a707 7552 depot aborts connection for add operations with payload greater than 100MB
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 916
diff changeset
   744
            "server.max_request_body_size": MAX_REQUEST_BODY_SIZE,
858
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   745
            "server.shutdown_timeout": 0,
2230
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   746
            "server.socket_host": address,
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   747
            "server.socket_port": port,
858
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   748
            "server.socket_timeout": socket_timeout,
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   749
            "server.ssl_certificate": ssl_cert_file,
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   750
            "server.ssl_private_key": ssl_key_file,
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   751
            "server.thread_pool": threads,
742
909b912fa942 3011 new depot index page desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 689
diff changeset
   752
            "tools.log_headers.on": True,
858
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   753
            "tools.encode.on": True
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   754
        }
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   755
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   756
        if "headers" in dconf.get_property("pkg", "debug"):
858
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   757
                # Despite its name, this only logs headers when there is an
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   758
                # error; it's redundant with the debug feature enabled.
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   759
                gconf["tools.log_headers.on"] = False
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   760
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   761
                # Causes the headers of every request to be logged to the error
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   762
                # log; even if an exception occurs.
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   763
                gconf["tools.log_headers_always.on"] = True
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   764
                cherrypy.tools.log_headers_always = cherrypy.Tool(
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   765
                    "on_start_resource",
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   766
                    cherrypy.lib.cptools.log_request_headers)
c8f3fcec3301 6245 intent information is not properly sent
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 817
diff changeset
   767
2992
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   768
        log_cfg = {
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   769
            "access": dconf.get_property("pkg", "log_access"),
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   770
            "errors": dconf.get_property("pkg", "log_errors")
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   771
        }
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   772
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   773
        # If stdin is not a tty and the pkgdepot controller isn't being used,
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   774
        # then assume process will be daemonized and redirect output.
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   775
        if not os.environ.get("PKGDEPOT_CONTROLLER") and \
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   776
            not os.isatty(sys.stdin.fileno()):
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   777
                # Ensure log handlers are setup to use the file descriptors for
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   778
                # stdout and stderr as the Daemonizer (used for test suite and
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   779
                # SMF service) requires this.
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   780
                if log_cfg["access"] == "stdout":
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   781
                        log_cfg["access"] = "/dev/fd/{0:d}".format(
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   782
                            sys.stdout.fileno())
2992
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   783
                elif log_cfg["access"] == "stderr":
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   784
                        log_cfg["access"] = "/dev/fd/{0:d}".format(
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   785
                            sys.stderr.fileno())
2992
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   786
                elif log_cfg["access"] == "none":
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   787
                        log_cfg["access"] = "/dev/null"
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   788
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   789
                if log_cfg["errors"] == "stderr":
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   790
                        log_cfg["errors"] = "/dev/fd/{0:d}".format(
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   791
                            sys.stderr.fileno())
2992
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   792
                elif log_cfg["errors"] == "stdout":
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   793
                        log_cfg["errors"] = "/dev/fd/{0:d}".format(
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   794
                            sys.stdout.fileno())
2992
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   795
                elif log_cfg["errors"] == "none":
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   796
                        log_cfg["errors"] = "/dev/null"
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   797
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   798
        log_type_map = {
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   799
            "errors": {
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   800
                "param": "log.error_file",
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   801
                "attr": "error_log"
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   802
            },
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   803
            "access": {
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   804
                "param": "log.access_file",
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   805
                "attr": "access_log"
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   806
            }
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   807
        }
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   808
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   809
        for log_type in log_type_map:
2992
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   810
                dest = log_cfg[log_type]
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   811
                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
   812
                        if dest == "none":
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   813
                                h = logging.StreamHandler(LogSink())
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   814
                        else:
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   815
                                h = logging.StreamHandler(eval("sys.{0}".format(
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   816
                                    dest)))
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   817
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   818
                        h.setLevel(logging.DEBUG)
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   819
                        h.setFormatter(cherrypy._cplogging.logfmt)
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   820
                        log_obj = eval("cherrypy.log.{0}".format(
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   821
                            log_type_map[log_type]["attr"]))
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   822
                        log_obj.addHandler(h)
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   823
                        # 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
   824
                        # 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
   825
                        dest = ""
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   826
                elif dest:
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   827
                        if not os.path.isabs(dest):
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   828
                                dest = os.path.join(pkg_root, dest)
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   829
                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
   830
612
353fef98c569 4102 test suite fails if /usr/share/lib/pkg doesn't exist
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 589
diff changeset
   831
        cherrypy.config.update(gconf)
353fef98c569 4102 test suite fails if /usr/share/lib/pkg doesn't exist
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 589
diff changeset
   832
353fef98c569 4102 test suite fails if /usr/share/lib/pkg doesn't exist
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 589
diff changeset
   833
        # Now that our logging, etc. has been setup, it's safe to perform any
353fef98c569 4102 test suite fails if /usr/share/lib/pkg doesn't exist
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 589
diff changeset
   834
        # remaining preparation.
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   835
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   836
        # Initialize repository state.
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   837
        if not readonly:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   838
                # Not readonly, so assume a new repository should be created.
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   839
                try:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   840
                        sr.repository_create(inst_root, properties=repo_props)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   841
                except sr.RepositoryExistsError:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   842
                        # Already exists, nothing to do.
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   843
                        pass
3171
525f5bdb3f62 20434301 change exception handling syntax for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3158
diff changeset
   844
                except (api_errors.ApiException, sr.RepositoryError) as _e:
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   845
                        emsg("pkg.depotd: {0}".format(_e))
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   846
                        sys.exit(1)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   847
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   848
        try:
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   849
                sort_file_max_size = dconf.get_property("pkg",
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   850
                    "sort_file_max_size")
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   851
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   852
                repo = sr.Repository(cfgpathname=repo_config_file,
2515
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   853
                    log_obj=cherrypy, mirror=mirror, properties=repo_props,
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   854
                    read_only=readonly, root=inst_root,
c84f703961a9 17988 dynamic-mirror service needs update for image format changes
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2507
diff changeset
   855
                    sort_file_max_size=sort_file_max_size,
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   856
                    writable_root=writable_root)
3171
525f5bdb3f62 20434301 change exception handling syntax for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3158
diff changeset
   857
        except (RuntimeError, sr.RepositoryError) as _e:
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   858
                emsg("pkg.depotd: {0}".format(_e))
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   859
                sys.exit(1)
3171
525f5bdb3f62 20434301 change exception handling syntax for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3158
diff changeset
   860
        except search_errors.IndexingException as _e:
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   861
                emsg("pkg.depotd: {0}".format(str(_e)), "INDEX")
1672
3a71439a03f3 13021 file manager exceptions should be api exceptions
Shawn Walker <srw@sun.com>
parents: 1633
diff changeset
   862
                sys.exit(1)
3171
525f5bdb3f62 20434301 change exception handling syntax for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3158
diff changeset
   863
        except api_errors.ApiException as _e:
3158
58c9c2c21e67 20177033 change string formatting for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3143
diff changeset
   864
                emsg("pkg.depotd: {0}".format(str(_e)))
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   865
                sys.exit(1)
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   866
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   867
        if not rebuild and not add_content and not repo.mirror and \
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   868
            not (repo.read_only and not repo.writable_root):
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   869
                # Automatically update search indexes on startup if not already
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   870
                # told to, and not in readonly/mirror mode.
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   871
                reindex = True
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   872
612
353fef98c569 4102 test suite fails if /usr/share/lib/pkg doesn't exist
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 589
diff changeset
   873
        if reindex:
617
d146e7256c65 4048 A PartialIndexingException on the depot shouldn't stack trace or cause usage to be displayed
Brock Pytlik <bpytlik@sun.com>
parents: 612
diff changeset
   874
                try:
2065
314bed0b4ef8 16982 depot should be more cooperative about indexing during startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
   875
                        # Only execute a index refresh here if --exit-ready was
314bed0b4ef8 16982 depot should be more cooperative about indexing during startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
   876
                        # requested; it will be handled later in the setup
314bed0b4ef8 16982 depot should be more cooperative about indexing during startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
   877
                        # process for other cases.
314bed0b4ef8 16982 depot should be more cooperative about indexing during startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
   878
                        if repo.root and exit_ready:
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   879
                                repo.refresh_index()
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   880
                except (sr.RepositoryError, search_errors.IndexingException,
3171
525f5bdb3f62 20434301 change exception handling syntax for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3158
diff changeset
   881
                    api_errors.ApiException) as e:
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   882
                        emsg(str(e), "INDEX")
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   883
                        sys.exit(1)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   884
        elif rebuild:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   885
                try:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   886
                        repo.rebuild(build_index=True)
3171
525f5bdb3f62 20434301 change exception handling syntax for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3158
diff changeset
   887
                except sr.RepositoryError as e:
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   888
                        emsg(str(e), "REBUILD")
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   889
                        sys.exit(1)
975
346745ea94fe 2701 "scratch area" for depot
Brock Pytlik <bpytlik@sun.com>
parents: 965
diff changeset
   890
                except (search_errors.IndexingException,
1779
b80275b45b18 14176 copytree callers must catch shutil.Error and not traceback
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
   891
                    api_errors.UnknownErrors,
3171
525f5bdb3f62 20434301 change exception handling syntax for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3158
diff changeset
   892
                    api_errors.PermissionsException) as e:
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   893
                        emsg(str(e), "INDEX")
617
d146e7256c65 4048 A PartialIndexingException on the depot shouldn't stack trace or cause usage to be displayed
Brock Pytlik <bpytlik@sun.com>
parents: 612
diff changeset
   894
                        sys.exit(1)
1542
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   895
        elif add_content:
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   896
                try:
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   897
                        repo.add_content()
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   898
                        repo.refresh_index()
3171
525f5bdb3f62 20434301 change exception handling syntax for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3158
diff changeset
   899
                except sr.RepositoryError as e:
1542
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   900
                        emsg(str(e), "ADD_CONTENT")
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   901
                        sys.exit(1)
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   902
                except (search_errors.IndexingException,
1779
b80275b45b18 14176 copytree callers must catch shutil.Error and not traceback
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
   903
                    api_errors.UnknownErrors,
3171
525f5bdb3f62 20434301 change exception handling syntax for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3158
diff changeset
   904
                    api_errors.PermissionsException) as e:
1542
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   905
                        emsg(str(e), "INDEX")
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   906
                        sys.exit(1)
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   907
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 1968
diff changeset
   908
        # Ready to start depot; exit now if requested.
1542
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   909
        if exit_ready:
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   910
                sys.exit(0)
c97893ed7cd4 12891 pkgsend publish should support the --no-index flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1516
diff changeset
   911
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   912
        # Next, initialize depot.
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   913
        if nasty:
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   914
                depot = ds.NastyDepotHTTP(repo, dconf)
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   915
        else:
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   916
                depot = ds.DepotHTTP(repo, dconf)
612
353fef98c569 4102 test suite fails if /usr/share/lib/pkg doesn't exist
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 589
diff changeset
   917
451
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   918
        # Now build our site configuration.
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   919
        conf = {
3274
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
   920
            "/": {},
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   921
            "/robots.txt": {
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   922
                "tools.staticfile.on": True,
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   923
                "tools.staticfile.filename": os.path.join(depot.web_root,
382
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   924
                    "robots.txt")
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   925
            },
95304bd3b365 1854 rework depot to use higher-level framework
Shawn Walker <swalker@opensolaris.org>
parents: 374
diff changeset
   926
        }
3274
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
   927
        if list(map(int, version)) >= [3, 2, 0]:
e06a0700e218 15768696 evaluate changes needed to upgrade to external python libraries
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3273
diff changeset
   928
                conf["/"]["request.dispatch"] = Pkg5Dispatcher()
145
08bee7fd13f6 Add versioning to the protocols
Danek Duvall <danek.duvall@sun.com>
parents: 135
diff changeset
   929
1968
c0540b1e4f7e 8722 advanced repository metadata store needed
Shawn Walker <shawn.walker@oracle.com>
parents: 1963
diff changeset
   930
        proxy_base = dconf.get_property("pkg", "proxy_base")
451
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   931
        if proxy_base:
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   932
                # 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
   933
                # 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
   934
                # or some other webserver process.
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   935
                #
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   936
                # 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
   937
                #    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
   938
                proxy_conf = {
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   939
                        "tools.proxy.on": True,
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   940
                        "tools.proxy.local": "",
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   941
                        "tools.proxy.base": proxy_base
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   942
                }
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   943
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   944
                # 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
   945
                # existing configuration.
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   946
                for entry in proxy_conf:
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   947
                        conf["/"][entry] = proxy_conf[entry]
74f1fe85fe2d 1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents: 445
diff changeset
   948
1902
59b7214232cb 6957 mDNS support for depot
johansen <johansen@opensolaris.org>
parents: 1895
diff changeset
   949
        if ll_mirror:
2230
76f30e842e82 15750 depot bind address should be configurable
Shawn Walker <shawn.walker@oracle.com>
parents: 2100
diff changeset
   950
                ds.DNSSD_Plugin(cherrypy.engine, gconf).subscribe()
1902
59b7214232cb 6957 mDNS support for depot
johansen <johansen@opensolaris.org>
parents: 1895
diff changeset
   951
2065
314bed0b4ef8 16982 depot should be more cooperative about indexing during startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
   952
        if reindex:
314bed0b4ef8 16982 depot should be more cooperative about indexing during startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
   953
                # Tell depot to update search indexes when possible;
314bed0b4ef8 16982 depot should be more cooperative about indexing during startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
   954
                # this is done as a background task so that packages
314bed0b4ef8 16982 depot should be more cooperative about indexing during startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
   955
                # can be served immediately while search indexes are
314bed0b4ef8 16982 depot should be more cooperative about indexing during startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
   956
                # still being updated.
314bed0b4ef8 16982 depot should be more cooperative about indexing during startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
   957
                depot._queue_refresh_index()
314bed0b4ef8 16982 depot should be more cooperative about indexing during startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
   958
2507
d2873152e497 15761 pkg/server is duration=child, foils SMF's fault detection
Shawn Walker <shawn.walker@oracle.com>
parents: 2230
diff changeset
   959
        # If stdin is not a tty and the pkgdepot controller isn't being used,
d2873152e497 15761 pkg/server is duration=child, foils SMF's fault detection
Shawn Walker <shawn.walker@oracle.com>
parents: 2230
diff changeset
   960
        # then assume process should be daemonized.
d2873152e497 15761 pkg/server is duration=child, foils SMF's fault detection
Shawn Walker <shawn.walker@oracle.com>
parents: 2230
diff changeset
   961
        if not os.environ.get("PKGDEPOT_CONTROLLER") and \
d2873152e497 15761 pkg/server is duration=child, foils SMF's fault detection
Shawn Walker <shawn.walker@oracle.com>
parents: 2230
diff changeset
   962
            not os.isatty(sys.stdin.fileno()):
2992
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   963
                # Translate the values in log_cfg into paths.
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   964
                Daemonizer(cherrypy.engine, stderr=log_cfg["errors"],
e48a94cff862 15813784 logging to stderr/stdout broken for svc:/application/pkg/server
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2962
diff changeset
   965
                    stdout=log_cfg["access"]).subscribe()
2507
d2873152e497 15761 pkg/server is duration=child, foils SMF's fault detection
Shawn Walker <shawn.walker@oracle.com>
parents: 2230
diff changeset
   966
814
76909c2cad8f 5603 server catalog permissions should be 644, not 600
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 812
diff changeset
   967
        try:
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1288
diff changeset
   968
                root = cherrypy.Application(depot)
466
7cfb6502ff1b 2333 control over access / error log destination desired
Shawn Walker <shawn.walker@sun.com>
parents: 461
diff changeset
   969
                cherrypy.quickstart(root, config=conf)
3171
525f5bdb3f62 20434301 change exception handling syntax for python 3 migration
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3158
diff changeset
   970
        except Exception as _e:
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   971
                emsg("pkg.depotd: unknown error starting depot server, " \
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   972
                    "illegal option value specified?")
873
b95d76c53b5e 2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 858
diff changeset
   973
                emsg(_e)
812
7e82ae7acf48 2154 pkg.depotd should offer SSL/HTTPS option
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 797
diff changeset
   974
                sys.exit(1)