From 95ee2535ab74f16d0e46a030ba5c728cc1129c70 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Thu, 29 Jan 2004 01:00:08 +0000 Subject: [PATCH] * alicia: Added * docs/alicia.1.sgml: Added * docs/Makefile: Added alicia to the list of manpages to build * docs/README.names: Noted what alicia does * docs/README.first: Noted where alicia is useful --- alicia | 206 +++++++++++++++++++++++++++++++++++++++++++++ docs/Makefile | 2 +- docs/README.first | 2 + docs/alicia.1.sgml | 82 ++++++++++++++++++ 4 files changed, 291 insertions(+), 1 deletion(-) create mode 100755 alicia create mode 100644 docs/alicia.1.sgml diff --git a/alicia b/alicia new file mode 100755 index 00000000..50e5745d --- /dev/null +++ b/alicia @@ -0,0 +1,206 @@ +#!/usr/bin/env python + +# Microscopic modification and query tool for overrides in projectb +# Copyright (C) 2004 Daniel Silverstone +# $Id: alicia,v 1.1 2004-01-29 01:00:08 dsilvers 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 + + +################################################################################ +## So line up your soldiers and she'll shoot them all down +## Coz Alisha Rules The World +## You think you found a dream, then it shatters and it seems, +## That Alisha Rules The World +################################################################################ + +import pg, pwd, sys; +import utils, db_access; +import apt_pkg, logging; + +################################################################################ + +Cnf = None; +projectB = None; + +################################################################################ + +# Shamelessly stolen from melanie. Should probably end up in utils.py +def game_over(): + answer = utils.our_raw_input("Continue (y/N)? ").lower(); + if answer != "y": + print "Aborted." + sys.exit(1); + + +def usage (exit_code=0): + print """Usage: alicia [OPTIONS] package [section priority] +Make a microscopic override change/query + + -h, --help show this help and exit + -n, --no-action don't do anything + -s, --suite specify the suite to use +""" + sys.exit(exit_code) + +def main (): + global Cnf, projectB; + + Cnf = utils.get_conf() + + Arguments = [('h',"help","Alicia::Options::Help"), + ('n',"no-action","Alicia::Options::No-Action"), + ('s',"suite","Alicia::Options::Suite", "HasArg"), + ]; + for i in ["help", "no-action"]: + if not Cnf.has_key("Alicia::Options::%s" % (i)): + Cnf["Alicia::Options::%s" % (i)] = ""; + if not Cnf.has_key("Alicia::Options::Suite"): + Cnf["Alicia::Options::Suite"] = "unstable"; + + arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv); + Options = Cnf.SubTree("Alicia::Options") + + if Options["Help"]: + usage(); + + projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])); + db_access.init(Cnf, projectB); + + if not arguments: + utils.fubar("package name is a required argument."); + + package = arguments.pop(0); + + if arguments and len(arguments) > 2: + utils.fubar("Too many arguments"); + + if arguments and len(arguments) == 1: + # Determine if the argument is a priority or a section... + arg = arguments.pop(); + q = projectB.query(""" + SELECT ( SELECT COUNT(*) FROM section WHERE section=%s ) AS secs, + ( SELECT COUNT(*) FROM priority WHERE priority=%s ) AS prios + """ % ( pg._quote(arg,"str"), pg._quote(arg,"str"))); + r = q.getresult(); + if r[0][0] == 1: + arguments = (arg,"."); + elif r[0][1] == 1: + arguments = (".",arg); + else: + utils.fubar("%s is not a valid section or priority"); + + + # Retrieve current section/priority... + q = projectB.query(""" + SELECT priority.priority AS prio, section.section AS sect + FROM override, priority, section, suite + WHERE override.priority = priority.id + AND override.section = section.id + AND override.package = %s + AND override.suite = suite.id + AND suite.suite_name = %s + """ % (pg._quote(package,"str"), pg._quote(Options["Suite"],"str"))); + + if q.ntuples() == 0: + utils.fubar("Unable to find package %s" % (package)); + if q.ntuples() > 1: + utils.fubar("%s is ambiguous. Matches %d packages" % (package,q.ntuples())); + + r = q.getresult(); + oldsection = r[0][1]; + oldpriority = r[0][0]; + + if not arguments: + print "%s is in section '%s' at priority '%s'" % ( + package,oldsection,oldpriority); + sys.exit(0); + + # At this point, we have a new section and priority... check they're valid... + newsection, newpriority = arguments; + + if newsection == ".": + newsection = oldsection; + if newpriority == ".": + newpriority = oldpriority; + + q = projectB.query("SELECT id FROM section WHERE section=%s" % ( + pg._quote(newsection,"str"))); + + if q.ntuples() == 0: + utils.fubar("Supplied section %s is invalid" % (newsection)); + newsecid = q.getresult()[0][0]; + + q = projectB.query("SELECT id FROM priority WHERE priority=%s" % ( + pg._quote(newpriority,"str"))); + + if q.ntuples() == 0: + utils.fubar("Supplied priority %s is invalid" % (newpriority)); + newprioid = q.getresult()[0][0]; + + if newpriority == oldpriority and newsection == oldsection: + print "I: Doing nothing" + sys.exit(0); + + # If we're in no-action mode + if Options["No-Action"]: + if newpriority != oldpriority: + print "I: Would change priority from %s to %s" % (oldpriority,newpriority); + if newsection != oldsection: + print "I: Would change section from %s to %s" % (oldsection,newsection); + sys.exit(0); + + if newpriority != oldpriority: + print "I: Will change priority from %s to %s" % (oldpriority,newpriority); + if newsection != oldsection: + print "I: Will change section from %s to %s" % (oldsection,newsection); + + game_over(); + + Logger = logging.Logger(Cnf, "alicia"); + + projectB.query("BEGIN WORK"); + # We're in "do it" mode, we have something to do... do it + if newpriority != oldpriority: + q = projectB.query(""" + UPDATE override + SET priority=%d + WHERE package=%s + AND suite = (SELECT id FROM suite WHERE suite_name=%s)""" % ( + newprioid, + pg._quote(package,"str"), + pg._quote(Options["Suite"],"str") )); + Logger.log(["changed priority",package,oldpriority,newpriority]); + + if newsection != oldsection: + q = projectB.query(""" + UPDATE override + SET section=%d + WHERE package=%s + AND suite = (SELECT id FROM suite WHERE suite_name=%s)""" % ( + newsecid, + pg._quote(package,"str"), + pg._quote(Options["Suite"],"str") )); + Logger.log(["changed priority",package,oldsection,newsection]); + projectB.query("COMMIT WORK"); + + Logger.close(); + + print "Done"; + +################################################################################# + +if __name__ == '__main__': + main() diff --git a/docs/Makefile b/docs/Makefile index c5c7f0e3..feaa9442 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -2,7 +2,7 @@ # TODO: alyson andrea claire fernanda jenna neve rene shania tea ziyi -SGMLMANPAGES = catherine.1.sgml charisma.1.sgml cindy.1.sgml heidi.1.sgml julia.1.sgml kelly.1.sgml lisa.1.sgml madison.1.sgml melanie.1.sgml natalie.1.sgml rhona.1.sgml +SGMLMANPAGES = catherine.1.sgml charisma.1.sgml cindy.1.sgml heidi.1.sgml julia.1.sgml kelly.1.sgml lisa.1.sgml madison.1.sgml melanie.1.sgml natalie.1.sgml rhona.1.sgml alicia.1.sgml MANPAGES = $(patsubst %.sgml, %, $(SGMLMANPAGES)) diff --git a/docs/README.first b/docs/README.first index d77a526c..5a526ac8 100644 --- a/docs/README.first +++ b/docs/README.first @@ -37,11 +37,13 @@ o To clean things up: * rhona - to remove obsolete files from the pool * shania - to remove obsolete/stray files from the queue * melanie - to remove package(s) from suite(s) + * alicia - to change individual override entries o Information display: * madison - shows information about package(s) * helena - shows information about package(s) in queue/ + * alicia - can show you individual override entries Generic and useful, but only for those with existing archives ------------------------------------------------------------- diff --git a/docs/alicia.1.sgml b/docs/alicia.1.sgml new file mode 100644 index 00000000..92111904 --- /dev/null +++ b/docs/alicia.1.sgml @@ -0,0 +1,82 @@ + + +%katieent; + +]> + + + &katie-docinfo; + + + alicia + 1 + + + + + alicia + Make micromodifications or queries to the overrides table + + + + + + alicia + + package + + + + + + Description</> + <para> + <command>alicia</command> makes micromodifications and queries the overrides. + </PARA> + </REFSECT1> + + <RefSect1><Title>Options</> + + <VariableList> + <VarListEntry><term><option>-h/--help</option></> + <ListItem> + <Para>Show help and then exit.</PARA> + </LISTITEM> + </VarListEntry> + <VarListEntry><term><option>-n/--no-action</option></> + <ListItem> + <Para>Show what alicia would do but make no changes</PARA> + </LISTITEM> + </VarListEntry> + <VarListEntry><term><option>-s/--suite=<replaceable>suite</replaceable></option></> + <ListItem> + <Para>Affect the overrides in suite listed. The default is <literal>unstable</literal></PARA> + </LISTITEM> + </VarListEntry> + + </VariableList> + </RefSect1> + + <RefSect1><Title>Common use</> + <para> + <command>alicia</command> when invoked with only a package name will tell you what section and priority the given package has. + </PARA> + <para> + <command>alicia</command> when invoked with a package and one or two other values will set the section and/or priority to the values given. You may use a single period ('.') to represent "do not change" or you can ommit the value you do not want to change. + </PARA> + </RefSect1> + <RefSect1><Title>Notes</> + + <Para>alicia essentially lets you do what natalie does only on the microscopic scale rather than the macroscopic scale of natalie. Use with care.</> + + <RefSect1><Title>Diagnostics</> + <para> + <command>alicia</command> returns zero on normal operation, non-zero on error. + </PARA> + </RefSect1> + + &manauthor; + +</refentry> -- 2.39.5