Beispiel #1
0
    def upgrade(self):
        warnings = OrderedDict()
        do_warn = False
        for vn, upgs in self.upgrades.items():
            warnings[vn] = []

            for u in upgs:
                try:
                    exp = self.expand(u)
                except:
                    continue

                for upg in exp:
                    try:
                        old = self.get_item(upg["old"])
                    except:
                        # OK: deprecated item not found
                        pass
                    else:
                        msg = self.show_keys(upg["old"])
                        if upg["new"]:
                            msg += " -> " + self.show_keys(upg["new"])
                        else:
                            upg["new"] = upg["old"]
                        msg += " - " + upg["cvt"].describe()
                        warnings[vn].append(msg)
                        do_warn = True
                        self.del_item(upg["old"])
                        if upg["cvt"].describe() != "DELETED (OBSOLETE)":
                            self.put_item(upg["new"], upg["cvt"].convert(old))
        if do_warn and cylc.flags.verbose:
            print >>sys.stderr, "WARNING: deprecated items were automatically upgraded in '" + self.descr + "':"
            for vn, msgs in warnings.items():
                for m in msgs:
                    print >>sys.stderr, " * (" + vn + ")", m
Beispiel #2
0
def loadCode(saveCode):
    try:
        saveCode = saveCode.split(" ")
        orderedCards = OrderedDict(sorted(allCards.items(), key=lambda t: t[0]))
        i = 0
        cards = bin(int(saveCode[0]))
        # Trim binary 0b
        cards = cards[2:]
        # if there are missing leading digits
        while len(cards) < 4:
            cards = "0" + cards
        while cards:
            if cards[0].isdigit():
                if int(cards[0]):
                    card = orderedCards.items()[i]
                    deck[card[0]] = card[1]
                    if card[0] in looseCards:
                        del looseCards[card[0]]
            i += 1
            cards = cards[1:]
        model.name = saveCode[1]
        model.char = "char" + saveCode[2]
        return True
    except:
        return False
Beispiel #3
0
 def __init__(self, cutflow):
     if isinstance(cutflow, CutflowDecision):
         self._cutflow = OrderedDict(cutflow._cutflow)
     else:
         self._cutflow = OrderedDict(cutflow)
     # just need functions and flags for this
     for key in self._cutflow.keys():
         self._cutflow[key] = self._cutflow[key][:2] + [False]
Beispiel #4
0
class CutflowDecision:
    def __init__(self, cutflow):
        if isinstance(cutflow, CutflowDecision):
            self._cutflow = OrderedDict(cutflow._cutflow)
        else:
            self._cutflow = OrderedDict(cutflow)
        # just need functions and flags for this
        for key in self._cutflow.keys():
            self._cutflow[key] = self._cutflow[key][:2] + [False]
        # print self._cutflow

    def __getitem__(self, idx):
        return self._cutflow[idx][-1]

    def __call__(self, event, index=-1):
        # print 'object index:',index
        for item in self._cutflow.itervalues():
            args = []
            for arg in item[1]:
                argv = getattr(event, arg)
                if index > -1 and not isinstance(argv, (int, float, bool, long)):
                    args.append(argv[index])
                else:
                    args.append(argv)
            # print index, item[1], args
            # print 'calling %s with values:'%(item[0]),args
            item[-1] = bool(item[0](*tuple(args)))

    def __nonzero__(self):
        for item in self._cutflow.itervalues():
            if not item[-1]:
                return False
        return True

    # take the modulus of the current value of the cut
    def __mod__(self, cuts):
        for key, item in self._cutflow.iteritems():
            if key not in cuts and not item[-1]:
                return False
        return True

    # cuts is a list of names or an ordereddict
    def __sub__(self, cuts):
        cutflow = []
        if isinstance(cuts, (list, OrderedDict)):
            for key in self._cutflow.keys():
                if key not in cuts:
                    cutflow.append([key, [self._cutflow[key]]])
        return CutflowDecision(cutflow)

    # cuts is a list as mentioned in the class comment or an ordered dict
    def __add__(self, cuts):
        cutflow = OrderDict(self._cutflow)
        if isinstance(cuts, (list, OrderedDict)):
            cutflow += OrderedDict(cuts)
        return CutflowDecision(cutflow)
Beispiel #5
0
    def __init__(self, name, rtdefs, rtover, run_mode):
        if re.search("[^0-9a-zA-Z_\.]", name):
            # dot for namespace syntax (NOT USED).
            # regex [\w] allows spaces.
            raise DefinitionError, "ERROR: Illegal task name: " + name

        rtcfg = {}
        replicate(rtcfg, rtdefs.odict())  # copy [runtime] default dict
        override(rtcfg, rtover)  # override with suite [runtime] settings

        self.run_mode = run_mode
        self.rtconfig = rtcfg

        # some defaults
        self.intercycle = False
        self.cycling = False
        self.asyncid_pattern = None
        self.modifiers = []
        self.is_coldstart = False
        self.cyclers = []

        self.follow_on_task = None
        self.clocktriggered_offset = None
        self.namespace_hierarchy = []
        # triggers[0,6] = [ A, B:1, C(T-6), ... ]
        self.triggers = OrderedDict()
        # cond[6,18] = [ '(A & B)|C', 'C | D | E', ... ]
        self.cond_triggers = OrderedDict()
        self.outputs = []  # list of explicit internal outputs; change to
        # OrderedDict() if need to vary per cycle.
        self.loose_prerequisites = []  # asynchronous tasks

        self.name = name
        self.type = "free"
Beispiel #6
0
 def __init__(self, cfg, spec, descr, verbose=True):
     """Store the config dict to be upgraded if necessary."""
     self.cfg = cfg
     self.spec = spec
     self.descr = descr
     self.verbose = verbose
     # upgrades must be ordered in case several act on the same item
     self.upgrades = OrderedDict()
Beispiel #7
0
class KeymapGroup:
    def __init__(self, name):
        self.name = name
        self.subgroups = OrderedDict()

    def getAllKeys(self):
        allKeys = []
        for keys in self.subgroups.itervalues():
            for key in keys:
                allKeys.append(key)
        return allKeys
Beispiel #8
0
    def __init__(
        self,
        widget,
        label=None,
        displayLabel=True,
        buttons=None,
        toolTips=None,
        setChecked=None,
        orientation="vertical",
        callback=None,
        **kwargs
    ):
        kwargs.setdefault("includeInReports", True)
        kwargs.setdefault("sizePolicy", QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred))
        QWidget.__init__(self, widget)
        widgetState.__init__(self, widget, label, **kwargs)

        self.label = label

        if displayLabel:
            self.box = groupBox(self.controlArea, label=label, orientation=orientation)
            self.controlArea.layout().addWidget(self.box)
        else:
            self.box = widgetBox(self.controlArea, orientation=orientation)

        self.controlArea.layout().setAlignment(Qt.AlignTop | Qt.AlignLeft)
        self.box.setSizePolicy(QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred))
        # if orientation=='vertical':
        # self.box.setSizePolicy(QSizePolicy(QSizePolicy.Preferred,
        # QSizePolicy.MinimumExpanding))
        # else:
        # self.box.setSizePolicy(QSizePolicy(QSizePolicy.MinimumExpanding,
        # QSizePolicy.Preferred))

        self.items = OrderedDict()
        self.buttons = QButtonGroup(self.box)
        if buttons:
            self.addButtons(buttons)

        # for i,b in zip(range(len(buttons)),buttons):
        # w = QRadioButton(b)
        # if toolTips:
        # w.setToolTip(toolTips[i])
        # self.buttons.addButton(w)
        # self.box.layout().addWidget(w)

        if callback:
            QObject.connect(self.buttons, SIGNAL("buttonClicked(int)"), callback)

        if setChecked:
            self.setChecked(setChecked)
Beispiel #9
0
    def __init__(
        self,
        widget,
        value=None,
        label=None,
        displayLabel=True,
        orientation="vertical",
        selectionMode=QAbstractItemView.SingleSelection,
        enableDragDrop=0,
        dragDropCallback=None,
        dataValidityCallback=None,
        sizeHint=None,
        callback=None,
        items=None,
        *args,
        **kwargs
    ):
        kwargs.setdefault("includeInReports", True)
        kwargs.setdefault("sizePolicy", QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred))
        widgetState.__init__(self, widget, label, **kwargs)
        QListWidget.__init__(self, *args)
        self.label = label
        self.widget = self.controlArea
        if displayLabel:
            self.hb = groupBox(self.controlArea, label=label, orientation=orientation)

        else:
            self.hb = widgetBox(self.controlArea, orientation=orientation)

        self.hb.layout().addWidget(self)
        self.ogValue = value
        self.ogLabels = label
        self.enableDragDrop = enableDragDrop
        self.dragDopCallback = dragDropCallback
        self.dataValidityCallback = dataValidityCallback
        self.defaultSizeHint = QSize(150, 100)
        self.setSelectionMode(selectionMode)
        if enableDragDrop:
            self.setDragEnabled(1)
            self.setAcceptDrops(1)
            self.setDropIndicatorShown(1)
            # self.setDragDropMode(QAbstractItemView.DragDrop)

            self.dragStartPosition = 0

        self.listItems = OrderedDict()
        if items:
            self.addItems(items)

        if callback:
            QObject.connect(self, SIGNAL("itemClicked(QListWidgetItem*)"), callback)
Beispiel #10
0
    def __init__(
        self,
        widget,
        label=None,
        displayLabel=True,
        buttons=None,
        toolTips=None,
        setChecked=None,
        orientation="vertical",
        callback=None,
        **kwargs
    ):
        kwargs.setdefault("includeInReports", True)
        kwargs.setdefault("sizePolicy", QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred))
        """Constructor, common parameters will be widget, label, buttons (a list or list-tuple of key values for buttons), toolTips (a list of toolTips for the buttons), and setChecked (a list of keys to check from the buttons)"""
        if toolTips and len(toolTips) != len(buttons):
            raise RuntimeError(_("Number of buttons and toolTips must be equal"))

        QWidget.__init__(self, widget)
        widgetState.__init__(self, widget, label, **kwargs)

        self.controlArea.layout().addWidget(self)

        if displayLabel:
            self.box = groupBox(self.controlArea, label=label, orientation=orientation)
            # self.layout().addWidget(self.box)
        else:
            self.box = widgetBox(self.controlArea, orientation=orientation)

        self.controlArea.layout().setAlignment(Qt.AlignTop | Qt.AlignLeft)
        self.box.setSizePolicy(QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred))

        # if orientation=='vertical':
        # self.box.setSizePolicy(QSizePolicy(QSizePolicy.Preferred,
        # QSizePolicy.MinimumExpanding))
        # else:
        # self.box.setSizePolicy(QSizePolicy(QSizePolicy.MinimumExpanding,
        # QSizePolicy.Preferred))

        self.label = label
        self.items = OrderedDict()
        self.buttons = QButtonGroup(self.box)
        self.buttons.setExclusive(False)
        if buttons:
            self.addButtons(buttons)

        if callback:
            QObject.connect(self.buttons, SIGNAL("buttonClicked(int)"), callback)
        if setChecked:
            self.setChecked(setChecked)
Beispiel #11
0
    def __init__(self, *args, **kwargs):
        tmt.EclipseProject.__init__(self, *args, **kwargs)
        tmt.WinstoneServer = self
        self.main = "net.gnehzr.tnoodle.server.TNoodleServer"
        self.argv = ["--nobrowser", "--consoleLevel=INFO"]

        # Winstone does all of these things =(.
        self.ignoredWarnings += ["unchecked"]
        self.ignoredWarnings += ["deprecation"]
        self.ignoredWarnings += ["serial"]
        self.ignoredWarnings += ["dep-ann"]
        self.ignoredWarnings += ["rawtypes"]

        # It is important that when we iterate through the plugins
        # in topological sorted order. This way if B uses A, B can clobber
        # A's settings.
        self.plugins = OrderedDict()
Beispiel #12
0
Datei: h.py Projekt: kybin/h
 def initStruct(self):
     self.struct = OrderedDict(
         [
             ("root", self.rootpath),
             ("show", ""),
             ("work", "work"),
             # -------------------------------------------------
             # these levels could deleted depends on show struct
             ("seq", ""),
             ("scene", ""),
             ("shot", ""),
             # -------------------------------------------------
             ("run", "scenes"),
             ("task", ""),
             ("rev", ""),
         ]
     )
     self.head = "root"
     self.showStruct = set(["seq", "scene", "shot"])
     self.bypassStruct = ["work", "run"]
     self.printStruct = ["show", "seq", "scene", "shot", "task", "rev"]
Beispiel #13
0
    def __init__(
        self,
        widget,
        label=None,
        displayLabel=True,
        items=None,
        editable=False,
        orientation="horizontal",
        callback=None,
        **kwargs
    ):
        kwargs.setdefault("includeInReports", True)
        kwargs.setdefault("sizePolicy", QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred))
        widgetState.__init__(self, widget, label, **kwargs)
        QComboBox.__init__(self, self.controlArea)

        if displayLabel:
            self.hb = widgetBox(self.controlArea, orientation=orientation)
            lb = widgetLabel(self.hb, label)
            self.hb.layout().addWidget(self)
            self.hasLabel = True
            self.hb.layout().setAlignment(lb, Qt.AlignRight)
            lb.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        else:
            self.controlArea.layout().addWidget(self)
            self.hasLabel = False
        self.label = label

        self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred)

        self.items = OrderedDict()
        self.setEditable(editable)

        if items:
            self.addItems(items)

        if callback:
            QObject.connect(self, SIGNAL("activated(int)"), callback)
Beispiel #14
0
 def __init__(self, cfg, descr):
     """Store the config dict to be upgraded if necessary."""
     self.cfg = cfg
     self.descr = descr
     # upgrades must be ordered in case several act on the same item
     self.upgrades = OrderedDict()
Beispiel #15
0
class upgrader(object):
    """Handles upgrading of deprecated config values."""

    def __init__(self, cfg, descr):
        """Store the config dict to be upgraded if necessary."""
        self.cfg = cfg
        self.descr = descr
        # upgrades must be ordered in case several act on the same item
        self.upgrades = OrderedDict()

    def deprecate(self, vn, oldkeys, newkeys=None, cvtr=None):
        if vn not in self.upgrades:
            self.upgrades[vn] = []
        if cvtr is None:
            cvtr = converter(lambda x: x, "value unchanged")  # identity
        self.upgrades[vn].append({"old": oldkeys, "new": newkeys, "cvt": cvtr})

    def obsolete(self, vn, oldkeys, newkeys=None):
        if vn not in self.upgrades:
            self.upgrades[vn] = []
        cvtr = converter(lambda x: x, "DELETED (OBSOLETE)")  # identity
        self.upgrades[vn].append({"old": oldkeys, "new": newkeys, "cvt": cvtr})

    def get_item(self, keys):
        item = self.cfg
        for key in keys:
            item = item[key]
        return item

    def put_item(self, keys, val):
        item = self.cfg
        for key in keys[:-1]:
            if key not in item:
                item[key] = {}
            item = item[key]
        item[keys[-1]] = val

    def del_item(self, keys):
        item = self.cfg
        for key in keys[:-1]:
            item = item[key]
        del item[keys[-1]]

    def show_keys(self, keys):
        return "[" + "][".join(keys) + "]"

    def expand(self, upg):
        """Expands __MANY__ items."""
        if "__MANY__" not in upg["old"]:
            return [upg]
        if upg["old"].count("__MANY__") > 1:
            print >>sys.stderr, upg["old"]
            raise UpgradeError("Multiple simultaneous __MANY__ not supported")
        exp_upgs = []
        pre = []
        post = []
        many = []
        i = -1
        okeys = upg["old"]
        for k in okeys:
            i += 1
            if k == "__MANY__":
                pre = okeys[:i]
                post = okeys[i + 1 :]
                tmp = self.cfg
                for j in pre:
                    tmp = tmp[j]
                many = tmp.keys()
                break
        if not many:
            exp_upgs.append(upg)
        else:
            i = -1
            nkeys = upg["new"]
            npre = []
            npost = []
            for k in nkeys:
                i += 1
                if k == "__MANY__":
                    npre = nkeys[:i]
                    npost = nkeys[i + 1 :]
            if not npre or not npost:
                raise UpgradeError("ERROR: __MANY__ mismatch")
            for m in many:
                exp_upgs.append({"old": pre + [m] + post, "new": npre + [m] + npost, "cvt": upg["cvt"]})
        return exp_upgs

    def upgrade(self):
        warnings = OrderedDict()
        do_warn = False
        for vn, upgs in self.upgrades.items():
            warnings[vn] = []

            for u in upgs:
                try:
                    exp = self.expand(u)
                except:
                    continue

                for upg in exp:
                    try:
                        old = self.get_item(upg["old"])
                    except:
                        # OK: deprecated item not found
                        pass
                    else:
                        msg = self.show_keys(upg["old"])
                        if upg["new"]:
                            msg += " -> " + self.show_keys(upg["new"])
                        else:
                            upg["new"] = upg["old"]
                        msg += " - " + upg["cvt"].describe()
                        warnings[vn].append(msg)
                        do_warn = True
                        self.del_item(upg["old"])
                        if upg["cvt"].describe() != "DELETED (OBSOLETE)":
                            self.put_item(upg["new"], upg["cvt"].convert(old))
        if do_warn and cylc.flags.verbose:
            print >>sys.stderr, "WARNING: deprecated items were automatically upgraded in '" + self.descr + "':"
            for vn, msgs in warnings.items():
                for m in msgs:
                    print >>sys.stderr, " * (" + vn + ")", m
Beispiel #16
0
class listBox(QListWidget, widgetState):
    def __init__(
        self,
        widget,
        value=None,
        label=None,
        displayLabel=True,
        orientation="vertical",
        selectionMode=QAbstractItemView.SingleSelection,
        enableDragDrop=0,
        dragDropCallback=None,
        dataValidityCallback=None,
        sizeHint=None,
        callback=None,
        items=None,
        *args,
        **kwargs
    ):
        kwargs.setdefault("includeInReports", True)
        kwargs.setdefault("sizePolicy", QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred))
        widgetState.__init__(self, widget, label, **kwargs)
        QListWidget.__init__(self, *args)
        self.label = label
        self.widget = self.controlArea
        if displayLabel:
            self.hb = groupBox(self.controlArea, label=label, orientation=orientation)

        else:
            self.hb = widgetBox(self.controlArea, orientation=orientation)

        self.hb.layout().addWidget(self)
        self.ogValue = value
        self.ogLabels = label
        self.enableDragDrop = enableDragDrop
        self.dragDopCallback = dragDropCallback
        self.dataValidityCallback = dataValidityCallback
        self.defaultSizeHint = QSize(150, 100)
        self.setSelectionMode(selectionMode)
        if enableDragDrop:
            self.setDragEnabled(1)
            self.setAcceptDrops(1)
            self.setDropIndicatorShown(1)
            # self.setDragDropMode(QAbstractItemView.DragDrop)

            self.dragStartPosition = 0

        self.listItems = OrderedDict()
        if items:
            self.addItems(items)

        if callback:
            QObject.connect(self, SIGNAL("itemClicked(QListWidgetItem*)"), callback)

    def getItems(self):
        """Returns an OrderedDict of the items (key, value) in the listBox, this can be treated as a dict also."""
        return self.listItems

    def addItem(self, id, item):
        QListWidget.addItem(self, item)
        self.listItems[id] = item

    def addItems(self, items):
        progressBar = startProgressBar("Setting List Items", "", len(items))
        progress = 0
        if type(items) in [dict, OrderedDict]:

            for k, v in items.items():
                self.addItem(k, v)
                progress += 1
                progressBar.setValue(progress)

        elif type(items) in [list]:
            progressBar = startProgressBar("Setting List Items", "", len(items))
            if len(items) > 0 and type(items[0]) is tuple:
                for k, v in items:
                    self.addItem(k, v)
                    progress += 1
                    progressBar.setValue(progress)
            else:
                for v in items:
                    self.addItem(v, v)
                    progress += 1
                    progressBar.setValue(progress)
            # redRLog.log(redRLog.REDRCORE,redRLog.DEBUG,_('In listBox should not use list'))
        else:
            progressBar.hide()
            raise Exception(_("In listBox, addItems takes a list, dict or OrderedDict"))
        progressBar.hide()

    def setSelectedIds(self, ids):
        """Sets a list of ids (ids) to be selected."""
        if ids == None:
            return
        progressBar = startProgressBar("Setting Selected Items", "", len(ids))
        progress = 0
        for x in ids:
            try:
                self.item(self.listItems.keys().index(x)).setSelected(True)
            except:
                pass
            progress += 1
            progressBar.setValue(progress)

    def update(self, items):
        """Clears the list, adds new items, and sets any selected items in the old list to being selected in the new list (if they exist of course)."""
        current = self.selectedIds()
        self.clear()
        self.addItems(items)
        self.setSelectedIds(current)

    def clear(self):
        """Clears the list"""
        QListWidget.clear(self)
        self.listItems = OrderedDict()

    def invertSelection(self):
        for i in range(self.count()):
            if self.isItemSelected(self.item(i)):
                self.item(i).setSelected(False)
            else:
                self.item(i).setSelected(True)

    def selectionCount(self):
        return len(self.selectedIndexes())

    def currentSelection(self):
        """Returns a list of selected values (the text in the list)"""
        return self.selectedItems().values()

    def selectedItems(self):
        """Returns a dict of selected items."""
        items = {}
        for x in self.selectedIndexes():
            items[self.listItems.keys()[x.row()]] = self.listItems.values()[x.row()]
        return items

    def selectedIds(self):
        """Returns a list of selected ids"""
        ids = []
        for x in self.selectedIndexes():
            ids.append(self.listItems.keys()[x.row()])
        return ids

    # def setSelectedIds(self, ids):
    # if ids == None: return
    # for i in range(self.count()):
    # if self.listItems.keys()[i] in ids:
    # self.item(i).setSelect(True)

    def sizeHint(self):
        return self.defaultSizeHint

    def startDrag(self, supportedActions):
        if not self.enableDragDrop:
            return

        drag = QDrag(self)
        mime = QMimeData()

        if not self.ogValue:
            selectedItems = [i for i in range(self.count()) if self.item(i).isSelected()]
        else:
            selectedItems = getdeepattr(self.widget, self.ogValue, default=[])

        mime.setText(unicode(selectedItems))
        mime.source = self
        drag.setMimeData(mime)
        drag.start(Qt.MoveAction)

    def dragEnterEvent(self, ev):
        if not self.enableDragDrop:
            return
        if self.dataValidityCallback:
            return self.dataValidityCallback(ev)

        if ev.mimeData().hasText():
            ev.accept()
        else:
            ev.ignore()

    def dragMoveEvent(self, ev):
        if not self.enableDragDrop:
            return
        if self.dataValidityCallback:
            return self.dataValidityCallback(ev)

        if ev.mimeData().hasText():
            ev.setDropAction(Qt.MoveAction)
            ev.accept()
        else:
            ev.ignore()

    def dropEvent(self, ev):
        if not self.enableDragDrop:
            return
        if ev.mimeData().hasText():
            item = self.itemAt(ev.pos())
            if item:
                index = self.indexFromItem(item).row()
            else:
                index = self.count()

            source = ev.mimeData().source
            selectedItemIndices = eval(unicode(ev.mimeData().text()))

            if self.ogLabels != None and self.ogValue != None:
                allSourceItems = getdeepattr(source.widget, source.ogLabels, default=[])
                selectedItems = [allSourceItems[i] for i in selectedItemIndices]
                allDestItems = getdeepattr(self.widget, self.ogLabels, default=[])

                if source != self:
                    setattr(
                        source.widget, source.ogLabels, [item for item in allSourceItems if item not in selectedItems]
                    )  # TODO: optimize this code. use the fact that the selectedItemIndices is a sorted list
                    setattr(self.widget, self.ogLabels, allDestItems[:index] + selectedItems + allDestItems[index:])
                    setattr(source.widget, source.ogValue, [])  # clear selection in the source widget
                else:
                    items = [item for item in allSourceItems if item not in selectedItems]
                    if index < len(allDestItems):
                        while index > 0 and index in getdeepattr(
                            self.widget, self.ogValue, default=[]
                        ):  # if we are dropping items on a selected item, we have to select some previous unselected item as the drop target
                            index -= 1
                        destItem = allDestItems[index]
                        index = items.index(destItem)
                    else:
                        index = max(0, index - len(selectedItems))
                    setattr(self.widget, self.ogLabels, items[:index] + selectedItems + items[index:])
                setattr(self.widget, self.ogValue, range(index, index + len(selectedItems)))
            else:  # if we don't have variables ogValue and ogLabel
                if source != self:
                    self.insertItems(source.selectedItems())
                    for index in selectedItemIndices[::-1]:
                        source.takeItem(index)
                else:
                    if index < self.count():
                        while (
                            index > 0 and self.item(index).isSelected()
                        ):  # if we are dropping items on a selected item, we have to select some previous unselected item as the drop target
                            index -= 1
                    items = [source.item(i) for i in selectedItemIndices]
                    for ind in selectedItemIndices[::-1]:
                        source.takeItem(ind)
                        if ind <= index:
                            index -= 1
                    for item in items[::-1]:
                        self.insertItem(index, item)
                    self.clearSelection()
                    for i in range(index, index + len(items)):
                        self.item(i).setSelected(1)

            if self.dragDopCallback:  # call the callback
                self.dragDopCallback()
            ev.setDropAction(Qt.MoveAction)
            ev.accept()

            ## whatever all of this does we need to execute the function to update the items
            self.updateRedRItems()
        else:
            ev.ignore()

    def updateRedRItems(self):
        """Updates the items in the list to a new order."""
        ## we go through all of the items and remake the items OrderedDict
        newDict = OrderedDict()
        for r in range(self.count()):
            t = unicode(self.item(r).text())  # get the text of the item
            if t not in self.listItems.values():
                newDict[t] = t
            else:
                for i, ov in self.listItems.items():
                    if ov == t:
                        newDict[i] = ov
        self.listItems = newDict

    def getSettings(self):
        # print 'saving list box'
        r = {"items": self.listItems, "selected": self.selectedIds()}
        # print r
        return r

    def loadSettings(self, data):
        self.clear()
        self.addItems(data.get("items", []))
        self.setSelectedIds(data.get("selected", None))

    def getReportText(self, fileDir):
        items = self.getItems()
        selected = self.currentSelection()
        new = []

        for x in items:
            if x in selected:
                new.append([_("Selected"), x])
            else:
                new.append([_("Not Selected"), x])
        # print new
        text = redRReports.createTable(new, columnNames=[_("Selection"), _("Option")])
        # if text != '':
        # text += '\nSelected text has * in front'

        r = {self.widgetName: {"includeInReports": self.includeInReports, "text": text}}

        return r
Beispiel #17
0
 def __init__(self, fn=""):
     OrderedDict.__init__(self)
     _DpkgDatalist.__init__(self, fn)
Beispiel #18
0
 def __init__(self, name):
     self.name = name
     self.subgroups = OrderedDict()
Beispiel #19
0
class MagnetWrapper(DeviceWrapper):
    def connect(self, nodeName, cxn):
        print "Connect: %s" % nodeName
        self.cxn = cxn
        self.ctxt = self.cxn.context()
        self.nodeName = nodeName

        # state variables of this object
        self.status = "Missing Devices"
        self.setCurrent = Value(NaN, "A")
        self.voltageLimit = VOLTAGE_LIMIT_DEFAULT
        self.temperatureOverride = False  # if True, ignore temperature checks
        self.sensingMode = True

        # devices we must link to
        self.devs = OrderedDict()
        self.devs[POWER] = {
            "server": None,
            "values": [NaN] * len(POWER_SETTINGS),
            "status": "not initialized",
            "settings": POWER_SETTINGS,
            "extras": ["output"],
        }
        self.devs[DMM] = {
            "server": None,
            "values": [NaN] * len(DMM_SETTINGS),
            "status": "not initialized",
            "settings": DMM_SETTINGS,
            "gpib address": 24,
            "init funcs": ["configure_voltage"],
        }
        self.devs[DC] = {
            "server": None,
            "values": [NaN] * len(DC_SETTINGS),
            "status": "not initialized",
            "settings": DC_SETTINGS,
            "extras": ["output", "persistent_switch_mode", "persistent_switch_time_elapsed"],
        }
        self.devs[TEMPERATURE] = {
            "server": None,
            "values": [NaN] * len(TEMPERATURE_SETTINGS),
            "status": "not initialized",
            "settings": TEMPERATURE_SETTINGS,
            "flatten": True,
            "pickOneValue": 1,
        }
        self.devs[DMM2] = {
            "server": None,
            "values": [NaN] * len(DMM2_SETTINGS),
            "status": "not initialized",
            "settings": DMM2_SETTINGS,
            "gpib address": 27,
        }

        # Persistent Switch
        self.psHeated = None  # T/F for switch heated or not
        self.psCurrent = NaN * A  # current when switch was cooled/closed
        self.psTime = 0  # time since switch state was last changed
        self.psRequestedState = None  # None=leave as is, T = heated, F = cooled
        self.psStatus = "Not started"

        # DV logging stuff
        self.dv = None
        self.dvName = None
        self.dvRecordDelay = 5  # record every X seconds
        self.dvLastTimeRecorded = 0
        self.dvStatus = "Not started"

        # the main loop stuff
        self.timeInterval = 0.2
        self.loop = LoopingCall(self.mainLoop)
        self.loopDone = self.loop.start(self.timeInterval, now=True)
        print "loop started"

    @inlineCallbacks
    def shutdown(self):
        self.loop.stop()
        yield self.loopDone

    @inlineCallbacks
    def mainLoop(self):
        # print 'loop executing'
        # do our updates asynch
        defers = [self.doDevice(dev) for dev in self.devs.keys()]
        for defer in defers:
            yield defer
        # do we have all devices?
        if not (
            "OK" == self.devs[POWER]["status"]
            and "OK" == self.devs[DMM]["status"]
            and "OK" == self.devs[DC]["status"]
            and "OK" == self.devs[TEMPERATURE]["status"]
        ):
            # if not, update status, do nothing
            self.status = "Missing Devices"
        else:
            # if so, do stuff
            # check the temperature
            if self.checkTemperature():
                try:
                    # if we don't have a current setpoint, set it to the setpoint of the power supply
                    if math.isnan(self.setCurrent) and self.devs[POWER]["status"] == "OK":
                        self.current(self.devs[POWER]["values"][0])
                    # see about a mag
                    # yield self.doMagCycle()
                    self.doMagCycle()
                    self.status = "OK"
                except Exception as e:
                    print "Exception in main loop: %s" % str(e)
            else:
                # we are over temperature
                # shut down the magnet if it's running
                if self.devs[POWER]["status"] == "OK" and abs(self.devs[POWER]["values"][0]) > CURRENT_RESOLUTION:
                    self.devs[POWER]["server"].shut_off(context=self.devs[POWER]["context"])
                    self.current(0 * A)
                self.status = "Over Temperature"
        try:
            # record data
            self.doDataVault()
        except Exception as e:
            print "Exception in data vault"
        try:
            # persistent switch
            self.doPersistentSwitch()
        except Exception as e:
            print "Exception in persistent switch"

    @inlineCallbacks
    def doDevice(self, dev):
        # do we need a server? if so, connect to it
        if not self.devs[dev]["server"] and SERVERS[dev] in self.cxn.servers:
            self.devs[dev]["server"] = self.cxn[SERVERS[dev]]
            self.devs[dev]["context"] = self.devs[dev]["server"].context()
        # do we have a server? if so, get our data
        if self.devs[dev]["server"]:
            # build packet out of requested settings
            p = self.devs[dev]["server"].packet()
            for s in self.devs[dev]["settings"]:
                p[s](key=s)
            if "extras" in self.devs[dev].keys():
                for s in self.devs[dev]["extras"]:
                    p[s](key=s)
            try:
                # try to get our data
                ans = yield p.send(context=self.devs[dev]["context"])
                self.devs[dev]["values"] = [ans[s] for s in self.devs[dev]["settings"]]
                # couple of special cases
                if "flatten" in self.devs[dev].keys():
                    self.devs[dev]["values"] = [item for sublist in self.devs[dev]["values"] for item in sublist]
                if "pickOneValue" in self.devs[dev].keys():
                    self.devs[dev]["values"] = [self.devs[dev]["values"][self.devs[dev]["pickOneValue"]]]
                if "pickSubset" in self.devs[dev].keys():
                    self.devs[dev]["values"] = [self.devs[dev]["values"][x] for x in self.devs[dev]["pickSubset"]]
                if "extras" in self.devs[dev].keys():
                    self.devs[dev]["extraValues"] = [ans[s] for s in self.devs[dev]["extras"]]
                self.devs[dev]["status"] = "OK"
            except Error as e:
                # catch labrad error (usually DeviceNotSelectedError) -- select our device if we have one
                self.devs[dev]["values"] = [NaN] * len(self.devs[dev]["settings"])
                if "DeviceNotSelectedError" in e.msg or "NoDevicesAvailableError" in e.msg:
                    devs = yield self.devs[dev]["server"].list_devices(context=self.devs[dev]["context"])
                    found = False
                    for d in devs:
                        if "gpib address" in self.devs[dev].keys():
                            # print d[1]
                            if not d[1].endswith(str(self.devs[dev]["gpib address"])):
                                continue
                        if self.nodeName.upper() in d[1].upper():
                            found = True
                            yield self.devs[dev]["server"].select_device(d[0], context=self.devs[dev]["context"])
                            if "init funcs" in self.devs[dev].keys():
                                for i_f in self.devs[dev]["init funcs"]:
                                    print "calling %s" % i_f
                                    self.devs[dev]["server"][i_f](context=self.devs[dev]["context"])
                            self.devs[dev]["status"] = "Found Device"
                    if not found:
                        self.devs[dev]["status"] = "No Device"
                elif "Target" in e.msg and "unknown" in e.msg:
                    # server has been turned off
                    # print e.msg
                    self.devs[dev]["server"] = None
                    self.devs[dev]["status"] = "No Server"
                else:
                    print "Unhandled error in main loop: %s" % e.msg
                    self.devs[dev]["status"] = "Other Error"
        else:
            self.devs[dev]["status"] = "No Server"
            self.devs[dev]["values"] = [NaN] * len(self.devs[dev]["settings"])

    #    @inlineCallbacks
    def doMagCycle(self):
        """ Do a mag cycle if applicable. Here are the rules:
        -- Must have connection to all servers, below temperature. (status = OK)
        -- Must be below voltage limit.
        -- Current difference must be larger than the resolution limit.
        """
        if self.status != "OK":
            return
        if self.psStatus.startswith("Cooled"):
            self.doMagCycleSwitchCooled()
        elif not self.psStatus.startswith("Heated"):
            return
        if self.devs[POWER]["extraValues"][0] == False:
            self.devs[POWER]["server"].voltage_mode(context=self.devs[POWER]["context"])
            self.devs[POWER]["server"].output(True, context=self.devs[POWER]["context"])
        # is the set current where we want it to be?
        if self.devs[POWER]["values"][1] < abs(self.setCurrent):
            self.devs[POWER]["server"].set_current(abs(self.setCurrent), context=self.devs[POWER]["context"])
        # if the supply setpoint is above the server setpoint
        # and the supply value is below the supply setpoint
        # then set the supply setpoint to max(supply value, server setpoint)
        # (prevents us from leaving the supply setpoint at some high number when magging down)
        print self.devs[POWER]["values"][1], self.setCurrent, self.devs[POWER]["values"][0]
        if self.devs[POWER]["values"][1] > abs(self.setCurrent) + CURRENT_RESOLUTION:
            if abs(self.devs[POWER]["values"][0]) < self.devs[POWER]["values"][1]:
                newcurr = max(abs(self.devs[POWER]["values"][0]) + CURRENT_RESOLUTION * 100, abs(self.setCurrent))
                self.devs[POWER]["server"].set_current(newcurr, context=self.devs[POWER]["context"])

        ## first, sensing mode
        if self.sensingMode:
            # have we reached the target?
            if abs(self.devs[POWER]["values"][0] - self.setCurrent) < CURRENT_RESOLUTION:
                self.devs[POWER]["server"].set_voltage(0, context=self.devs[POWER]["context"])
            # do we go up or down?
            elif self.setCurrent < self.devs[POWER]["values"][0]:
                self.devs[POWER]["server"].set_voltage(-1 * abs(self.voltageLimit), context=self.devs[POWER]["context"])
            elif self.setCurrent > self.devs[POWER]["values"][0]:
                self.devs[POWER]["server"].set_voltage(1 * abs(self.voltageLimit), context=self.devs[POWER]["context"])
        ### now, old mode ("manual sensing")
        else:
            # have we reached the target?
            if abs(self.devs[POWER]["values"][0] - self.setCurrent) < CURRENT_RESOLUTION:
                # set the voltage so that the magnet voltage is zero
                newvolt = self.devs[POWER]["values"][2] - self.devs[DMM]["values"][0]
                self.devs[POWER]["server"].set_voltage(newvolt, context=self.devs[POWER]["context"])
                print "done magging! %s" % newvolt
                return
            # is the magnet voltage below the limit?
            if self.setCurrent < self.devs[POWER]["values"][0] and self.devs[DMM]["values"][0] > -self.voltageLimit:
                newvolt = self.devs[POWER]["values"][2] - VOLTAGE_STEP
                print "mag step -> %s" % newvolt
                self.devs[POWER]["server"].set_voltage(newvolt, context=self.devs[POWER]["context"])
            elif self.setCurrent > self.devs[POWER]["values"][0] and self.devs[DMM]["values"][0] < self.voltageLimit:
                newvolt = self.devs[POWER]["values"][2] + VOLTAGE_STEP
                print "mag step -> %s" % newvolt
                self.devs[POWER]["server"].set_voltage(newvolt, context=self.devs[POWER]["context"])

    def doMagCycleSwitchCooled(self):
        """ this is called when the persistent switch is cold. """
        if abs(self.devs[POWER]["values"][0] - self.setCurrent) < CURRENT_RESOLUTION * 5:
            if abs(self.setCurrent) < CURRENT_RESOLUTION:
                self.devs[POWER]["server"].output(False, context=self.devs[POWER]["context"])
            return
        if self.setCurrent < self.devs[POWER]["values"][0]:
            newvolt = self.devs[POWER]["values"][2] - VOLTAGE_STEP
            self.devs[POWER]["server"].set_voltage(newvolt, context=self.devs[POWER]["context"])
        else:
            newVolt = self.devs[POWER]["values"][2] + VOLTAGE_STEP
            self.devs[POWER]["server"].set_voltage(newvolt, context=self.devs[POWER]["context"])

    def doPersistentSwitch(self):
        """ Handle the persistent switch.
        """
        # make sure we have the server/device
        if self.devs[DC]["status"] != "OK":
            self.psStatus = "No server/device"
            return
        # is DC supply in PS mode?
        if not self.devs[DC]["extraValues"][1]:
            # asynch send message to put in PS Mode
            self.devs[DC]["server"].persistent_switch_mode(True, context=self.devs[DC]["context"])
            self.psStatus = "Setting PS mode on device."
            return
        self.psHeated = self.devs[DC]["extraValues"][0]
        self.psTime = self.devs[DC]["extraValues"][2]
        # Logic:
        # if desired state == None, set desired state = current state
        # if desired state == None or desired state == current state == heated, do nothing
        # if desired state == cooled and current state == cooled,
        #   if time > required time, mag to zero
        # if desired state == cooled and current state == heated,
        #   if current value is at setpoint, turn off switch heating, record current value
        # if desired state == heated and current state == cooled,
        #   if current value is not at recorded value, mag to recorded value
        #   if current value is at recorded value, heat switch
        if self.psRequestedState is None:
            self.psRequestedState = self.psHeated
            if not self.psRequestedState:
                self.psCurrent = self.setCurrent
        if self.psRequestedState is True and self.psHeated is True:
            if self.psTime < PS_COOLING_TIME:
                self.psStatus = "Waiting for heating"
                return
            else:
                self.psStatus = "Heated"
                return
        if self.psRequestedState is False and self.psHeated is False:
            if self.psTime > PS_COOLING_TIME and abs(self.setCurrent) > CURRENT_RESOLUTION:
                self.current(0)
                self.psStatus = "Cooled; turning off power"
                return
            elif self.psTime > PS_COOLING_TIME and abs(self.devs[POWER]["values"][0]) >= CURRENT_RESOLUTION:
                self.psStatus = "Cooled; powering down"
                return
            elif self.psTime > PS_COOLING_TIME and abs(self.devs[POWER]["values"][0]) < CURRENT_RESOLUTION:
                self.psStatus = "Cooled; power off"
                return
            else:  # waiting for switch to cool
                self.psStatus = "Waiting for cooling"
                return
        if self.psRequestedState is False and self.psHeated is True:
            # check for current to be at setpoint
            if abs(self.setCurrent - self.devs[POWER]["values"][0]) < CURRENT_RESOLUTION:
                self.psCurrent = self.devs[POWER]["values"][0]
                self.devs[DC]["server"].output(False, context=self.devs[DC]["context"])  # do the deed, asynch
                self.psStatus = "Turned heater off"
                return
            else:
                self.psStatus = "Heated; Waiting for current setpoint"
                return
        if self.psRequestedState is True and self.psHeated is False:
            # ramp to appropriate current
            self.current(self.psCurrent)
            if abs(self.psCurrent - self.devs[POWER]["values"][0]) < CURRENT_RESOLUTION * 5:
                # we're at the appropriate current
                self.devs[DC]["server"].output(True, context=self.devs[DC]["context"])
                self.psStatus = "Turned heater on"
                return
            else:
                self.psStatus = "Cooled; Powering up"
                return
        # if we made it here it's a programming error!
        self.psStatus = "Error in code!"

    def doDataVault(self):
        """ Record data if the appropriate time has passed.
        If we need to create a new dataset, do it.
        No need to wait on the return, though. 
        As we do this asynchronously there is a slight danger of one of the add data packets
        arriving ahead of the create dataset packets, but in a practical sense this should
        never happen with the multi-second delay we normally use."""
        # time, status check
        if (
            self.status != "OK" and self.status != "Over Temperature"
        ) or time.time() - self.dvLastTimeRecorded < self.dvRecordDelay:
            return
        self.dvLastTimeRecorded = t = time.time()
        # server check
        if self.dv is None and "Data Vault" in self.cxn.servers:
            self.dv = self.cxn.data_vault
        elif self.dv is None:
            self.dvStatus = "Data Vault server not found."
            return
        # get together our data
        data = [t, self.magnetCurrent(), self.current()]
        for x in self.devs.keys():
            data += self.devs[x]["values"]
        p = self.dv.packet(context=self.ctxt)
        # dataset check
        if not self.dvName:
            self.dvName = "Magnet Controller Log - %s - %s" % (self.nodeName, time.strftime("%Y-%m-%d %H:%M"))
            self.dvNew = True
            p.cd(DATA_PATH, True)
            p.new(
                self.dvName,
                ["time [s]"],
                [
                    "Current (Magnet) [A]",
                    "Current (Setpoint) [A]",
                    "Current (Power Supply) [A]",
                    "Current (Power Supply Setpoint) [A]",
                    "Voltage (Power Supply) [V]",
                    "Voltage (Power Supply Setpoint) [V]",
                    "Voltage (Magnet) [V]",
                    "Current (Heater) [A]",
                    "Voltage (Heater) [V]",
                    "Temperature (4K) [K]",
                    "Current (DMM2) [A]",
                ],
            )
            p.add_parameters(("Start Time (str)", time.strftime("%Y-%m-%d %H:%M")), ("Start Time (int)", time.time()))
        # add the data
        p.add(data)
        d = p.send(context=self.ctxt)
        d.addCallback(self.handleDVCreateCallback)
        d.addErrback(self.handleDVError)
        self.dvStatus = "Logging"

    def handleDVCreateCallback(self, response):
        """ called after dataset is created. just to get the correct name, really. """
        if self.dvNew:
            self.dvName = response.new[1]
            self.dvNew = False

    def handleDVError(self, failure):
        """ this is an errback added to the call to the data vault.
        if it gets called (i.e. there is an exception in the DV call),
        we assume that we need to create a data set. """
        print "dv error!"
        failure.trap(Error)
        print failure
        self.dvName = None
        self.dv = None
        self.dvStatus = "Creating new dataset"

    def checkTemperature(self):
        """ Checks that the magnet temperature is safe. """
        try:
            # print self.devs[TEMPERATURE]['values'][0]
            good = self.temperatureOverride or self.devs[TEMPERATURE]["values"][0] < TEMP_LIMIT
            return good
        except Exception as e:
            print "Exception in checkTemperature: %s" % e
            return False

    def current(self, current=None):
        """ change the current setpoint. """
        if current is None:
            return self.setCurrent
        if not isinstance(current, Value):
            current = Value(float(current), "A")
        self.setCurrent = current.inUnitsOf("A")
        self.setCurrent = max(-CURRENT_LIMIT, min(CURRENT_LIMIT, self.setCurrent))
        return self.setCurrent

    def magnetCurrent(self):
        """ Get the magnet current. This is either the power supply current (if the heater is on)
        or the remembered current if we're in persistent mode. """
        if self.psHeated is False:
            return self.psCurrent
        else:
            # return (self.devs[DMM2]['values'][0] / DMM2_RESISTANCE).inUnitsOf("A")
            return self.devs[POWER]["values"][0]

    def getStatus(self):
        """ returns all the statuses """
        return [self.status, self.dvStatus, self.psStatus] + [self.devs[dev]["status"] for dev in self.devs.keys()]

    def getValues(self):
        """ returns all the applicable values of this magnet controller. """
        # a little hackish because we only return the 4K temperature
        r = [self.magnetCurrent(), self.current()]
        for dev in self.devs.keys():
            r += self.devs[dev]["values"]
        r.insert(7, self.voltageLimit)
        return r
        # return self.devs[POWER]['values'] + self.devs[DMM]['values'] + self.devs[DC]['values'] + [self.devs[TEMPERATURE]['values'][1]]

    def persistentSwitch(self, newState):
        """ sets/gets the desired state of the switch.
        True = heated = open (leave it this way when magging)
        False = cooled = closed (for steady field)
        Note that the process of opening/closing the switch is an involved one.
        """
        if newState is not None:
            self.psRequestedState = bool(newState)
        return self.psRequestedState

    def psSetCurrent(self, newCurrent):
        if newCurrent is not None:
            if not isinstance(newCurrent, Value):
                newCurrent = Value(float(newCurrent), "A")
            self.psCurrent = newCurrent.inUnitsOf("A")
            self.psCurrent = max(-CURRENT_LIMIT, min(CURRENT_LIMIT, self.psCurrent))
        return self.psCurrent
Beispiel #20
0
    def __init__(self, name):
        if re.search("[^0-9a-zA-Z_\.]", name):
            # dot for namespace syntax (NOT USED).
            # regex [\w] allows spaces.
            raise DefinitionError, "ERROR: Illegal task name: " + name

        self.name = name
        self.type = "free"
        self.job_submit_method = None
        self.job_submission_shell = None
        self.job_submit_command_template = None
        self.job_submit_log_directory = None
        self.job_submit_share_directory = None
        self.job_submit_work_directory = None
        self.manual_messaging = False
        self.modifiers = []
        self.asyncid_pattern = None
        self.cycling = False
        self.is_coldstart = False

        self.remote_host = None
        self.owner = None
        self.remote_shell_template = None
        self.remote_cylc_directory = None
        self.remote_suite_directory = None
        self.remote_log_directory = None

        self.reset_timer = False
        self.event_handlers = {}
        self.timeouts = {}
        self.resurrectable = False

        self.intercycle = False
        self.cyclers = []
        self.logfiles = []
        self.description = ["Task description has not been completed"]

        self.follow_on_task = None

        self.clocktriggered_offset = None

        # triggers[0,6] = [ A, B:1, C(T-6), ... ]
        self.triggers = OrderedDict()
        # cond[6,18] = [ '(A & B)|C', 'C | D | E', ... ]
        self.cond_triggers = OrderedDict()

        self.outputs = []  # list of explicit internal outputs; change to
        # OrderedDict() if need to vary per cycle.

        self.loose_prerequisites = []  # asynchronous tasks

        self.command = None
        self.retry_delays = deque()
        self.precommand = None
        self.postcommand = None
        self.initial_scripting = None
        self.enviro_scripting = None
        self.ssh_messaging = False

        self.environment = OrderedDict()  # var = value
        self.directives = OrderedDict()  # var = value

        self.namespace_hierarchy = []

        self.sim_mode_run_length = None
        self.fail_in_sim_mode = False
Beispiel #21
0
class radioButtons(widgetState, QWidget):
    def __init__(
        self,
        widget,
        label=None,
        displayLabel=True,
        buttons=None,
        toolTips=None,
        setChecked=None,
        orientation="vertical",
        callback=None,
        **kwargs
    ):
        kwargs.setdefault("includeInReports", True)
        kwargs.setdefault("sizePolicy", QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred))
        QWidget.__init__(self, widget)
        widgetState.__init__(self, widget, label, **kwargs)

        self.label = label

        if displayLabel:
            self.box = groupBox(self.controlArea, label=label, orientation=orientation)
            self.controlArea.layout().addWidget(self.box)
        else:
            self.box = widgetBox(self.controlArea, orientation=orientation)

        self.controlArea.layout().setAlignment(Qt.AlignTop | Qt.AlignLeft)
        self.box.setSizePolicy(QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred))
        # if orientation=='vertical':
        # self.box.setSizePolicy(QSizePolicy(QSizePolicy.Preferred,
        # QSizePolicy.MinimumExpanding))
        # else:
        # self.box.setSizePolicy(QSizePolicy(QSizePolicy.MinimumExpanding,
        # QSizePolicy.Preferred))

        self.items = OrderedDict()
        self.buttons = QButtonGroup(self.box)
        if buttons:
            self.addButtons(buttons)

        # for i,b in zip(range(len(buttons)),buttons):
        # w = QRadioButton(b)
        # if toolTips:
        # w.setToolTip(toolTips[i])
        # self.buttons.addButton(w)
        # self.box.layout().addWidget(w)

        if callback:
            QObject.connect(self.buttons, SIGNAL("buttonClicked(int)"), callback)

        if setChecked:
            self.setChecked(setChecked)

    def addButtons(self, buttons):
        if type(buttons) in [dict, OrderedDict]:
            for k, v in buttons.items():
                self.addButton(k, v)
        elif type(buttons) in [list]:
            if len(buttons) > 0 and type(buttons[0]) is tuple:
                for k, v in buttons:
                    self.addButton(k, v)
            else:
                for v in buttons:
                    self.addButton(v, v)

            # redRLog.log(redRLog.REDRCORE,redRLog.DEBUG,_('In radioButtons should not use list'))
        else:
            raise Exception(_("In radioButtons, addButtons takes a list, dict or OrderedDict"))

    def addButton(self, id, text, toolTip=None):
        self.items[id] = text
        w = QRadioButton(text)
        if toolTip:
            w.setToolTip(toolTip)
        self.buttons.addButton(w, self.items.keys().index(id))
        self.box.layout().addWidget(w)

    def setChecked(self, id):
        buttons = self.buttons.buttons()
        try:
            self.buttons.button(self.items.keys().index(id)).setChecked(True)
        except:
            pass
        # for i in self.buttons.buttons():
        # if i.text() == id: i.setChecked(True)
        # else: i.setChecked(False)

    def getCheckedItem(self):
        buttonId = self.buttons.checkedId()
        if buttonId == -1:
            return
        return {self.items.keys()[buttonId]: self.items[self.items.keys()[buttonId]]}

    def getChecked(self):
        buttonId = self.buttons.checkedId()
        if buttonId == -1:
            return
        return self.items[self.items.keys()[buttonId]]

        # if button == 0 or button == None or button.isEnabled()==False: return 0
        # else: return unicode(button.text())

    def getCheckedId(self):
        buttonId = self.buttons.checkedId()
        if buttonId == -1:
            return
        return self.items.keys()[buttonId]

    def setSizePolicy(self, h, w):
        # self.controlArea.setSizePolicy(h,w)
        # QWidget.setSizePolicy(self,h,w)
        self.box.setSizePolicy(h, w)

    def disable(self, buttons):
        for i in self.buttons.buttons():
            if i.text() in buttons:
                i.setDisabled(True)

    def enable(self, buttons):
        for i in self.buttons.buttons():
            if i.text() in buttons:
                i.setEnabled(True)

    def getSettings(self):
        # print _('radioButtons getSettings') + self.getChecked()
        r = {"items": self.items, "checked": self.getCheckedId(), "visible": self.box.isVisible()}
        return r

    def loadSettings(self, data):
        # print _('radioButtons loadSettings') + data
        # self.addButtons(data['items'])
        self.setChecked(data["checked"])

    def getReportText(self, fileDir):
        r = {self.widgetName: {"includeInReports": self.includeInReports, "text": self.getChecked()}}
        return r
Beispiel #22
0
class checkBox(widgetState, QWidget):
    def __init__(
        self,
        widget,
        label=None,
        displayLabel=True,
        buttons=None,
        toolTips=None,
        setChecked=None,
        orientation="vertical",
        callback=None,
        **kwargs
    ):
        kwargs.setdefault("includeInReports", True)
        kwargs.setdefault("sizePolicy", QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred))
        """Constructor, common parameters will be widget, label, buttons (a list or list-tuple of key values for buttons), toolTips (a list of toolTips for the buttons), and setChecked (a list of keys to check from the buttons)"""
        if toolTips and len(toolTips) != len(buttons):
            raise RuntimeError(_("Number of buttons and toolTips must be equal"))

        QWidget.__init__(self, widget)
        widgetState.__init__(self, widget, label, **kwargs)

        self.controlArea.layout().addWidget(self)

        if displayLabel:
            self.box = groupBox(self.controlArea, label=label, orientation=orientation)
            # self.layout().addWidget(self.box)
        else:
            self.box = widgetBox(self.controlArea, orientation=orientation)

        self.controlArea.layout().setAlignment(Qt.AlignTop | Qt.AlignLeft)
        self.box.setSizePolicy(QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred))

        # if orientation=='vertical':
        # self.box.setSizePolicy(QSizePolicy(QSizePolicy.Preferred,
        # QSizePolicy.MinimumExpanding))
        # else:
        # self.box.setSizePolicy(QSizePolicy(QSizePolicy.MinimumExpanding,
        # QSizePolicy.Preferred))

        self.label = label
        self.items = OrderedDict()
        self.buttons = QButtonGroup(self.box)
        self.buttons.setExclusive(False)
        if buttons:
            self.addButtons(buttons)

        if callback:
            QObject.connect(self.buttons, SIGNAL("buttonClicked(int)"), callback)
        if setChecked:
            self.setChecked(setChecked)

    def addButtons(self, buttons):
        """Internal function to add buttons.  Can be called by end developer but should be extensively tested to ensure the desired functionality"""
        if type(buttons) in [dict, OrderedDict]:
            for k, v in buttons.items():
                self.addButton(k, v)
        elif type(buttons) in [list]:
            if len(buttons) > 0 and type(buttons[0]) is tuple:
                for k, v in buttons:
                    self.addButton(k, v)
            else:
                for v in buttons:
                    self.addButton(v, v)

            # redRLog.log(redRLog.REDRCORE,redRLog.DEBUG,_('In radioButtons should not use list'))
        else:
            raise Exception(_("In radioButtons, addButtons takes a list, dict or OrderedDict"))

    def addButton(self, id, text, toolTip=None):
        """Internal function called by addButtons"""
        self.items[id] = text
        w = QCheckBox(text)
        if toolTip:
            w.setToolTip(toolTip)
        self.buttons.addButton(w, self.items.keys().index(id))
        self.box.layout().addWidget(w)

    def setSizePolicy(self, h, w):
        # self.controlArea.setSizePolicy(h,w)
        # QWidget.setSizePolicy(self,h,w)
        self.box.setSizePolicy(h, w)

    def setChecked(self, ids, logical=True):
        """Sets the keys listed in ids to checked"""
        for i in self.buttons.buttons():
            id = self.buttons.id(i)
            if unicode(self.items.keys()[id]) in ids:
                i.setChecked(logical)
            else:
                i.setChecked(not logical)

    def checkAll(self):
        """Checks all of the buttons"""
        for i in self.buttons.buttons():
            i.setChecked(True)

    def uncheckAll(self):
        """Unchecks all of the buttons"""
        for i in self.buttons.buttons():
            i.setChecked(False)

    def clear(self):
        """Removes all buttons from the widget.  Should be called before an end developer calls addButtons"""
        self.items = {}
        for i in self.buttons.buttons():
            self.buttons.removeButton(i)

    def getChecked(self):
        """Returns a list of checked button's labels"""
        return self.getCheckedItems().values()

    def getCheckedIds(self):
        """Returns a list of checked button's IDs"""
        return self.getCheckedItems().keys()

    def getCheckedItems(self):
        """Returns a dict of checked keys and labels"""
        checked = {}
        for i in self.buttons.buttons():
            id = self.buttons.id(i)
            if i.isChecked():
                checked[self.items.keys()[id]] = self.items[self.items.keys()[id]]
        return checked

    def getUncheckedItems(self):
        """Returns a dict of unchecked keys and labels"""
        checked = {}
        for i in self.buttons.buttons():
            id = self.buttons.id(i)
            if not i.isChecked():
                checked[self.items.keys()[id]] = self.items[self.items.keys()[id]]
        return checked

    def getUnchecked(self):
        """Same as getChecked but reversed"""
        return self.getUncheckedItems.values()

    def getUncheckedIds(self):
        """Same as getCheckedIds but reversed"""
        return self.getUncheckedItems.keys()

    def buttonAt(self, ind):
        """Returns the button at a given index"""
        return unicode(self.buttons.button(ind).text())

    def getSettings(self):
        """Called by :mod:`widgetSettings` to get settings"""
        # print _('radioButtons getSettings') + self.getChecked()
        r = {"items": self.items, "checked": self.getCheckedIds()}
        return r

    def loadSettings(self, data):
        """Called by :mod:`widgetSettings` to set settings"""
        # print _('radioButtons loadSettings') + data
        # self.addButtons(data['items'])
        self.setChecked(data["checked"])

    def getReportText(self, fileDir):
        """Returns report text for report generator"""
        selected = self.getChecked()

        if len(selected):
            text = "Checked: " + ", ".join(selected)
        else:
            text = _("Nothing Checked")
        r = {self.widgetName: {"includeInReports": self.includeInReports, "text": text}}
        return r
Beispiel #23
0
 def clear(self):
     """Removes all items from the comboBox"""
     QComboBox.clear(self)
     self.items = OrderedDict()
Beispiel #24
0
class comboBox(QComboBox, widgetState):
    def __init__(
        self,
        widget,
        label=None,
        displayLabel=True,
        items=None,
        editable=False,
        orientation="horizontal",
        callback=None,
        **kwargs
    ):
        kwargs.setdefault("includeInReports", True)
        kwargs.setdefault("sizePolicy", QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred))
        widgetState.__init__(self, widget, label, **kwargs)
        QComboBox.__init__(self, self.controlArea)

        if displayLabel:
            self.hb = widgetBox(self.controlArea, orientation=orientation)
            lb = widgetLabel(self.hb, label)
            self.hb.layout().addWidget(self)
            self.hasLabel = True
            self.hb.layout().setAlignment(lb, Qt.AlignRight)
            lb.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        else:
            self.controlArea.layout().addWidget(self)
            self.hasLabel = False
        self.label = label

        self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred)

        self.items = OrderedDict()
        self.setEditable(editable)

        if items:
            self.addItems(items)

        if callback:
            QObject.connect(self, SIGNAL("activated(int)"), callback)

    def getSettings(self):
        """Standard getSettings"""
        r = {"items": self.items, "current": self.currentIndex()}
        return r

    def loadSettings(self, data):
        """Standard loadSettings"""
        # print _('in comboBox load')
        # print data

        self.update(data.get("items", []))
        if data.get("current", None) != None:
            self.setCurrentIndex(data["current"])

    def currentId(self):
        """Returns the current ID"""
        try:
            return self.items.keys()[self.currentIndex()]
        except:
            return None

    def currentItem(self):
        """Returns the current key value pair"""
        return {self.items.keys()[self.currentIndex()]: self.items.values()[self.currentIndex()]}

    def setCurrentId(self, id):
        """Sets the current ID, the ID's value will apear in the comboBox"""
        try:
            self.setCurrentIndex(self.items.keys().index(id))
        except:
            pass

    def addItems(self, items):
        """Adds items to the comboBox, new items will appear after old ones"""
        if type(items) in [dict, OrderedDict]:
            for k, v in items.items():
                self.addItem(k, v)
        elif type(items) in [list]:
            if len(items) > 0 and type(items[0]) is tuple:
                for k, v in items:
                    self.addItem(k, v)
            else:
                for v in items:
                    self.addItem(v, v)
            # redRLog.log(redRLog.REDRCORE,redRLog.DEBUG,_('In listBox should not use list'))
        else:
            raise Exception(_("In comboBox, addItems takes a list, dict or OrderedDict"))

    def update(self, items):
        """Clears the comboBox and adds new items, sets the current ID to the previously selected ID if found in the items"""
        current = self.currentId()
        self.clear()
        self.addItems(items)
        self.setCurrentId(current)

    def clear(self):
        """Removes all items from the comboBox"""
        QComboBox.clear(self)
        self.items = OrderedDict()

    def addItem(self, id, item):
        """Adds a single item"""
        QComboBox.addItem(self, item)
        self.items[id] = item

    def getReportText(self, fileDir):
        """Standard getReportText"""
        r = {self.widgetName: {"includeInReports": self.includeInReports, "text": self.currentText()}}
        # return '%s set to %s' % (self.label, self.currentText())
        return r
Beispiel #25
0
 def clear(self):
     """Clears the list"""
     QListWidget.clear(self)
     self.listItems = OrderedDict()
SANS1878 = OrderedDict()
SANS1878[
    "sans1878_DatasetTitle"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString/text()"
SANS1878[
    "sans1878_DatasetReferenceDate"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date/gmd:date/gco:DateTime/text()"
SANS1878[
    "sans1878_DatasetResponsibleParty"
] = "//gmd:contact/gmd:CI_ResponsibleParty/gmd:individualName/gco:CharacterString/text()"
SANS1878[
    "sans1878_DatasetResponsiblePartyOrganization"
] = "//gmd:contact/gmd:CI_ResponsibleParty/gmd:organisationName/gco:CharacterString/text()"
SANS1878[
    "sans1878_DatasetResponsiblePartyPosition"
] = "//gmd:contact/gmd:CI_ResponsibleParty/gmd:positionName/gco:CharacterString/text()"
SANS1878["sans1878_DatasetLanguage"] = "//gmd:language/gco:CharacterString/text()"
SANS1878["sans1878_DatasetCharacterSet"] = "//gmd:characterSet/gmd:MD_CharacterSetCode/@codeListValue"
SANS1878[
    "sans1878_DatasetTopicCategory"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:topicCategory/gmd:MD_TopicCategoryCode/text()"
SANS1878[
    "sans1878_DatasetScale"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:spatialResolution/gmd:MD_Resolution/gmd:equivalentScale/gmd:MD_RepresentativeFraction/gmd:denominator/gco:Integer/text()"
SANS1878[
    "sans1878_DatasetAbstract"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:abstract/gco:CharacterString/text()"
SANS1878[
    "sans1878_DatasetFormatName"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:resourceFormat/gmd:MD_Format/gmd:name/gco:CharacterString/text()"
SANS1878[
    "sans1878_DatasetFormatVersion"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:resourceFormat/gmd:MD_Format/gmd:version/gco:CharacterString/text()"

SANS1878[
    "sans1878_SpatialWest"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:westBoundLongitude/gco:Decimal/text()"
SANS1878[
    "sans1878_SpatialSouth"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:southBoundLatitude/gco:Decimal/text()"
SANS1878[
    "sans1878_SpatialEast"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:eastBoundLongitude/gco:Decimal/text()"
SANS1878[
    "sans1878_SpatialNorth"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:northBoundLatitude/gco:Decimal/text()"
SANS1878[
    "sans1878_SpatialBeginDate"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition/text()"
SANS1878[
    "sans1878_SpatialEndDate"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:endPosition/text()"
SANS1878[
    "sans1878_SpatialVerticalExtentMinimum"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:verticalElement/gmd:EX_VerticalExtent/gmd:minimumValue/gco:Real/text()"
SANS1878[
    "sans1878_SpatialMaximum"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:verticalElement/gmd:EX_VerticalExtent/gmd:maximumValue/gco:Real/text()"
SANS1878[
    "sans1878_SpatialVerticalExtentUnits"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:verticalElement/gmd:EX_VerticalExtent/gmd:verticalCRS/gml:VerticalCRS/gml:verticalCS/gml:VerticalCS/gml:axis/gml:CoordinateSystemAxis/@gml:uom"
SANS1878[
    "sans1878_SpatialVerticalExtentDatum"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:verticalElement/gmd:EX_VerticalExtent/gmd:verticalCRS/gml:VerticalCRS/gml:verticalDatum/gml:VerticalDatum/gml:identifier/text()"
SANS1878[
    "sans1878_SpatialRepresentation"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:spatialRepresentationType/gmd:MD_SpatialRepresentationTypeCode/@codeListValue"
SANS1878[
    "sans1878_SpatialReferenceSystem"
] = "//gmd:referenceSystemInfo/gmd:MD_ReferenceSystem /gmd:referenceSystemIdentifier/gmd:RS_Identifier/gmd:code/gco:CharacterString/text()"
SANS1878[
    "sans1878_SpatialLinageStatement"
] = "//gmd:dataQualityInfo/gmd:DQ_DataQuality/gmd:lineage/gmd:LI_Lineage/gmd:statement/gco:CharacterString/text()"
SANS1878[
    "sans1878_SpatialOnlineResourceURL"
] = "//gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine/gmd:CI_OnlineResource/gmd:linkage/gmd:URL/text()"
SANS1878[
    "sans1878_SpatialOnlineResourceProtocol"
] = "//gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine/gmd:CI_OnlineResource/gmd:protocol/gco:CharacterString/text()"
SANS1878[
    "sans1878_SpatialOnlineResourceName"
] = "//gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine/gmd:CI_OnlineResource/gmd:name/gco:CharacterString/text()"
SANS1878[
    "sans1878_SpatialOnlineResourceDescription"
] = "//gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine/gmd:CI_OnlineResource/gmd:description/gco:CharacterString/text()"

SANS1878["sans1878_MetadataFileIdentifier"] = "//gmd:fileIdentifier/gco:CharacterString/text()"
SANS1878["sans1878_MetadataStandardName"] = "//gmd:metadataStandardName/gco:CharacterString/text()"
SANS1878["sans1878_MetadataStandardVersion"] = "//gmd:metadataStandardVersion/gco:CharacterString/text()"
SANS1878[
    "sans1878_MetadataLanguage"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:language/gco:CharacterString/text()"
SANS1878[
    "sans1878_MetadataCharacterSet"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:characterSet/gmd:MD_CharacterSetCode/@codeListValue"
SANS1878["sans1878_MetadataTimeStamp"] = "//gmd:dateStamp/gco:DateTime/text()"
SANS1878[
    "sans1878_MetadataPointOfContactIndividualName"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact/gmd:CI_ResponsibleParty/gmd:individualName/gco:CharacterString/text()"
SANS1878[
    "sans1878_MetadataPointOfContactOrganizationName"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact/gmd:CI_ResponsibleParty/gmd:organisationName/gco:CharacterString/text()"
SANS1878[
    "sans1878_MetadataPointOfContactPositionName"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact/gmd:CI_ResponsibleParty/gmd:positionName/gco:CharacterString/text()"
SANS1878[
    "sans1878_MetadataPointOfContactRole"
] = "//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact/gmd:CI_ResponsibleParty/gmd:role/gmd:CI_RoleCode/@codeListValue"


ISO19115 = OrderedDict()
ISO19115p2 = OrderedDict()
ISO19139 = OrderedDict()

# generate iso xpath dicts from sans dict
for k in SANS1878.keys():
Beispiel #27
0
class Project(tmt.EclipseProject):
    def __init__(self, *args, **kwargs):
        tmt.EclipseProject.__init__(self, *args, **kwargs)
        tmt.WinstoneServer = self
        self.main = "net.gnehzr.tnoodle.server.TNoodleServer"
        self.argv = ["--nobrowser", "--consoleLevel=INFO"]

        # Winstone does all of these things =(.
        self.ignoredWarnings += ["unchecked"]
        self.ignoredWarnings += ["deprecation"]
        self.ignoredWarnings += ["serial"]
        self.ignoredWarnings += ["dep-ann"]
        self.ignoredWarnings += ["rawtypes"]

        # It is important that when we iterate through the plugins
        # in topological sorted order. This way if B uses A, B can clobber
        # A's settings.
        self.plugins = OrderedDict()

    def configure(self):
        tmt.EclipseProject.configure(self)

        self.nonJavaResourceDeps |= tmt.glob(self.srcResource, ".*$", relativeTo=self.srcResource)
        for f in xmlFileTypes:
            self.nonJavaResourceDeps -= tmt.glob(self.srcResource, "%s$" % f, relativeTo=self.srcResource)

        self.nonJavaSrcDeps |= tmt.glob(self.src, ".*\\.properties$", relativeTo=self.src)
        self.nonJavaSrcDeps |= tmt.glob(self.src, ".*\\.xsd$", relativeTo=self.src)
        self.nonJavaSrcDeps |= tmt.glob(self.src, ".*\\.dtd$", relativeTo=self.src)

    def addPlugin(self, project, needsDb=False):
        project.main = self.main
        project.argv = self.argv

        self.plugins[project.name] = project
        project.needsDb = needsDb

        notDotfile = lambda dirname: not dirname.startswith(".")

        def wrapCompile(ogCompile):
            def newCompile(self):
                if ogCompile(self):
                    assert self.webContent
                    for dirpath, dirnames, filenames in os.walk(self.webContent):
                        dirnames[:] = filter(notDotfile, dirnames)  # Note that we're modifying dirnames in place

                        if "WEB-INF" in dirnames:
                            dirnames.remove("WEB-INF")
                        for filename in filter(notDotfile, filenames):
                            path = os.path.normpath(os.path.join(dirpath, filename))
                            pathRelToWebContent = relpath(path, self.webContent)
                            name = join(tmt.WinstoneServer.binResource, "webapps", "ROOT", pathRelToWebContent)
                            linkParent = os.path.dirname(name)
                            if not os.path.exists(linkParent):
                                os.makedirs(linkParent)
                            else:
                                assert os.path.isdir(linkParent)
                            tmt.createSymlinkIfNotExistsOrStale(relpath(path, linkParent), name)
                    tmt.WinstoneServer.mungeXmlFiles(topLevelWebProject=self)

            return newCompile

        project.__class__.compile = wrapCompile(project.__class__.compile)

        def webContentDist(self):
            # We just compiled ourself, which caused a recompile
            # of winstone server, so there's no need to recompile it.
            # In fact, recompiling it would be bad, as it would nuke
            # our carefully constructed tnoodle_resources.
            tmt.WinstoneServer.dist(noRemake=True)
            tmt.WinstoneServer.distJarFile()
            shutil.copy(tmt.WinstoneServer.distJarFile(), self.distJarFile())

        project.__class__.webContentDist = webContentDist

    def getWebappDir(self):
        webappsDir = join(self.binResource, "webapps")
        webappDir = join(webappsDir, "ROOT")
        return webappDir

    def compile(self):
        if tmt.EclipseProject.compile(self):
            if tmt.TmtProject.projects[tmt.args.project] == self:
                # No wrapped compile to call this for us
                self.mungeXmlFiles(topLevelWebProject=self)

            webappDir = self.getWebappDir()
            webappWebInfDir = join(webappDir, "WEB-INF")
            libDir = join(webappWebInfDir, "lib")
            if not os.path.exists(libDir):
                os.makedirs(libDir)
            classesDir = join(webappWebInfDir, "classes")
            if not os.path.exists(classesDir):
                os.makedirs(classesDir)

    def mungeXmlFiles(self, topLevelWebProject):
        for f in xmlFileTypes:
            deps = topLevelWebProject.getRecursiveDependenciesTopoSorted()

            webappDir = self.getWebappDir()
            webappWebInfDir = join(webappDir, "WEB-INF")
            if not os.path.isdir(webappWebInfDir):
                os.makedirs(webappWebInfDir)

            srcWebInfDir = join(self.srcResource, "webapps", "ROOT", "WEB-INF")
            xmlRoot = ET.parse(join(srcWebInfDir, f)).getroot()

            if self.needsDb():
                h2ConsoleServlet = """<?xml version="1.0" encoding="UTF-8"?>
<junk>
	<!-- H2 web console -->
	<servlet>
		<servlet-name>H2Console</servlet-name>
		<servlet-class>org.h2.server.web.WebServlet</servlet-class>
		<init-param>
			<param-name>properties</param-name>
			<param-value>null</param-value>
		</init-param>
		<!--
		<init-param>
			<param-name>webAllowOthers</param-name>
			<param-value></param-value>
		</init-param>
		<init-param>
			<param-name>trace</param-name>
			<param-value></param-value>
		</init-param>
		-->
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet>
		<servlet-name>InitializeH2Console</servlet-name>
		<servlet-class>net.gnehzr.tnoodle.server.InitializeH2Console</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>H2Console</servlet-name>
		<url-pattern>/h2/*</url-pattern>
	</servlet-mapping>
</junk>
"""
                root = ET.fromstring(h2ConsoleServlet)
                for child in reversed(root):
                    xmlRoot.insert(0, child)

            for project in deps:
                if project in self.plugins.values():
                    assert project.webContent
                    pluginXmlFile = join(project.webContent, "WEB-INF", f)
                    if not os.path.exists(pluginXmlFile):
                        continue
                    tree = ET.parse(pluginXmlFile)
                    root = tree.getroot()
                    for child in reversed(root):
                        xmlRoot.insert(0, child)

            xmlFile = join(webappWebInfDir, f)
            xmlFileOut = open(xmlFile, "w")

            ET.register_namespace("", "http://java.sun.com/xml/ns/javaee")

            xmlFileOut.write(ET.tostring(xmlRoot))
            xmlFileOut.close()

    def needsDb(self):
        if getattr(tmt.args, "project", None) is None:
            # None may not yet be a key in tmt.TmtProject.projects,
            # we just hack around this by unconditionally returning True here.
            return True
        webProject = tmt.TmtProject.projects[tmt.args.project]
        if webProject == self:
            return True
        deps = webProject.getRecursiveDependenciesTopoSorted(exclude=set([self]))

        for project in deps:
            if project in self.plugins.values():
                if project.needsDb:
                    return True

        return False

    def getJars(self, includeCompileTimeOnlyDependencies=False):
        jars = tmt.EclipseProject.getJars(self, includeCompileTimeOnlyDependencies=includeCompileTimeOnlyDependencies)
        if self.needsDb():
            jars.append(tmt.TmtProject.projects["h2-1.3.169.jar"])

        return jars

    def tweakJarFile(self, jar):
        # We don't necessarily want all the plugins in self.plugins to load here,
        # we only want the ones that the project we're currently building somehow
        # depends on.
        webProject = tmt.TmtProject.projects[tmt.args.project]

        # Out jar file already contains everything needed to start up winstone.
        # All the contents of tnoodle_resources are there too (including webroot).
        # The problem is that even after compiling, webroot/WEB-INF/lib/ and
        # webroot/WEB-INF/classes/ are still unpopulated, so simply jarring it up
        # isn't good enough. Here we populate classes/ and lib/. To do so, we need
        # all of the things that webProject depends on, EXCEPT for winstone (ourself).
        deps = webProject.getRecursiveDependenciesTopoSorted(exclude=set([self]))

        webInf = join("tnoodle_resources", "webapps", "ROOT", "WEB-INF")
        libDir = join(webInf, "lib")
        classesDir = join(webInf, "classes")
        for project in deps:
            assert project is not self
            if hasattr(project, "jarFile"):
                arcPath = join(libDir, basename(project.jarFile))
                jar.write(project.jarFile, arcPath)
            elif isinstance(project, tmt.EclipseProject):
                for dirpath, dirnames, filenames in os.walk(project.bin, followlinks=True):
                    for name in filenames:
                        if dirpath.startswith(join(project.bin, "tnoodle_resources")):
                            destDir = ""
                        else:
                            destDir = classesDir
                        path = join(dirpath, name)
                        prefixLen = len(project.bin)
                        if project.bin.endswith("/"):
                            prefixLen += 1
                        arcPath = join(destDir, path[prefixLen + 1 :])
                        jar.write(path, arcPath)
Beispiel #28
0
    def connect(self, nodeName, cxn):
        print "Connect: %s" % nodeName
        self.cxn = cxn
        self.ctxt = self.cxn.context()
        self.nodeName = nodeName

        # state variables of this object
        self.status = "Missing Devices"
        self.setCurrent = Value(NaN, "A")
        self.voltageLimit = VOLTAGE_LIMIT_DEFAULT
        self.temperatureOverride = False  # if True, ignore temperature checks
        self.sensingMode = True

        # devices we must link to
        self.devs = OrderedDict()
        self.devs[POWER] = {
            "server": None,
            "values": [NaN] * len(POWER_SETTINGS),
            "status": "not initialized",
            "settings": POWER_SETTINGS,
            "extras": ["output"],
        }
        self.devs[DMM] = {
            "server": None,
            "values": [NaN] * len(DMM_SETTINGS),
            "status": "not initialized",
            "settings": DMM_SETTINGS,
            "gpib address": 24,
            "init funcs": ["configure_voltage"],
        }
        self.devs[DC] = {
            "server": None,
            "values": [NaN] * len(DC_SETTINGS),
            "status": "not initialized",
            "settings": DC_SETTINGS,
            "extras": ["output", "persistent_switch_mode", "persistent_switch_time_elapsed"],
        }
        self.devs[TEMPERATURE] = {
            "server": None,
            "values": [NaN] * len(TEMPERATURE_SETTINGS),
            "status": "not initialized",
            "settings": TEMPERATURE_SETTINGS,
            "flatten": True,
            "pickOneValue": 1,
        }
        self.devs[DMM2] = {
            "server": None,
            "values": [NaN] * len(DMM2_SETTINGS),
            "status": "not initialized",
            "settings": DMM2_SETTINGS,
            "gpib address": 27,
        }

        # Persistent Switch
        self.psHeated = None  # T/F for switch heated or not
        self.psCurrent = NaN * A  # current when switch was cooled/closed
        self.psTime = 0  # time since switch state was last changed
        self.psRequestedState = None  # None=leave as is, T = heated, F = cooled
        self.psStatus = "Not started"

        # DV logging stuff
        self.dv = None
        self.dvName = None
        self.dvRecordDelay = 5  # record every X seconds
        self.dvLastTimeRecorded = 0
        self.dvStatus = "Not started"

        # the main loop stuff
        self.timeInterval = 0.2
        self.loop = LoopingCall(self.mainLoop)
        self.loopDone = self.loop.start(self.timeInterval, now=True)
        print "loop started"
def getMergedStandards():
    """
    @summary: returns a dictionary containing all listed standards
    """
    all = OrderedDict()
    all.update(SANS1878)
    all.update(EML)
    all.update(DublinCore)
    all.update(ISO19115)
    all.update(ISO19115p2)
    all.update(ISO19139)
    all.update(SANS1878)
    all.update(COMMON)
    return all
Beispiel #30
0
class taskdef(object):
    def __init__(self, name, rtdefs, rtover, run_mode):
        if re.search("[^0-9a-zA-Z_\.]", name):
            # dot for namespace syntax (NOT USED).
            # regex [\w] allows spaces.
            raise DefinitionError, "ERROR: Illegal task name: " + name

        rtcfg = {}
        replicate(rtcfg, rtdefs.odict())  # copy [runtime] default dict
        override(rtcfg, rtover)  # override with suite [runtime] settings

        self.run_mode = run_mode
        self.rtconfig = rtcfg

        # some defaults
        self.intercycle = False
        self.cycling = False
        self.asyncid_pattern = None
        self.modifiers = []
        self.is_coldstart = False
        self.cyclers = []

        self.follow_on_task = None
        self.clocktriggered_offset = None
        self.namespace_hierarchy = []
        # triggers[0,6] = [ A, B:1, C(T-6), ... ]
        self.triggers = OrderedDict()
        # cond[6,18] = [ '(A & B)|C', 'C | D | E', ... ]
        self.cond_triggers = OrderedDict()
        self.outputs = []  # list of explicit internal outputs; change to
        # OrderedDict() if need to vary per cycle.
        self.loose_prerequisites = []  # asynchronous tasks

        self.name = name
        self.type = "free"

    def add_trigger(self, trigger, cycler):
        if cycler not in self.triggers:
            self.triggers[cycler] = []
        self.triggers[cycler].append(trigger)

    def add_conditional_trigger(self, triggers, exp, cycler):
        if cycler not in self.cond_triggers:
            self.cond_triggers[cycler] = []
        self.cond_triggers[cycler].append([triggers, exp])

    def add_to_valid_cycles(self, cyclr):
        if len(self.cyclers) == 0:
            self.cyclers = [cyclr]
        else:
            self.cyclers.append(cyclr)

    def time_trans(self, strng, hours=False):
        # Time unit translation.
        # THIS IS NOT CURRENTLY USED, but may be useful in the future.
        # translate a time of the form:
        #  x sec, y min, z hr
        # into float MINUTES or HOURS,

        if (
            not re.search("^\s*(.*)\s*min\s*$", strng)
            and not re.search("^\s*(.*)\s*sec\s*$", strng)
            and not re.search("^\s*(.*)\s*hr\s*$", strng)
        ):
            print >>sys.stderr, "ERROR: missing time unit on " + strng
            sys.exit(1)

        m = re.search("^\s*(.*)\s*min\s*$", strng)
        if m:
            [mins] = m.groups()
            if hours:
                return str(float(mins / 60.0))
            else:
                return str(float(mins))

        m = re.search("^\s*(.*)\s*sec\s*$", strng)
        if m:
            [secs] = m.groups()
            if hours:
                return str(float(secs) / 3600.0)
            else:
                return str(float(secs) / 60.0)

        m = re.search("^\s*(.*)\s*hr\s*$", strng)
        if m:
            [hrs] = m.groups()
            if hours:
                return float(hrs)
            else:
                return float(hrs) * 60.0

    def get_task_class(self):
        # return a task proxy class definition, to be used for
        # instantiating objects of this particular task class.
        base_types = []
        for foo in self.modifiers + [self.type]:
            # __import__() keyword args were introduced in Python 2.5
            # mod = __import__( 'cylc.task_types.' + foo, fromlist=[foo] )
            mod = __import__("cylc.task_types." + foo, globals(), locals(), [foo])
            base_types.append(getattr(mod, foo))

        tclass = type(self.name, tuple(base_types), dict())

        # set class variables here
        tclass.title = self.rtconfig["title"]
        tclass.description = self.rtconfig["description"]

        # For any instance-specific environment variables (note that
        # [runtime][TASK][enviroment] is now held in a class variable).
        tclass.env_vars = OrderedDict()

        tclass.name = self.name  # TO DO: NOT NEEDED, USED class.__name__
        tclass.instance_count = 0
        tclass.upward_instance_count = 0

        tclass.rtconfig = self.rtconfig
        tclass.run_mode = self.run_mode

        tclass.elapsed_times = []
        tclass.mean_total_elapsed_time = None

        tclass.intercycle = self.intercycle
        tclass.follow_on = self.follow_on_task

        tclass.namespace_hierarchy = self.namespace_hierarchy

        def tclass_add_prerequisites(sself, startup, cycler, tag):

            # NOTE: Task objects hold all triggers defined for the task
            # in all cycling graph sections in this data structure:
            #     self.triggers[cycler] = [list of triggers for this cycler]
            # The list of triggers associated with cyclerX will only be
            # used by a particular task if the task's cycle time is a
            # valid member of cyclerX's sequence of cycle times.

            # 1) non-conditional triggers
            pp = plain_prerequisites(sself.id)
            sp = plain_prerequisites(sself.id)
            lp = loose_prerequisites(sself.id)
            for cyc in self.triggers:
                for trig in self.triggers[cyc]:
                    if trig.startup and not startup:
                        continue
                    if trig.cycling and not cyc.valid(ct(sself.tag)):
                        # This trigger is not used in current cycle.
                        # (see NOTE just above)
                        ##DEBUGGING:
                        ##print >> sys.stderr, sself.name + ': this trigger not used for', sself.tag + ':'
                        ##print >> sys.stderr, ' ', trig.get(sself.tag, cyc)
                        continue
                    # NOTE that if we need to check validity of async
                    # tags, async tasks can appear in cycling sections
                    # in which case cyc.valid( at(sself.tag)) will fail.
                    if trig.async_repeating:
                        lp.add(trig.get(tag, cycler))
                    else:
                        if trig.suicide:
                            sp.add(trig.get(tag, cycler))
                        else:
                            pp.add(trig.get(tag, cycler))
            sself.prerequisites.add_requisites(pp)
            sself.prerequisites.add_requisites(lp)
            sself.suicide_prerequisites.add_requisites(sp)

            # 2) conditional triggers
            for cyc in self.cond_triggers.keys():
                for ctrig, exp in self.cond_triggers[cyc]:
                    foo = ctrig.keys()[0]
                    if ctrig[foo].startup and not startup:
                        continue
                    if ctrig[foo].cycling and not cyc.valid(ct(sself.tag)):
                        # This trigger is not valid for current cycle.
                        # (see NOTE just above)
                        ##DEBUGGING:
                        ##print >> sys.stderr, sself.name + ': this trigger not used for', sself.tag + ':'
                        ##print >> sys.stderr, ' ', trig.get(sself.tag, cyc)
                        continue
                    # NOTE that if we need to check validity of async
                    # tags, async tasks can appear in cycling sections
                    # in which case cyc.valid( at(sself.tag)) will fail.
                    cp = conditional_prerequisites(sself.id)
                    for label in ctrig:
                        trig = ctrig[label]
                        cp.add(trig.get(tag, cycler), label)
                    cp.set_condition(exp)
                    if ctrig[foo].suicide:
                        sself.suicide_prerequisites.add_requisites(cp)
                    else:
                        sself.prerequisites.add_requisites(cp)

        tclass.add_prerequisites = tclass_add_prerequisites

        # class init function
        def tclass_init(sself, start_tag, initial_state, stop_c_time=None, startup=False, validate=False):

            sself.cycon = container.cycon(self.cyclers)
            if self.cycling:  # and startup:
                # adjust only needed at start-up but it does not hurt to
                # do it every time as after the first adjust we're already
                # on-cycle.
                sself.tag = sself.cycon.initial_adjust_up(start_tag)
            else:
                sself.tag = start_tag

            sself.c_time = sself.tag

            sself.id = sself.name + TaskID.DELIM + sself.tag

            sself.asyncid_pattern = self.asyncid_pattern

            if "clocktriggered" in self.modifiers:
                sself.real_time_delay = float(self.clocktriggered_offset)

            # prerequisites
            sself.prerequisites = prerequisites()
            sself.suicide_prerequisites = prerequisites()
            sself.add_prerequisites(startup, sself.cycon, sself.tag)

            sself.logfiles = logfiles()
            for lfile in self.rtconfig["extra log files"]:
                sself.logfiles.add_path(lfile)

            # outputs
            sself.outputs = outputs(sself.id)
            for outp in self.outputs:
                msg = outp.get(sself.tag)
                if not sself.outputs.exists(msg):
                    sself.outputs.add(msg)
            sself.outputs.register()

            if "catchup_clocktriggered" in self.modifiers:
                catchup_clocktriggered.__init__(sself)

            if stop_c_time:
                # cycling tasks with a final cycle time set
                super(sself.__class__, sself).__init__(initial_state, stop_c_time, validate=validate)
            else:
                # TO DO: TEMPORARY HACK FOR ASYNC
                sself.stop_c_time = "99991231230000"
                super(sself.__class__, sself).__init__(initial_state, validate=validate)

            sself.reconfigure_me = False
            sself.is_coldstart = self.is_coldstart
            sself.set_from_rtconfig()

        tclass.__init__ = tclass_init

        return tclass