~styluseater/swift/lp610583

« back to all changes in this revision

Viewing changes to bin/swift-container-replicator

  • Committer: Adam M Dutko
  • Date: 2010-07-28 23:41:37 UTC
  • Revision ID: dutko.adam@gmail.com-20100728234137-bvrnfngu9z1htx9b
Changed getopt to optparse for three scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import sys
18
18
from ConfigParser import ConfigParser
19
 
import getopt
 
19
from optparse import OptionParser
20
20
 
21
21
from swift.container import server as container_server
22
22
from swift.common import db, db_replicator, utils
23
23
 
 
24
usage = "Usage: container-replicator -c CONFIG_FILE --once" 
 
25
 
24
26
class ContainerReplicator(db_replicator.Replicator):
25
27
    server_type = 'container'
26
28
    ring_file = 'container.ring.gz'
29
31
    default_port = 6001
30
32
 
31
33
if __name__ == '__main__':
32
 
    optlist, args = getopt.getopt(sys.argv[1:], '', ['once'])
 
34
    parser = OptionParser()
 
35
    parser.add_option("-c", "--config", dest="config",
 
36
                    help="Path to the configuration file.")
 
37
    parser.add_option("--once", action="store_true", dest="once",
 
38
                    help="Run the replicator once.")
33
39
 
34
 
    if not args:
35
 
        print "Usage: container-replicator <--once> CONFIG_FILE [once]"
36
 
        sys.exit()
 
40
    (options, args) = parser.parse_args()
37
41
 
38
42
    c = ConfigParser()
39
 
    if not c.read(args[0]):
 
43
    if not c.read(options.config):
40
44
        print "Unable to read config file."
41
45
        sys.exit(1)
42
 
    once = len(args) > 1 and args[1] == 'once'
43
46
 
44
47
    server_conf = dict(c.items('container-server'))
45
48
    if c.has_section('container-replicator'):
46
49
        replicator_conf = dict(c.items('container-replicator'))
47
50
    else:
48
51
        print "Unable to find container-replicator config section in %s." % \
49
 
                args[0]
 
52
            options.config   
50
53
        sys.exit(1)
51
54
 
52
55
    utils.drop_privileges(server_conf.get('user', 'swift'))
53
 
    if once or '--once' in [opt[0] for opt in optlist]:
 
56
    if options.once:
54
57
        ContainerReplicator(server_conf, replicator_conf).replicate_once()
55
58
    else:
56
59
        ContainerReplicator(server_conf, replicator_conf).replicate_forever()