#!/usr/bin/env python # Sync the ISC configuartion file and the SQL database # Copyright (C) 2000, 2001 James Troup # $Id: alyson,v 1.4 2001-03-20 00:28:11 troup Exp $ # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ################################################################################ import pg, sys, string import utils, db_access import apt_pkg; ################################################################################ Cnf = None; projectB = None; ################################################################################ def main (): global Cnf, projectB; apt_pkg.init(); Cnf = apt_pkg.newConfiguration(); apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file()); Arguments = [('D',"debug","Alyson::Options::Debug", "IntVal"), ('h',"help","Alyson::Options::Help"), ('v',"version","Alyson::Options::Version")]; apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv); projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])); db_access.init(Cnf, projectB); # Quick hack to populate section, priority and bin_type; the rest todo later projectB.query("BEGIN WORK"); projectB.query("DELETE FROM override_type"); for type in Cnf.SubTree("OverrideType").List(): projectB.query("INSERT INTO override_type (type) VALUES ('%s')" % (type)); projectB.query("COMMIT WORK"); projectB.query("BEGIN WORK"); projectB.query("DELETE FROM priority"); for priority in Cnf.SubTree("Priority").List(): projectB.query("INSERT INTO priority (priority, level) VALUES ('%s', %s)" % (priority, Cnf["Priority::%s" % (priority)])); projectB.query("COMMIT WORK"); projectB.query("BEGIN WORK"); projectB.query("DELETE FROM section"); for component in Cnf.SubTree("Component").List(): if Cnf["Natalie::ComponentPosition"] == "prefix": suffix = ""; if component != 'main': prefix = component + '/'; else: prefix = ""; else: prefix = ""; component = string.replace(component, "non-US/", ""); if component != 'main': suffix = '/' + component; else: suffix = ""; for section in Cnf.SubTree("Section").List(): projectB.query("INSERT INTO section (section) VALUES ('%s%s%s')" % (prefix, section, suffix)); projectB.query("COMMIT WORK"); ####################################################################################### if __name__ == '__main__': main()