1 # -*- coding: utf-8 -*-
4 ## This file is part of Indico.
5 ## Copyright (C) 2002 - 2012 European Organization for Nuclear Research (CERN).
7 ## Indico is free software; you can redistribute it and/or
8 ## modify it under the terms of the GNU General Public License as
9 ## published by the Free Software Foundation; either version 3 of the
10 ## License, or (at your option) any later version.
12 ## Indico is distributed in the hope that it will be useful, but
13 ## WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ## General Public License for more details.
17 ## You should have received a copy of the GNU General Public License
18 ## along with Indico;if not, see <http://www.gnu.org/licenses/>.
21 """Connect to a ZEO server and ask it to pack.
23 Usage: zeopack.py [options]
27 -p port -- port to connect to
29 -h host -- host to connect to (default is current host)
31 -U path -- Unix-domain socket to connect to
33 -S name -- storage name (default is '1')
35 -d days -- pack objects more than days old
37 -1 -- Connect to a ZEO 1 server
39 -W -- wait for server to come up. Normally the script tries to
40 connect for 10 seconds, then exits with an error. The -W
41 option is only supported with ZEO 1.
43 You must specify either -p and -h or -U.
51 from ZEO
.ClientStorage
import ClientStorage
53 WAIT
= 10 # wait no more than 10 seconds for client to connect
56 # The connect-on-startup logic that ZEO provides isn't too useful
57 # for this script. We'd like to client to attempt to startup, but
58 # fail if it can't get through to the server after a reasonable
59 # amount of time. There's no external support for this, so we'll
60 # expose the ZEO 1.0 internals. (consenting adults only)
62 while t0
+ WAIT
> time
.time():
63 storage
._call
.connect()
64 if storage
._connected
:
66 raise RuntimeError, "Unable to connect to ZEO server"
68 def pack1(addr
, storage
, days
, wait
):
69 cs
= ClientStorage(addr
, storage
=storage
,
70 wait_for_server_on_startup
=wait
)
72 # _startup() is an artifact of the way ZEO 1.0 works. The
73 # ClientStorage doesn't get fully initialized until registerDB()
74 # is called. The only thing we care about, though, is that
75 # registerDB() calls _startup().
80 cs
.pack(wait
=1, days
=days
)
83 def pack2(addr
, storage
, days
):
84 cs
= ClientStorage(addr
, storage
=storage
, wait
=1, read_only
=1)
85 cs
.pack(wait
=1, days
=days
)
90 print " ".join(sys
.argv
)
102 opts
, args
= getopt
.getopt(sys
.argv
[1:], 'p:h:U:S:d:W1')
118 except Exception, err
:
126 host
= socket
.gethostname()
132 pack1(addr
, storage
, days
, wait
)
134 pack2(addr
, storage
, days
)
136 if __name__
== "__main__":
139 except Exception, err
: