Logo Search packages:      
Sourcecode: falcon version File versions  Download package

def falcon::config::SystemConfiguration::configure (   self  ) 

Python-newt based interactive config editor

Reimplemented from falcon::config::Configuration.

Definition at line 184 of file config.py.

00184                        :
        """Python-newt based interactive config editor"""
        screen = falcon.screen = snack.SnackScreen()
        screen.drawRootText(1,1, _("Falcon %s interactive configuration editor") % self.falcon_version)
        screen.drawRootText(1,2, "(C)2005-2008 %s" % (self.falcon_author))
        self.force_yes = False
        self.force_no = False

        EXIT, GENERAL, POCKETS, MIRRORS, PLUGINS, BUILDING = range(6)
        mainmenu = falcon.questions.SelectionForm(_("Configuration wizard"), _("Please choose from the menu"), 
                                                  ((_("General configuration"), GENERAL),
                                                   (_("Pockets and components"), POCKETS),
                                                   (_("Mirrors"), MIRRORS),
                                                   (_("Plugins"), PLUGINS),
                                                   (_("Building"), BUILDING)),
                                                   _("Exit configuration"))
        while True:
            ret = mainmenu.run()
            if not ret:
                screen.suspend()
                self.configured = True
                return

            if ret == GENERAL:
                current = dict([(x.key, self[x.key]) for x in self.questions])
                form = falcon.questions.QuestionForm(_("General configuration"), self.questions)
                answers = form.run(current)
                if answers:
                    for k in answers:
                        self[k] = answers[k]
                                
            elif ret == POCKETS:
                pocketmenu = falcon.questions.SelectionForm(_("Pocket configuration"), _("Select a pocket to configure"),
                                                            tuple([(p.name,p) for p in falcon.pockets]),
                                                            _("Back to main menu"))
                while True:
                    pocket = pocketmenu.run()
                    if not pocket:
                        break
                    
                    # Now configure the pocket
                    questions = [
                     falcon.questions.Entry(_("Version number for this pocket"),[falcon.validators.version]),
                     falcon.questions.Text(_("Description of this pocket"),[])
                    ]
                    questions[0].key = 'version'
                    questions[1].key = 'description'

                    current =  {'version': pocket.version, 'description': pocket.description}
                    for c in pocket.realcomponents.all():
                        q = falcon.questions.Text(_("Description for component %s") % c.name)
                        q.key = c.id
                        current[c.id] = c.description
                        questions.append(q)

                    form = falcon.questions.QuestionForm(_("Pocket %s") % pocket.name, questions)
                    answers = form.run(current)

                    if not answers:
                        continue

                    pocket.version = answers['version']
                    pocket.description = answers['description']
                    pocket.save()

                    for c in pocket.realcomponents.all():
                        c.description = answers[c.id]
                        c.save()

                    # Metacomponents
                    while True:
                        questions = []
                        current = {}
                        for c in pocket.metacomponents.all():
                            q1 = falcon.questions.Text(_("Description for metacomponent %s") % c.name, [])
                            q1.key = (c.id,'description')
                            current[(c.id,'description')] = c.description
                            q2 = falcon.questions.SelectMulti(_("Components"), sorted([y.name for y in pocket.realcomponents.all()]), [])
                            q2.key = (c.id, 'components')
                            current[(c.id,'components')] = [x.name for x in c.components.all()]
                            questions += [q1, q2]
                        questions.append(falcon.questions.Entry(_("Add new metacomponent"), [falcon.validators.nospaces]))
                        questions[-1].key = 'newcomponent'
                        current['newcomponent'] = ''

                        metacompform = falcon.questions.QuestionForm(_("Pocket %s, metacomponents") % pocket.name, questions)
                        answers = metacompform.run(current)
                        if not answers:
                            break

                        for c in pocket.metacomponents.all():
                            c.description = answers[(c.id, 'description')]
                            current_components = [x.id for x in c.components.all()]
                            if not len(answers[(c.id, 'components')]):
                                c.delete()
                                continue
                            for _c in answers[(c.id, 'components')]:
                                _c = falcon.pocket.Component.objects.get(name=_c, pocket=pocket)
                                if _c.id not in current_components:
                                    c.components.add(_c)
                                else:
                                    current_components.remove(_c.id)
                            for _c in c.components.all():
                                if c.id in current_components:
                                    c.components.remove(_c)
                            c.save()
                        if answers['newcomponent']:
                            c = falcon.pocket.MetaComponent(pocket=pocket, name=answers['newcomponent'])
                            c.save()
                        else:
                            break

            elif ret == MIRRORS:
                while True:
                    mirrormenu = falcon.questions.SelectionForm(_("Mirror configuration"), _("Select a mirror to configure"),
                                                                tuple([(m.name, m) for m in falcon.mirror.Mirror.objects.all()] +
                                                                      [(_("New mirror"), -1)]),
                                                                _("Back to main menu"))

                    mirror = mirrormenu.run()
                    if not mirror:
                        break
                    if mirror == -1:
                        mirror = falcon.mirror.Mirror()
                        comps = []
                    else:
                        comps = list(mirror.realcomponents.all()) + list(mirror.metacomponents.all())

                    questions = [
                     falcon.questions.Entry(_("Name of this mirror"), [falcon.validators.shellsafe, falcon.validators.nospaces]),
                     falcon.questions.Entry(_("URL of this mirror's root")),
                     falcon.questions.Entry(_("Rsync upload path"), [falcon.validators.shellsafe]),
                     falcon.questions.QuotedEntry(_("Extra rsync arguments")),
                     falcon.questions.Entry(_("Who sponsors this mirror")),
                     falcon.questions.ComponentTree(_("Which components should be mirrored"))
                    ]
                    questions[0].key = 'name'; questions[1].key = 'webbase'; questions[2].key = 'rsync'
                    questions[3].key = 'rsync_opts'; questions[4].key = 'sponsor'; questions[5].key = 'components'
                    current = {
                     'name': mirror.name, 'webbase': mirror.webbase, 'rsync': mirror.rsync,
                     'rsync_opts': mirror.rsync_opts, 'sponsor': mirror.sponsor, 'components': comps
                    }
                    form = falcon.questions.QuestionForm(_("Mirror %s") % mirror.name, questions)
                    answers = form.run(current)
                    if not answers:
                        continue

                    mirror.name = answers['name']
                    mirror.webbase = answers['webbase']
                    mirror.rsync = answers['rsync']
                    mirror.rsync_opts = answers['rsync_opts']
                    mirror.sponsor = answers['sponsor']

                    if not len(mirror.name):
                        if mirror.id:
                            mirror.delete()
                    else:
                        mirror.save()
                        mirror = falcon.mirror.Mirror.objects.get(name=mirror.name)
                        mirror.realcomponents = [x for x in answers['components'] if type(x) == falcon.pocket.Component]
                        mirror.metacomponents = [x for x in answers['components'] if type(x) == falcon.pocket.MetaComponent]
                        mirror.save()

            elif ret == BUILDING:
                while True:
                    buildmenu = falcon.questions.SelectionForm(_("Builder configuration"), _("Select a builder to configure"),
                                                                tuple([(b.name, b) for b in falcon.build.Builder.objects.all()] +
                                                                      [(_("New builder"), -1)]),
                                                                _("Back to main menu"))

                    builder = buildmenu.run()
                    if not builder:
                        break
                    if builder == -1:
                        builder = falcon.build.Builder()

                    all_architectures = ('i386','amd64','powerpc','sparc','arm','ia64','alpha','hppa','m68k','mips','mipsel','s390')
                    questions = [
                     falcon.questions.Entry(_("Name of this buildd"), [falcon.validators.shellsafe, falcon.validators.nospaces]),
                     falcon.questions.Entry(_("Hostname of this buildd")),
                     falcon.questions.Select(_("Architecture"), all_architectures),
                     falcon.questions.Boolean(_("Build Arch: all packages")),
                     falcon.questions.Entry(_("Rsync upload path (with hostname)"), [falcon.validators.shellsafe]),
                     falcon.questions.Entry(_("Rsync download path (with hostname)"), [falcon.validators.shellsafe]),
                     falcon.questions.QuotedEntry(_("Build command")),
                     falcon.questions.Text(_("Comment"))
                    ]
                    questions[0].key = 'name'; questions[1].key = 'hostname'; questions[2].key = 'arch'; questions[3].key = 'arch_all'
                    questions[4].key = 'uploadpath'; questions[5].key = 'downloadpath'; questions[6].key = 'buildcommand'; questions[7].key = 'comment'
                    current = {
                      'name': builder.name, 'hostname': builder.hostname, 'arch': builder.arch, 
                      'arch_all': builder.arch_all, 'uploadpath': builder.uploadpath, 'downloadpath': builder.downloadpath, 
                      'buildcommand': builder.buildcommand, 'comment': builder.comment
                    }

                    form = falcon.questions.QuestionForm(_("Builder %s") % builder.name, questions)
                    answers = form.run(current)
                    if not answers:
                        continue

                    builder.name = answers['name']
                    builder.hostname = answers['hostname']
                    builder.arch = answers['arch']
                    builder.arch_all = answers['arch_all']
                    builder.uploadpath = answers['uploadpath']
                    builder.downloadpath = answers['downloadpath']
                    builder.buildcommand = answers['buildcommand']
                    builder.comment = answers['comment']

                    if not len(builder.name):
                        if builder.id:
                            builder.delete()
                    else:
                        builder.save()

            elif ret == PLUGINS:
                while True:
                    pluginmenu = falcon.questions.SelectionForm(_("Plugin configuration"), _("Select a plugin to configure"),
                                                                tuple([(p.name, p) for p in falcon.plugin.loaded_plugins.values()]),
                                                                _("Back to main menu"))
                    plugin = pluginmenu.run()
                    if not plugin:
                        break
                    plugin.configure()

# Initial config
conf = SystemConfiguration()


Generated by  Doxygen 1.6.0   Back to index