Beispiel #1
0
    def load_ipsets(self):
        '''
    load ipsets into selectedConfigurationCombo
    '''
        self.selectedConfigurationCombo.startMultipleChanges()
        self.selectedConfigurationCombo.deleteAllItems()

        self.selectedConfigurationCombo.setEnabled(True)
        self.selectedConfigurationCombo.setLabel(
            self.configureViews['ipsets']['title'])

        ipsets = []
        if self.runtime_view:
            ipsets = self.fw.getIPSets()
        else:
            ipsets = self.fw.config().getIPSetNames()

        # ipsets
        itemColl = yui.YItemCollection()
        for ipset in ipsets:
            item = yui.YItem(ipset, False)
            itemColl.push_back(item)
            item.this.own(False)

        self.selectedConfigurationCombo.addItems(itemColl)
        self.selectedConfigurationCombo.doneMultipleChanges()
Beispiel #2
0
    def load_zones(self, selected=None):
        '''
    load zones into selectedConfigurationCombo
    '''
        self.selectedConfigurationCombo.startMultipleChanges()
        self.selectedConfigurationCombo.deleteAllItems()

        self.selectedConfigurationCombo.setEnabled(True)
        self.selectedConfigurationCombo.setLabel(
            self.configureViews['zones']['title'])

        zones = []
        if self.runtime_view:
            zones = self.fw.getZones()
        else:
            zones = self.fw.config().getZoneNames()

        selected_zone = selected
        if selected not in zones:
            selected_zone = self.fw.getDefaultZone()

        # zones
        itemColl = yui.YItemCollection()
        for zone in zones:
            item = yui.YItem(zone, False)
            if zone == selected_zone:
                item.setSelected(True)
            itemColl.push_back(item)
            item.this.own(False)

        self.selectedConfigurationCombo.addItems(itemColl)
        self.selectedConfigurationCombo.doneMultipleChanges()
Beispiel #3
0
    def load_services(self, service_name=None):
        '''
    load services into selectedConfigurationCombo
    '''
        self.selectedConfigurationCombo.startMultipleChanges()
        self.selectedConfigurationCombo.deleteAllItems()

        self.selectedConfigurationCombo.setEnabled(True)
        self.selectedConfigurationCombo.setLabel(
            self.configureViews['services']['title'])

        services = []
        if self.runtime_view:
            services = self.fw.listServices()
        else:
            services = self.fw.config().getServiceNames()

        # services
        itemColl = yui.YItemCollection()
        for service in services:
            item = yui.YItem(service, False)
            if service == service_name:
                item.setSelected(True)
            itemColl.push_back(item)
            item.this.own(False)

        self.selectedConfigurationCombo.addItems(itemColl)
        self.selectedConfigurationCombo.doneMultipleChanges()
Beispiel #4
0
    def _populateTree(self, data):
        '''
        Populate history date tree
        @param data list of date and tid
        '''
        self._tid = {}

        main = {}
        for tid, dt in data:
            # example of dt : 2017-11-01T13:37:50
            date = datetime.datetime.strptime(dt, "%Y-%m-%dT%H:%M:%S")

            # year
            if date.year not in main.keys():
                main[date.year] = {}
                item = yui.YTreeItem(date.strftime("%Y"), True)
                item.this.own(False)
                main[date.year]['item'] = item

            mdict = main[date.year]
            # month
            if date.month not in mdict.keys():
                mdict[date.month] = {}
                item = yui.YTreeItem(main[date.year]['item'],
                                     date.strftime("%m"), True)
                item.this.own(False)
                mdict[date.month]['item'] = item

            ddict = mdict[date.month]
            # day
            if date.day not in ddict.keys():
                ddict[date.day] = {}
                item = yui.YTreeItem(mdict[date.month]['item'],
                                     date.strftime("%d"), True)
                item.this.own(False)
                ddict[date.day]['item'] = item
            ddict[date.day][date.strftime("%H:%M:%S")] = tid
            item = yui.YTreeItem(ddict[date.day]['item'],
                                 date.strftime("%H:%M:%S"), False)
            item.this.own(False)
            self._tid[tid] = item

        itemVect = []
        for year in main.keys():
            itemVect.append(main[year]['item'])

        self._dlg.pollEvent()

        yui.YUI.app().busyCursor()
        itemCollection = yui.YItemCollection(itemVect)
        self._historyTree.startMultipleChanges()
        self._historyTree.deleteAllItems()
        self._historyTree.addItems(itemCollection)
        self._historyTree.doneMultipleChanges()
        yui.YUI.app().normalCursor()
Beispiel #5
0
 def _serviceConfigurationViewCollection(self):
     '''
 returns an YItemCollection containing Service configuration views
 '''
     ordered_Views = [
         'ports', 'protocols', 'source_ports', 'modules', 'destinations'
     ]
     itemColl = yui.YItemCollection()
     for v in ordered_Views:
         item = yui.YItem(self.serviceConfigurationView[v]['title'], False)
         show_item = 'ports'
         if show_item == v:
             item.setSelected(True)
         # adding item to views to find the item selected
         self.serviceConfigurationView[v]['item'] = item
         itemColl.push_back(item)
         item.this.own(False)
     return itemColl
Beispiel #6
0
    def _ipsecConfigurationViewCollection(self):
        '''
    returns an YItemCollection containing IPSEC configuration views
    '''
        ordered_Views = [
            'entries',
        ]
        itemColl = yui.YItemCollection()
        for v in ordered_Views:
            item = yui.YItem(self.ipsecConfigurationView[v]['title'], False)
            show_item = 'entries'
            if show_item == v:
                item.setSelected(True)
            # adding item to views to find the item selected
            self.ipsecConfigurationView[v]['item'] = item
            itemColl.push_back(item)
            item.this.own(False)

        return itemColl
Beispiel #7
0
    def _zoneConfigurationViewCollection(self):
        '''
    returns an YItemCollection containing Zone configuration views
    '''
        ordered_configureViews = [
            'services', 'ports', 'protocols', 'source_ports', 'masquerading',
            'port_forwarding', 'icmp_filter', 'rich_rules', 'interfaces',
            'sources'
        ]
        itemColl = yui.YItemCollection()
        for v in ordered_configureViews:
            item = yui.YItem(self.zoneConfigurationView[v]['title'], False)
            show_item = 'services'
            if show_item == v:
                item.setSelected(True)
            # adding item to views to find the item selected
            self.zoneConfigurationView[v]['item'] = item
            itemColl.push_back(item)
            item.this.own(False)

        return itemColl
Beispiel #8
0
    def _fillRPServices(self):
        services = None
        if self.runtime_view:
            services = self.fw.listServices()
        else:
            services = self.fw.config().getServiceNames()

        v = []
        for service in services:
            item = yui.YCBTableItem(service)
            item.check(False)
            item.this.own(False)
            v.append(item)

        #NOTE workaround to get YItemCollection working in python
        itemCollection = yui.YItemCollection(v)
        self.serviceList.startMultipleChanges()
        # cleanup old changed items since we are removing all of them
        self.serviceList.setChangedItem(None)
        self.serviceList.addItems(itemCollection)
        self.serviceList.doneMultipleChanges()
Beispiel #9
0
  def UIlayout(self, layout):
    '''
    layout to setup UI for Manalog
    '''
    optFactory = yui.YUI.optionalWidgetFactory()
    dialog = self.factory.createVBox(layout)

    lbl1 = self.factory.createLabel(  (dialog), _("A tool to monitor your logs"),True,False)
    cols = self.factory.createHBox(layout)
    col1 = self.factory.createVBox(cols)
    frame = self.factory.createFrame(col1, _("Options"))
    vbox = self.factory.createVBox(col1)
    #### Last Boot
    self.lastBoot = self.factory.createCheckBox(self.factory.createLeft(vbox),_("Last boot"),True)
    self.lastBoot.setNotify(True)
    self.eventManager.addWidgetEvent(self.lastBoot, self.onLastBootEvent)
    #### Tailing mode
    self.tailing = self.factory.createCheckBox(self.factory.createLeft(vbox),_("Tail mode"),False)
    self.tailing.setNotify(True)
    self.eventManager.addWidgetEvent(self.tailing, self.onTailingEvent)
    #### Monotonic display for timestamp
    self.monotonbt = self.factory.createCheckBox(self.factory.createLeft(vbox),_("Monotonic timestamp"),True)

    self.factory.createVSpacing(vbox,0.5)
    row1 = self.factory.createHBox(vbox)
    self.factory.createVSpacing(vbox, 0.5)
    row2 = self.factory.createHBox(vbox)
    self.factory.createVSpacing(vbox, 0.5)
    row3 = self.factory.createHBox(vbox)
    self.factory.createVSpacing(vbox, 0.5)
    row4 = self.factory.createHBox(vbox)
    self.factory.createVSpacing(vbox, 0.5)
    row5 = self.factory.createHBox(vbox)
    self.factory.createVSpacing(vbox, 0.5)
    row6 = self.factory.createHBox(vbox)
    self.factory.createVSpacing(vbox, 0.5)
    row7 = self.factory.createHBox(vbox)
    self.factory.createVSpacing(vbox, 0.5)
    row8 = self.factory.createHBox(vbox)
    self.factory.createVSpacing(vbox, 0.5)
    row9 = self.factory.createHBox(vbox)
    
    #### since and until
    self.sinceFrame = self.factory.createCheckBoxFrame(row1, _("Since"), True)
    self.sinceFrame.setWeight(yui.YD_HORIZ, 1)
    self.sinceFrame.setNotify(True)
    self.eventManager.addWidgetEvent(self.sinceFrame, self.onSinceFrameEvent)
    self.untilFrame = self.factory.createCheckBoxFrame(row2, _("Until"), True)
    self.untilFrame.setWeight(yui.YD_HORIZ, 1)
    self.untilFrame.setNotify(True)
    self.eventManager.addWidgetEvent(self.untilFrame, self.onUntilFrameEvent)
    if (optFactory.hasDateField()):
        hbox1 = self.factory.createHBox(self.sinceFrame)
        self.sinceDate = self.optFactory.createDateField(hbox1, "")
        self.factory.createHSpacing(hbox1, 1.0)
        self.sinceTime = optFactory.createTimeField(hbox1, "");
        sday = date.today().isoformat()
        self.sinceDate.setValue(sday)
        self.sinceTime.setValue("00:00:00")

        hbox1 =  self.factory.createHBox(self.untilFrame)
        self.untilDate = optFactory.createDateField(hbox1, "")
        self.factory.createHSpacing(hbox1, 1.0)
        self.untilTime = optFactory.createTimeField(hbox1, "")
        self.untilDate.setValue(sday)
        self.untilTime.setValue("23:59:59")
    else :
        self.sinceFrame.enable(False)
        self.untilFrame.enable(False)

    #### units
    spacing = self.factory.createHSpacing(row1, 2.0)
    self.unitsFrame = self.factory.createCheckBoxFrame(row3,_("Select a unit"), True)
    self.unitsFrame.setNotify(True)
    self.units = self.factory.createComboBox( self.factory.createLeft(self.unitsFrame), "" )
    
    yui.YUI.app().busyCursor()
    myserv = mnservices.Services()
    list_services = myserv.service_info
    list_units = []
    for unit in list_services.keys() :
        list_units.append(unit)
    list_units.sort()
    dlist = []
    for unit in list_units :
        item = yui.YItem(unit)
        item.this.own(False)
        dlist.append(item)
    itemCollection = yui.YItemCollection(dlist)
    self.units.addItems(itemCollection)
    #### boots
    dlist = []
    self.bootModel = {}
    for boot in self.listBoots() :
        key = boot[0]+' '+boot[2]
        item = yui.YItem(key)
        self.bootModel[key] = boot[1]    #  boot_id
        item.this.own(False)
        dlist.append(item)
    self.bootsFrame = self.factory.createCheckBoxFrame(row4,_("Select a boot"), True)
    self.bootsFrame.setNotify(True)
    if dlist == [] :
        self.eventManager.addWidgetEvent(self.bootsFrame, self.onBootFrameErrorEvent)
    else :
      self.eventManager.addWidgetEvent(self.bootsFrame, self.onBootFrameEvent)      
    self.boots = self.factory.createComboBox( self.factory.createLeft(self.bootsFrame), "" )
    itemCollection = yui.YItemCollection(dlist)
    self.boots.addItems(itemCollection)
    
    #### priority
    # From
    self.factory.createHSpacing(row2, 2.0)
    self.priorityFromFrame = self.factory.createCheckBoxFrame(row5, _("Priority level"), True)
    self.priorityFromFrame.setNotify(True)
    self.priorityFromFrame.setWeight(yui.YD_HORIZ, 1)
    self.priorityFrom = self.factory.createComboBox( self.priorityFromFrame, "" )

    self.pr = ('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug')
    dlist = []
    for prio in self.pr:
        item = yui.YItem(prio)
        if ( prio == 'debug' ):
            item.setSelected(True)
        item.this.own(False)
        dlist.append(item)
    itemCollection = yui.YItemCollection(dlist)
    self.priorityFrom.addItems(itemCollection)

    #### matching
    self.matchingInputField = self.factory.createInputField(row6, _("Matching"))
    self.factory.createSpacing(row3,1)
    #### not matching
    self.notMatchingInputField =self.factory.createInputField(row7, _("but not matching"))
    self.matchingInputField.setWeight(yui.YD_HORIZ, 1)
    self.notMatchingInputField.setWeight(yui.YD_HORIZ, 1)

    #### search
    self.stopButton = self.factory.createPushButton(self.factory.createRight(row8), _("&Stop"))
    self.eventManager.addWidgetEvent(self.stopButton, self.onStopButton)
    self.stopButton.setDisabled()
    self.findButton = self.factory.createPushButton(self.factory.createRight(row8), _("&Find"))
    self.eventManager.addWidgetEvent(self.findButton, self.onFindButton)
    
    #### create log view object
    self.logView = self.factory.createLogView(cols, _("Log content"), 10, 0)
    self.logView.setWeight(yui.YD_HORIZ, 4)

    self.unitsFrame.setValue(False)
    self.sinceFrame.setValue(False)
    self.untilFrame.setValue(False)
    self.priorityFromFrame.setValue(False)
    self.bootsFrame.setValue(False)

    # buttons on the last line
    align = self.factory.createRight(layout)
    hbox = self.factory.createHBox(align)
    aboutButton = self.factory.createPushButton(hbox, _("&About") )
    self.eventManager.addWidgetEvent(aboutButton, self.onAbout)
    align = self.factory.createRight(hbox)
    hbox     = self.factory.createHBox(align)
    saveButton = self.factory.createPushButton(hbox, _("&Save"))
    self.eventManager.addWidgetEvent(saveButton, self._save)
    quitButton = self.factory.createPushButton(hbox, _("&Quit"))
    self.eventManager.addWidgetEvent(quitButton, self.onQuit)

    # Let's test a cancel event
    self.eventManager.addCancelEvent(self.onCancelEvent)
Beispiel #10
0
dialog = factory.createMainDialog()

VBox = factory.createVBox(dialog)

yTableHeader = yui.YTableHeader()
yTableHeader.addColumn("package")
yTableHeader.addColumn("version")
yTableHeader.addColumn("release")
yTableHeader.addColumn("arch")

myTableMinSize = factory.createMinSize(VBox, 50, 12)
myTable = factory.createTable(myTableMinSize, yTableHeader)

myOK = factory.createPushButton(VBox, "OK")

# NOTE YItemCollection have problems
# because YItem is not disown() so it must
# be done explicitally by using this.own property
ic = yui.YItemCollection()
for pkg in range(1, 10):
    name = "name-{0}".format(pkg)
    item = yui.YTableItem(name, "1.0", "1", "i585")
    item.this.own(False)  # comment this to have a crash
    ic.push_back(item)

myTable.addItems(ic)

event1 = dialog.waitForEvent()

dialog.destroy()
  def UIlayout(self, layout):
    '''
    layout implementation called in base class to setup UI
    '''
    align = self.factory.createLeft(layout)
    self.name        = self.factory.createInputField(align, _("Name"))
    align = self.factory.createLeft(layout)
    self.version     = self.factory.createInputField(align, _("Version"))
    align = self.factory.createLeft(layout)
    self.short       = self.factory.createInputField(align, _("Short"))
    align = self.factory.createLeft(layout)
    self.description = self.factory.createMultiLineEdit(align, _("Description"))
    self.description.setDefaultVisibleLines(5)
    if 'max_zone_name_len' in self._zoneBaseInfo.keys():
      self.name.setInputMaxLength(self._zoneBaseInfo['max_zone_name_len'])
    if 'name' in self._zoneBaseInfo.keys():
      self.name.setValue(self._zoneBaseInfo['name'])
    if 'version' in self._zoneBaseInfo.keys():
      self.version.setValue(self._zoneBaseInfo['version'])
    if 'short' in self._zoneBaseInfo.keys():
      self.short.setValue(self._zoneBaseInfo['short'])
    if 'description' in self._zoneBaseInfo.keys():
      self.description.setValue(self._zoneBaseInfo['description'])

    hbox = self.factory.createHBox(layout)
    align = self.factory.createLeft(hbox)
    self.defaultTarget = self.factory.createCheckBox( align, _("Default Target"), False)
    self.eventManager.addWidgetEvent(self.defaultTarget, self.onDefaultTargetEvent)

    self.targets = {
            'ACCEPT' : {'title' : _("Accept")},
            'DROP'   : {'title' : _("Drop")},
            'REJECT' : {'title' : _("Reject")},
        }
    ordered_targets = [ 'ACCEPT', 'DROP', 'REJECT' ]

    defaultTgt = "default"
    if 'target' in self._zoneBaseInfo.keys():
      defaultTgt = self._zoneBaseInfo['target'] if self._zoneBaseInfo['target'] != "%%REJECT%%" else "REJECT"

    self.currentTargetCombobox = self.factory.createComboBox(hbox,"")
    itemColl = yui.YItemCollection()
    for v in ordered_targets:
      item = yui.YItem(self.targets[v]['title'], False)
      show_item = 'ACCEPT' if defaultTgt == "default" else defaultTgt
      if show_item == v :
          item.setSelected(True)
      # adding item to targets to find the item selected
      self.targets[v]['item'] = item
      itemColl.push_back(item)
      item.this.own(False)
    self.currentTargetCombobox.addItems(itemColl)
    self.defaultTarget.setValue(defaultTgt == "default")
    self.currentTargetCombobox.setEnabled(defaultTgt != "default")
    self.defaultTarget.setNotify(True)

    #### buttons on the last line
    align = self.factory.createRight(layout)
    bottomLine = self.factory.createHBox(align)

    cancelButton = self.factory.createPushButton(bottomLine, "&Cancel")
    self.eventManager.addWidgetEvent(cancelButton, self.onCancelButtonEvent)

    okButton = self.factory.createPushButton(bottomLine, "&Ok")
    self.eventManager.addWidgetEvent(okButton, self.onOkEvent)
    
    # Let's test a cancel event
    self.eventManager.addCancelEvent(self.onCancelEvent)

    if 'builtin' in self._zoneBaseInfo.keys() and 'default' in self._zoneBaseInfo.keys():
      # Let's disable name changes for builtin zones
      enabled = not self._zoneBaseInfo['builtin'] and self._zoneBaseInfo['default']
      self.name.setEnabled(enabled)
Beispiel #12
0
    def _handleEvents(self):
        '''
        manages dialog events and returns if sack should be filled again for new enabled/disabled repositories
        '''
        while True:
            event = self.dialog.waitForEvent()

            eventType = event.eventType()

            rebuild_package_list = False
            group = None
            #event type checking
            if (eventType == yui.YEvent.CancelEvent):
                break
            elif (eventType == yui.YEvent.WidgetEvent):
                # widget selected
                widget = event.widget()
                if (widget == self.quitButton):
                    #### QUIT
                    break
                elif (widget == self.applyButton):
                    enabled_repos = []
                    for k in self.itemList.keys():
                        if self.itemList[k]['enabled']:
                            enabled_repos.append(k)
                    logger.info("Enabling repos %s " % " ".join(enabled_repos))
                    self.backend.SetEnabledRepos(enabled_repos)
                    return True
                elif (widget == self.repoList):
                    wEvent = yui.toYWidgetEvent(event)
                    if (wEvent.reason() == yui.YEvent.ValueChanged):
                        changedItem = self.repoList.changedItem()
                        if changedItem:
                            for it in self.itemList:
                                if (self.itemList[it]['item'] == changedItem):
                                    self.itemList[it][
                                        'enabled'] = changedItem.checked()
                    repo_id = self._selectedRepository()
                    s = "TODO show repo %s information<br> See https://github.com/timlau/dnf-daemon/issues/11" % (
                        repo_id if repo_id else "---")
                    # TODO decide what and how to show when the crash https://github.com/timlau/dnf-daemon/issues/11 is fixed
                    v = []
                    try:
                        ri = self.backend.GetRepo(repo_id)
                        logger.debug(ri)
                        for k in sorted(ri.keys()):
                            if k == "enabled":
                                # NOTE: skipping 'enabled' since it is fake and it is better shown as checkbox
                                continue
                            key = None
                            if ri[k]:
                                key = self.infoKeys[
                                    k] if k in self.infoKeys.keys() else k
                                if k == 'size':
                                    value = misc.format_number(ri[k])
                                elif k == 'metadata_expire':
                                    if ri[k] <= -1:
                                        value = _('Never')
                                    else:
                                        value = _("%s second(s)" % (ri[k]))
                                else:
                                    value = "%s" % (ri[k])
                            else:
                                if k == 'metadata_expire':
                                    key = self.infoKeys[k]
                                    value = _('Now')
                            if key:
                                item = yui.YTableItem(key, value)
                                item.this.own(False)
                                v.append(item)

                    except NameError as e:
                        logger.error("dnfdaemon NameError: %s ", e)
                    except AttributeError as e:
                        logger.error("dnfdaemon AttributeError: %s ", e)
                    except:
                        logger.error("Unexpected error: %s ",
                                     sys.exc_info()[0])

                    #NOTE workaround to get YItemCollection working in python
                    itemCollection = yui.YItemCollection(v)

                    self.info.startMultipleChanges()
                    # cleanup old changed items since we are removing all of them
                    self.info.deleteAllItems()
                    self.info.addItems(itemCollection)
                    self.info.doneMultipleChanges()

        return False
Beispiel #13
0
    def _setupUI(self):
        '''
        setup the dialog layout
        '''
        self.appTitle = yui.YUI.app().applicationTitle()
        ## set new title to get it in dialog
        yui.YUI.app().setApplicationTitle(_("Repository Management"))

        self.dialog = self.factory.createPopupDialog()

        minSize = self.factory.createMinSize(self.dialog, 80, 26)

        vbox = self.factory.createVBox(minSize)

        #Line for logo and title
        hbox_iconbar = self.factory.createHBox(vbox)
        head_align_left = self.factory.createLeft(hbox_iconbar)
        hbox_iconbar = self.factory.createHBox(head_align_left)
        #TODO fix icon with one that recall repository management
        self.factory.createImage(hbox_iconbar, self.parent.icon)

        self.factory.createHeading(hbox_iconbar, _("Repository Management"))

        hbox_middle = self.factory.createHBox(vbox)
        hbox_bottom = self.factory.createHBox(vbox)
        hbox_footbar = self.factory.createHBox(vbox)

        hbox_middle.setWeight(1, 50)
        hbox_bottom.setWeight(1, 30)
        hbox_footbar.setWeight(1, 10)

        repoList_header = yui.YTableHeader()
        columns = [_('Name'), _("Enabled")]

        for col in (columns):
            repoList_header.addColumn(col)

        self.repoList = self.mgaFactory.createCBTable(
            hbox_middle, repoList_header, yui.YCBTableCheckBoxOnLastColumn)
        self.repoList.setImmediateMode(True)

        info_header = yui.YTableHeader()
        columns = [_('Information'), _('Value')]
        for col in (columns):
            info_header.addColumn(col)
        self.info = self.factory.createTable(hbox_bottom, info_header)

        #self.info = self.factory.createRichText(hbox_bottom,"")
        #self.info.setWeight(0,40)
        #self.info.setWeight(1,40)

        self.applyButton = self.factory.createIconButton(
            hbox_footbar, "", _("&Apply"))
        self.applyButton.setWeight(0, 3)

        self.quitButton = self.factory.createIconButton(
            hbox_footbar, "", _("&Cancel"))
        self.quitButton.setWeight(0, 3)
        self.dialog.setDefaultButton(self.quitButton)

        self.itemList = {}
        # TODO fix the workaround when GetRepo(id) works again
        repos = self.backend.get_repo_ids("*")
        for r in repos:
            item = yui.YCBTableItem(r)
            # TODO name from repo info
            self.itemList[r] = {'item': item, 'name': r, 'enabled': False}
            item.this.own(False)
        enabled_repos = self.backend.get_repo_ids("enabled")
        for r in enabled_repos:
            if r in self.itemList.keys():
                self.itemList[r]["enabled"] = True
                self.itemList[r]["item"].check(True)

        keylist = sorted(self.itemList.keys())
        v = []
        for key in keylist:
            item = self.itemList[key]['item']
            v.append(item)

        #NOTE workaround to get YItemCollection working in python
        itemCollection = yui.YItemCollection(v)

        self.repoList.startMultipleChanges()
        # cleanup old changed items since we are removing all of them
        self.repoList.deleteAllItems()
        self.repoList.addItems(itemCollection)
        self.repoList.doneMultipleChanges()
Beispiel #14
0
    def _populateHistory(self, selected=None):
        '''
        Populate history packages
        @param selected: selected date from tree
        '''
        itemVect = []
        if selected:
            pkgs = []
            tid = self._getTID(selected)
            if tid:
                pkgs = self.parent.backend.GetHistoryPackages(tid)

            # Order by package name.arch
            names = {}
            names_pair = {}
            for elem in pkgs:
                pkg_id, state, is_inst = elem
                (n, e, v, r, a, repo_id) = misc.to_pkg_tuple(pkg_id)
                na = "%s.%s" % (n, a)
                if state in const.HISTORY_UPDATE_STATES:  # part of a pair
                    if na in names_pair:
                        # this is the updating pkg
                        if state in const.HISTORY_NEW_STATES:
                            names_pair[na].insert(0, elem)  # add first in list
                        else:
                            names_pair[na].append(elem)
                    else:
                        names_pair[na] = [elem]
                else:
                    names[na] = [elem]

            # order by primary state
            states = {}
            # pkgs without relatives
            for na in sorted(list(names)):
                pkg_list = names[na]
                pkg_id, state, is_inst = pkg_list[
                    0]  # Get first element (the primary (new) one )
                if state in states:
                    states[state].append(pkg_list)
                else:
                    states[state] = [pkg_list]
            # pkgs with releatives
            for na in sorted(list(names_pair)):
                pkg_list = names_pair[na]
                pkg_id, state, is_inst = pkg_list[
                    0]  # Get first element (the primary (new) one )
                if state in states:
                    states[state].append(pkg_list)
                else:
                    states[state] = [pkg_list]

            # filling tree view items
            for state in const.HISTORY_SORT_ORDER:
                if state in states:
                    num = len(states[state])
                    cat = yui.YTreeItem(
                        "%s (%i)" % (const.HISTORY_STATE_LABLES[state], num),
                        True)
                    cat.this.own(False)

                    for pkg_list in states[state]:
                        pkg_id, st, is_inst = pkg_list[0]
                        name = misc.pkg_id_to_full_name(pkg_id)
                        pkg_cat = yui.YTreeItem(cat, name, True)
                        pkg_cat.this.own(False)

                        if len(pkg_list) == 2:
                            pkg_id, st, is_inst = pkg_list[1]
                            name = misc.pkg_id_to_full_name(pkg_id)
                            item = yui.YTreeItem(pkg_cat, name, True)
                            item.this.own(False)

                    itemVect.append(cat)

        itemCollection = None
        yui.YUI.app().busyCursor()
        if selected:
            itemCollection = yui.YItemCollection(itemVect)
        self._historyView.startMultipleChanges()
        self._historyView.deleteAllItems()
        if selected:
            self._historyView.addItems(itemCollection)
        self._historyView.doneMultipleChanges()
        yui.YUI.app().normalCursor()
Beispiel #15
0
    def run(self, pkglist):
        '''
        Populate the TreeView with data and rund the dialog
        @param pkglist: list containing view data
        '''

        ## push application title
        appTitle = yui.YUI.app().applicationTitle()
        ## set new title to get it in dialog
        yui.YUI.app().setApplicationTitle(_("Transaction result"))
        minWidth = 80
        minHeight = 25
        dlg = self.factory.createPopupDialog(yui.YDialogNormalColor)
        minSize = self.factory.createMinSize(dlg, minWidth, minHeight)
        layout = self.factory.createVBox(minSize)
        treeWidget = self.factory.createTree(layout,
                                             _("Transaction dependency"))
        sizeLabel = self.factory.createLabel(layout, "")

        align = self.factory.createRight(layout)
        hbox = self.factory.createHBox(align)
        okButton = self.factory.createPushButton(hbox, _("&Ok"))
        cancelButton = self.factory.createPushButton(hbox, _("&Cancel"))

        itemVect = []
        total_size = 0
        for sub, lvl1 in pkglist:
            label = const.TRANSACTION_RESULT_TYPES[sub]
            level1Item = yui.YTreeItem(label, True)
            level1Item.this.own(False)

            for pkgid, size, replaces in lvl1:
                label = misc.pkg_id_to_full_name(
                    pkgid) + " (" + misc.format_number(size) + ")"
                level2Item = yui.YTreeItem(level1Item, label, True)
                level2Item.this.own(False)

                # packages that need to be downloaded
                if sub in [
                        'install', 'update', 'install-deps', 'update-deps',
                        'obsoletes'
                ]:
                    total_size += size
                for r in replaces:
                    label = _("replacing ") + misc.pkg_id_to_full_name(
                        r) + " (" + misc.format_number(size) + ")"
                    item = yui.YTreeItem(level2Item, label, False)
                    item.this.own(False)

            itemVect.append(level1Item)

        sizeLabel.setText(_("Total size ") + misc.format_number(total_size))
        dlg.pollEvent()

        yui.YUI.app().busyCursor()
        itemCollection = yui.YItemCollection(itemVect)
        treeWidget.startMultipleChanges()
        treeWidget.deleteAllItems()
        treeWidget.addItems(itemCollection)
        treeWidget.doneMultipleChanges()
        yui.YUI.app().normalCursor()

        dlg.setDefaultButton(okButton)

        accepting = False
        while (True):
            event = dlg.waitForEvent()
            eventType = event.eventType()
            #event type checking
            if (eventType == yui.YEvent.CancelEvent):
                break
            elif (eventType == yui.YEvent.WidgetEvent):
                # widget selected
                widget = event.widget()

                if (widget == cancelButton):
                    break
                elif (widget == okButton):
                    accepting = True
                    break

        dlg.destroy()

        #restore old application title
        yui.YUI.app().setApplicationTitle(appTitle)

        return accepting
Beispiel #16
0
    def UIlayout(self, layout):
        '''
    layout implementation called in base class to setup UI
    '''

        # Let's test a Menu widget
        self.file_menu = self.factory.createMenuButton(
            self.factory.createLeft(layout), _("&File"))
        qm = yui.YMenuItem(_("&Quit"))
        self.file_menu.addItem(qm)
        self.file_menu.rebuildMenuTree()
        sendObjOnEvent = True
        self.eventManager.addMenuEvent(qm, self.onQuitEvent, sendObjOnEvent)

        # _______
        #|   |   |
        #
        cols = self.factory.createHBox(layout)
        col1 = self.factory.createVBox(cols)
        col2 = self.factory.createVBox(cols)

        # Column 1
        self.activeBindingsTree = self.factory.createTree(
            col1, _("Active bindings"))
        col1.setWeight(yui.YD_HORIZ, 30)
        changeBindingsButton = self.factory.createPushButton(
            col1, _("&Change binding"))
        self.eventManager.addWidgetEvent(changeBindingsButton,
                                         self.onChangeBinding, sendObjOnEvent)
        #### editFrameBox contains button to modify zones (add, remove, edit, load defaults)
        self.editFrameBox = self.factory.createFrame(col1, _("Edit zones"))
        hbox = self.factory.createHBox(self.editFrameBox)
        vbox1 = self.factory.createVBox(hbox)
        vbox2 = self.factory.createVBox(hbox)
        editFrameAddButton = self.factory.createPushButton(vbox1, _("&Add"))
        self.eventManager.addWidgetEvent(editFrameAddButton,
                                         self.onEditFrameAddButtonEvent)
        editFrameEditButton = self.factory.createPushButton(vbox1, _("&Edit"))
        self.eventManager.addWidgetEvent(editFrameEditButton,
                                         self.onEditFrameEditButtonEvent)
        editFrameRemoveButton = self.factory.createPushButton(
            vbox2, _("&Remove"))
        self.eventManager.addWidgetEvent(editFrameRemoveButton,
                                         self.onEditFrameRemoveButtonEvent)
        editFrameLoadDefaultsButton = self.factory.createPushButton(
            vbox2, _("&Load default"))
        self.eventManager.addWidgetEvent(
            editFrameLoadDefaultsButton,
            self.onEditFrameLoadDefaultsButtonEvent)
        self.editFrameBox.setEnabled(False)

        # Column 2
        align = self.factory.createTop(col2)  #self.factory.createLeft(col2)
        align = self.factory.createLeft(align)
        hbox = self.factory.createHBox(align)
        col2.setWeight(yui.YD_HORIZ, 80)

        #label = self.factory.createLabel(hbox, _("Configuration:"),False,False)
        self.views = {
            'runtime': {
                'title': _("Runtime")
            },
            'permanent': {
                'title': _("Permanent")
            },
        }
        ordered_views = ['runtime', 'permanent']

        self.currentViewCombobox = self.factory.createComboBox(
            hbox, _("Configuration"))
        itemColl = yui.YItemCollection()

        for v in ordered_views:
            item = yui.YItem(self.views[v]['title'], False)
            show_item = 'runtime'
            if show_item == v:
                item.setSelected(True)
            # adding item to views to find the item selected
            self.views[v]['item'] = item
            itemColl.push_back(item)
            item.this.own(False)

        self.currentViewCombobox.addItems(itemColl)
        self.currentViewCombobox.setNotify(True)
        self.eventManager.addWidgetEvent(self.currentViewCombobox,
                                         self.onChangeView)

        # mainNotebook (configure combo box)
        # TODO icmp_types, helpers, direct_configurations, lockdown_whitelist
        self.configureViews = {
            'zones': {
                'title': _("Zones")
            },
            'services': {
                'title': _("Services")
            },
            'ipsets': {
                'title': _("IP Sets")
            },
        }
        ordered_configureViews = ['zones', 'services', 'ipsets']
        self.configureViewCombobox = self.factory.createComboBox(
            hbox, _("View"))
        itemColl = yui.YItemCollection()

        for v in ordered_configureViews:
            item = yui.YItem(self.configureViews[v]['title'], False)
            show_item = 'zones'
            if show_item == v:
                item.setSelected(True)
            # adding item to views to find the item selected
            self.configureViews[v]['item'] = item
            itemColl.push_back(item)
            item.this.own(False)

        self.configureViewCombobox.addItems(itemColl)
        self.configureViewCombobox.setNotify(True)
        self.eventManager.addWidgetEvent(self.configureViewCombobox,
                                         self.onConfigurationViewChanged)

        # selectedConfigurationCombo is filled if requested by selected configuration view (which zones, services ...)
        self.selectedConfigurationCombo = self.factory.createComboBox(
            hbox, "     ")
        # adding a dummy item to enlarge combobox
        item = yui.YItem("--------------------", False)
        item.this.own(False)
        self.selectedConfigurationCombo.addItem(item)
        self.selectedConfigurationCombo.setEnabled(False)
        self.selectedConfigurationCombo.setNotify(True)
        self.eventManager.addWidgetEvent(
            self.selectedConfigurationCombo,
            self.onSelectedConfigurationComboChanged)

        ###
        # ZoneNotebook and other (combo box to configure selected thing)
        self.zoneConfigurationView = {
            'services': {
                'title': _("Services")
            },
            'ports': {
                'title': _("Ports")
            },
            'protocols': {
                'title': _("Protocols")
            },
            'source_ports': {
                'title': _("Source Ports")
            },
            'masquerading': {
                'title': _("Masquerading")
            },
            'port_forwarding': {
                'title': _("Port Forwarding")
            },
            'icmp_filter': {
                'title': _("ICMP Filter")
            },
            'rich_rules': {
                'title': _("Rich Rules")
            },
            'interfaces': {
                'title': _("Interfaces")
            },
            'sources': {
                'title': _("Sources")
            },
        }
        # ServiceNotebook
        self.serviceConfigurationView = {
            'ports': {
                'title': _("Ports")
            },
            'protocols': {
                'title': _("Protocols")
            },
            'source_ports': {
                'title': _("Source Ports")
            },
            'modules': {
                'title': _("Modules")
            },
            'destinations': {
                'title': _("Destinations")
            },
        }
        # ServiceNotebook
        self.ipsecConfigurationView = {
            'entries': {
                'title': _("Entries")
            },
        }
        self.configureCombobox = self.factory.createComboBox(
            hbox, _("Configure"))
        # adding a dummy item to enlarge combobox
        itemColl = self._zoneConfigurationViewCollection()
        self.configureCombobox.addItems(itemColl)
        self.configureCombobox.setNotify(True)
        self.eventManager.addWidgetEvent(self.configureCombobox,
                                         self.onSelectedConfigurationChanged)
        ###

        #### Replace Point to change configuration view
        #self.rightPaneFrame = self.factory.createFrame(col2, "TEST")
        self.replacePoint = self.factory.createReplacePoint(
            col2)  #self.rightPaneFrame)
        self.configurationPanel = self.factory.createVBox(self.replacePoint)

        self._replacePointServices()

        #### bottom status lines
        align = self.factory.createLeft(layout)
        statusLine = self.factory.createHBox(align)
        self.statusLabel = self.factory.createLabel(
            statusLine, self.failed_to_connect_label)
        align = self.factory.createLeft(layout)
        statusLine = self.factory.createHBox(align)
        self.defaultZoneLabel = self.factory.createLabel(
            statusLine,
            _("Default Zone: {}").format("--------"))
        self.logDeniedLabel = self.factory.createLabel(
            statusLine,
            _("Log Denied: {}").format("--------"))
        self.panicLabel = self.factory.createLabel(
            statusLine,
            _("Panic Mode: {}").format("--------"))
        self.automaticHelpersLabel = self.factory.createLabel(
            statusLine,
            _("Automatic Helpers: {}").format("--------"))
        self.lockdownLabel = self.factory.createLabel(
            statusLine,
            _("Lockdown: {}").format("--------"))

        #### buttons on the last line
        align = self.factory.createRight(layout)
        bottomLine = self.factory.createHBox(align)
        aboutButton = self.factory.createPushButton(bottomLine, _("&About"))
        self.eventManager.addWidgetEvent(aboutButton, self.onAbout)
        quitButton = self.factory.createPushButton(bottomLine, _("&Quit"))
        self.eventManager.addWidgetEvent(quitButton, self.onQuitEvent,
                                         sendObjOnEvent)

        # Let's test a cancel event
        self.eventManager.addCancelEvent(self.onCancelEvent)
        # Let's check external events every 100 msec
        self.timeout = 100
        #self.eventManager.addTimeOutEvent(self.onTimeOutEvent)
        # End Dialof layout

        self.initFWClient()