# init.py -- Initialize the replicator
#
# Richard Brooksby, Ravenbrook Limited, 2000-12-08.
#
# $Id: //info.ravenbrook.com/project/p4dti/branch/2001-01-16/new-teamshare-api/code/replicator/init.py#1 $
#
# Copyright 2000 Ravenbrook Limited.  This document is provided "as is",
# without any express or implied warranty. In no event will the authors
# be held liable for any damages arising from the use of this document.
# You may make and distribute copies and derivative works of this
# document provided that (1) you do not charge a fee for this document or
# for its distribution, and (2) you retain as they appear all copyright
# and licence notices and document history entries, and (3) you append
# descriptions of your modifications to the document history.
#

import p4
import replicator

from config import *

if dt_name == "TeamTrack":

    import configure_teamtrack
    import dt_teamtrack

    teamtrack_config, p4_config, replicator_config, jobspec = \
        configure_teamtrack.configuration \
        (
         administrator_address = administrator_address,
         changelist_url = changelist_url,
         closed_state = closed_state,
         log_file = log_file,
         p4_client_executable = p4_client_executable,
         p4_password = p4_password,
         p4_port = p4_port,
         p4_server_description = p4_server_description,
         p4_user = p4_user,
         replicator_address = replicator_address,
         replicated_fields = replicated_fields,
         smtp_server = smtp_server,
         teamtrack_password = teamtrack_password,
         teamtrack_server = teamtrack_server,
         teamtrack_user = teamtrack_user,
         verbose = verbose,
         )
    
    dt = dt_teamtrack.dt_teamtrack(rid, sid, teamtrack_config)

elif dt_name == "Bugzilla":

    import configure_bugzilla
    import dt_bugzilla

    bugzilla_config, p4_config, replicator_config, jobspec = \
        configure_bugzilla.configuration \
        (
         administrator_address = administrator_address,
         changelist_url = changelist_url,
         closed_state = closed_state,
         log_file = log_file,
         p4_client_executable = p4_client_executable,
         p4_password = p4_password,
         p4_port = p4_port,
         p4_server_description = p4_server_description,
         p4_user = p4_user,
         replicator_address = replicator_address,
         replicated_fields = replicated_fields,
         rid = rid,
         sid = sid,
         smtp_server = smtp_server,
         dbms_host = dbms_host,
         dbms_database = dbms_database,
         dbms_port = dbms_port,
         dbms_user = dbms_user,
         dbms_password = dbms_password,
         bugzilla_user = bugzilla_user,
         verbose = verbose,
        )
    
    dt = dt_bugzilla.dt_bugzilla(bugzilla_config)

else:

    raise "Configuration error", "The defect tracker '%s' is not supported." % dt_name

p4_interface = p4.p4(p4_config)

r = replicator.replicator(rid, dt, p4_interface, replicator_config)

r.p4.run('jobspec -i', [jobspec])

r.init()

#
# B. Document History
# 
# 2000-11-30  GDR  Added changelist_url configuration parameter.
# 
# 2000-12-04 GDR Alphabetized parameters.  Added replicator_address.  Made sure
# to pass all parameters to configure_teamtrack.
#
# 2000-12-08 RB  Moved configuration parameters to config.py.  Merged separate
# TeamTrack and Bugzilla activation scripts.
#
# 2001-01-11 NB  Bugzilla startup has changed because configure_bugzilla
# now opens the MySQL connection.
