123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- # Copyright (C) 2012, Ansgar Burchardt <ansgar@debian.org>
- #
- # 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.,
- # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- """module for administrative tasks in a dak install.
- This module provides classes to do administrative tasks in a dak install,
- eg. creating/modifying archives, suites, architectures, etc..
- """
- from daklib import utils
- from daklib.dbconn import *
- ################################################################################
- class ArchiveMaint(object):
- """Handle low-level archive changes
- """
- def __init__(self):
- pass
- def suite_list(self, d, args):
- s = d.session()
- for j in s.query(Suite).join(Suite.archive).order_by(Archive.archive_name, Suite.suite_name).all():
- if len(args) > 2 and args[2] == "--print-archive":
- print "{0} {1}".format(j.archive.archive_name, j.suite_name)
- else:
- print "{0}".format(j.suite_name)
-
- def suite_show(self, d, args):
- if len(args) < 2:
- die("E: showing an suite entry requires a suite")
-
- s = d.session()
- su = get_suite(args[2].lower())
- if su is None:
- die("E: can't find suite entry for %s" % (args[2].lower()))
-
- print su.details()
-
- def suite_add(self, d, args, addallarches=False):
- die_arglen(args, 4, "E: adding a suite requires at least a name and a version")
- suite_name = args[2].lower()
- version = args[3]
- rest = args[3:]
-
- if len(version) == 0:
- version = None
-
- def get_field(field):
- for varval in args:
- if varval.startswith(field + '='):
- return varval.split('=')[1]
- return None
-
- print "Adding suite %s" % suite_name
- if not dryrun:
- try:
- s = d.session()
- suite = Suite()
- suite.suite_name = suite_name
- suite.overridecodename = suite_name
- suite.version = version
- suite.label = get_field('label')
- suite.description = get_field('description')
- suite.origin = get_field('origin')
- suite.codename = get_field('codename')
- signingkey = get_field('signingkey')
- if signingkey is not None:
- suite.signingkeys = [signingkey.upper()]
- archive_name = get_field('archive')
- if archive_name is not None:
- suite.archive = get_archive(archive_name, s)
- else:
- suite.archive = s.query(Archive).filter(~Archive.archive_name.in_(['build-queues', 'new', 'policy'])).one()
- suite.srcformats = s.query(SrcFormat).all()
- s.add(suite)
- s.flush()
- except IntegrityError as e:
- die("E: Integrity error adding suite %s (it probably already exists)" % suite_name)
- except SQLAlchemyError as e:
- die("E: Error adding suite %s (%s)" % (suite_name, e))
- print "Suite %s added" % (suite_name)
-
- if addallarches:
- arches = []
- q = s.query(Architecture).order_by(Architecture.arch_string)
- for arch in q.all():
- suite.architectures.append(arch)
- arches.append(arch.arch_string)
-
- print "Architectures %s added to %s" % (','.join(arches), suite_name)
-
- s.commit()
-
- def suite_rm(self, d, args):
- die_arglen(args, 3, "E: removing a suite requires at least a name")
- name = args[2]
- print "Removing suite {0}".format(name)
- if not dryrun:
- try:
- s = d.session()
- su = get_suite(name.lower())
- if su is None:
- die("E: Cannot find suite {0}".format(name))
- s.delete(su)
- s.commit()
- except IntegrityError as e:
- die("E: Integrity error removing suite {0} (suite-arch entries probably still exist)".format(name))
- except SQLAlchemyError as e:
- die("E: Error removing suite {0} ({1})".format(name, e))
- print "Suite {0} removed".format(name)
-
- def suite_add_build_queue(self, d, args):
- session = d.session()
-
- die_arglen(args, 6, "E: Adding a build queue needs four parameters.")
-
- suite_name = args[2]
- build_queue_name = args[3]
- build_queue_codename = args[4]
- build_queue_archive_name = args[5]
- try:
- suite = session.query(Suite).filter_by(suite_name=suite_name).one()
- except NoResultFound:
- die("E: Unknown suite '{0}'".format(suite_name))
- try:
- build_queue_archive = session.query(Archive).filter_by(archive_name=build_queue_archive_name).one()
- except NoResultFound:
- die("E: Unknown archive '{0}'".format(build_queue_archive_name))
-
- # Create suite
- s = Suite()
- s.suite_name = build_queue_name
- s.origin = suite.origin
- s.label = suite.label
- s.description = "buildd {0} incoming".format(suite_name)
- s.codename = build_queue_codename
- s.notautomatic = suite.notautomatic
- s.overridesuite = suite.overridesuite or suite.suite_name
- s.butautomaticupgrades = suite.butautomaticupgrades
- s.signingkeys = suite.signingkeys
- s.include_long_description = False
-
- s.archive = build_queue_archive
- s.architectures.extend(suite.architectures)
- s.components.extend(suite.components)
- s.srcformats.extend(suite.srcformats)
-
- session.add(s)
- session.flush()
-
- bq = BuildQueue()
- bq.queue_name = build_queue_codename
- bq.suite = s
-
- session.add(bq)
- session.flush()
-
- suite.copy_queues.append(bq)
-
- session.commit()
- def suite_architecture_list(self, d, args):
- s = d.session()
- for j in s.query(Suite).order_by(Suite.suite_name):
- architectures = j.get_architectures(skipsrc = True, skipall = True)
- print j.suite_name + ': ' + \
- ', '.join([a.arch_string for a in architectures])
-
- def suite_architecture_listarch(self, d, args):
- die_arglen(args, 3, "E: suite-architecture list-arch requires a suite")
- suite = get_suite(args[2].lower(), d.session())
- if suite is None:
- die('E: suite %s is invalid' % args[2].lower())
- a = suite.get_architectures(skipsrc = True, skipall = True)
- for j in a:
- print j.arch_string
-
-
- def suite_architecture_listsuite(self, d, args):
- die_arglen(args, 3, "E: suite-architecture list-suite requires an arch")
- architecture = get_architecture(args[2].lower(), d.session())
- if architecture is None:
- die("E: architecture %s is invalid" % args[2].lower())
- for j in architecture.suites:
- print j.suite_name
-
-
- def suite_architecture_add(self, d, args):
- if len(args) < 3:
- die("E: adding a suite-architecture entry requires a suite and arch")
-
- s = d.session()
-
- suite = get_suite(args[2].lower(), s)
- if suite is None: die("E: Can't find suite %s" % args[2].lower())
-
- for arch_name in args[3:]:
- arch = get_architecture(arch_name.lower(), s)
- if arch is None: die("E: Can't find architecture %s" % args[3].lower())
-
- try:
- suite.architectures.append(arch)
- s.flush()
- except IntegrityError as e:
- die("E: Can't add suite-architecture entry (%s, %s) - probably already exists" % (args[2].lower(), arch_name))
- except SQLAlchemyError as e:
- die("E: Can't add suite-architecture entry (%s, %s) - %s" % (args[2].lower(), arch_name, e))
-
- print "Added suite-architecture entry for %s, %s" % (args[2].lower(), arch_name)
-
- if not dryrun:
- s.commit()
-
- s.close()
-
- def suite_architecture_rm(self, d, args):
- if len(args) < 3:
- die("E: removing an suite-architecture entry requires a suite and arch")
-
- s = d.session()
- if not dryrun:
- try:
- suite_name = args[2].lower()
- suite = get_suite(suite_name, s)
- if suite is None:
- die('E: no such suite %s' % suite_name)
- arch_string = args[3].lower()
- architecture = get_architecture(arch_string, s)
- if architecture not in suite.architectures:
- die("E: architecture %s not found in suite %s" % (arch_string, suite_name))
- suite.architectures.remove(architecture)
- s.commit()
- except IntegrityError as e:
- die("E: Can't remove suite-architecture entry (%s, %s) - it's probably referenced" % (args[2].lower(), args[3].lower()))
- except SQLAlchemyError as e:
- die("E: Can't remove suite-architecture entry (%s, %s) - %s" % (args[2].lower(), args[3].lower(), e))
-
- print "Removed suite-architecture entry for %s, %s" % (args[2].lower(), args[3].lower())
- def suite_component_list(self, d, args):
- s = d.session()
- for j in s.query(Suite).order_by(Suite.suite_name):
- components = j.components
- print j.suite_name + ': ' + \
- ', '.join([c.component_name for c in components])
-
-
- def suite_component_listcomponent(self, d, args):
- die_arglen(args, 3, "E: suite-component list-component requires a suite")
- suite = get_suite(args[2].lower(), d.session())
- if suite is None:
- die('E: suite %s is invalid' % args[2].lower())
- for c in suite.components:
- print c.component_name
-
-
- def suite_component_listsuite(self, d, args):
- die_arglen(args, 3, "E: suite-component list-suite requires an component")
- component = get_component(args[2].lower(), d.session())
- if component is None:
- die("E: component %s is invalid" % args[2].lower())
- for s in component.suites:
- print s.suite_name
-
-
- def suite_component_add(self, d, args):
- if len(args) < 3:
- die("E: adding a suite-component entry requires a suite and component")
-
- s = d.session()
-
- suite = get_suite(args[2].lower(), s)
- if suite is None: die("E: Can't find suite %s" % args[2].lower())
-
- for component_name in args[3:]:
- component = get_component(component_name.lower(), s)
- if component is None: die("E: Can't find component %s" % args[3].lower())
-
- try:
- suite.components.append(component)
- s.flush()
- except IntegrityError as e:
- die("E: Can't add suite-component entry (%s, %s) - probably already exists" % (args[2].lower(), component_name))
- except SQLAlchemyError as e:
- die("E: Can't add suite-component entry (%s, %s) - %s" % (args[2].lower(), component_name, e))
-
- print "Added suite-component entry for %s, %s" % (args[2].lower(), component_name)
-
- if not dryrun:
- s.commit()
- s.close()
-
- def suite_component_rm(self, d, args):
- if len(args) < 3:
- die("E: removing an suite-component entry requires a suite and component")
-
- s = d.session()
- if not dryrun:
- try:
- suite_name = args[2].lower()
- suite = get_suite(suite_name, s)
- if suite is None:
- die('E: no such suite %s' % suite_name)
- component_string = args[3].lower()
- component = get_component(arch_string, s)
- if component not in suite.components:
- die("E: component %s not found in suite %s" % (component_string, suite_name))
- suite.components.remove(component)
- s.commit()
- except IntegrityError as e:
- die("E: Can't remove suite-component entry (%s, %s) - it's probably referenced" % (args[2].lower(), args[3].lower()))
- except SQLAlchemyError as e:
- die("E: Can't remove suite-component entry (%s, %s) - %s" % (args[2].lower(), args[3].lower(), e))
-
- print "Removed suite-component entry for %s, %s" % (args[2].lower(), args[3].lower())
|