def set_new_selected(self,image):
     #mudo o status do antigo canal selecionado pra false
     self.channel_master.selected = False
     #busco o novo canal que foi clicado no banco e seto as coordenadas do frame
     new_channel = Channel.get(Channel.id==int(image.id))
     new_channel.selected = True
     new_channel.x = image.x
     new_channel.y = image.y
     new_channel.width = image.width
     new_channel.height = image.height
     self.channel_master = new_channel
     self.selected_box = image.parent
Ejemplo n.º 2
0
  def testAllParamsOK(self):
    """Expect 200 OK if all params match.

    Expect hub.challenge.
    """
    challenge = "venus"
    response = self.verify()
    self.assertEqual("200 OK", response.status)
    self.assertEqual(challenge, response.body)
    # Refetch the instance from the datastore, 
    # so its attributes get updated. 
    channel = Channel.get(self.channel.key())
    self.assertEqual(channel.status, "subscribed")
Ejemplo n.º 3
0
  def testParseRecurrentAtom(self):
    """Override entity when an entry being parsed more than once

    The entry existed in the datastore should be updated, instead of
    inserted. We simply assert the counts of the entries not changed.
    """
    app = TestApp(self.application)
    atom = open("test/atom.xml", "r").read()
    doc = feedparser.parse(atom)
    key = self.channel.key()
    response = app.post(WORKER["parser"] + str(key),
             params=atom,
	     content_type="application/atom+xml")
    oldcount = Channel.get(key).entry_set.count()

    # Rework the parsing task
    response = app.post(WORKER["parser"] + str(key),
             params=atom,
	     content_type="application/atom+xml")
    newcount = Channel.get(key).entry_set.count()

    self.assertEqual(oldcount, newcount)
 def silent_channel(self,image):
     print("mutou ",image.id)
     channel = Channel.get(Channel.id==int(image.id))
     channel.active = not channel.active
     channel.save()
     if self.ser.isOpen():
         if not channel.active:
             self.sendGain(channel.pin,0)
             if channel.note == 4:
                 self.sendThreshold(channel.pin,100)
             image.source = "resources/icons/icons_no_silence.png"
         else:
             self.sendGain(channel.pin,int(self.selected.dict_controls["Gain"].value))
             if channel.note == 4:
                 self.sendThreshold(channel.pin,self.selected.dict_controls["Threshold"].value)
             image.source = "resources/icons/icons_silence.png"
Ejemplo n.º 5
0
  def testParseAtom(self):
    """Datastore should have updated if everything goes well"""
    app = TestApp(self.application)
    atom = open("test/atom.xml", "r").read()
    doc = feedparser.parse(atom)
    response = app.post(WORKER["parser"] + str(self.channel.key()),
             params=atom,
	     content_type="application/atom+xml")
    channel = Channel.get(self.channel.key())

    self.assertEqual(doc.feed.title, channel.title)
    self.assertEqual(doc.feed.id, channel.uid)
    self.assertEqual(len(doc.entries), channel.entry_set.count())

    for e in doc.entries:
      entry = channel.entry_set.filter("uid =", e.id).get()
      self.assertEqual(e.title, entry.title)
      self.assertEqual(e.id, entry.uid)
Ejemplo n.º 6
0
    def get(self):
        """Handling PuSH verification

    Response:
    2xx hub.challenge  
        We agree with the action, the token matched, the topic found.
    404  
        Disagree with the action, please don't retry.
    4xx / 5xx
        Temporary failure, please retry later.
    """
        logging.info("Upon verification: %s from %s" % (self.request.url, self.request.remote_addr))
        token = self.request.get("hub.verify_token")
        if token != HUB["token"]:
            # token not match
            self.error(404)
            logging.error("Token not match: %s from %s" % (self.request.url, self.request.remote_addr))
            return  # fail fast

        # PuSH verification will come at WORKER['subbub'] + `key`
        # path = WORKER['subbub'] + "key"
        key = self.request.path[len(WORKER["subbub"]) :]
        try:
            channel = Channel.get(key)
        except:
            logging.error("Broken key: %s from %s" % (self.request.path, self.request.remote_addr))
            self.error(404)
        else:
            if channel:
                mode = self.request.get("hub.mode")
                topic = self.request.get("hub.topic")
                if mode and topic and channel.status == mode[:-1] + "ing" and channel.topic == topic:
                    channel.status = mode + "d"
                    channel.put()
                    logging.info("Verify success: %s to %s" % (channel.status, channel.topic))
                    self.response.out.write(self.request.get("hub.challenge"))
                else:
                    logging.error("Status or topic not match: %s" % self.request.url)
                    self.error(404)
            else:
                # Topic not found
                logging.error("Channel key not found: %s" % key)
                self.error(412)
Ejemplo n.º 7
0
    def post(self):
        key = self.request.path[len(WORKER["subscriber"]) :]
        try:
            channel = Channel.get(key)
        except:
            logging.error("Broken channel key: %s" % self.request.path)
            return

        action = self.request.get("hub.mode")
        if not action:
            logging.error("hub.mode not found in payload: %s from %s" % (self.request.body, self.request.url))
            self.error(204)
        if channel:
            if action == "subscribe":
                channel.subscribe()
            else:
                channel.unsubscribe()
        else:
            logging.error("Channel key not found: %s" % self.request.path)
            self.error(204)
Ejemplo n.º 8
0
    def post(self):
        """Handle PuSH notifications

    Response:
    2xx 
        Notification received
    3xx / 4xx / 5xx
        Fail, please retry the notification later

    Atom/rss feed is queued to `ParseWorker` for later parsing
    """
        type = self.request.headers["Content-Type"]

        # Content-Type not match, respond fast
        if type not in ["application/atom+xml", "application/rss+xml"]:
            self.response.headers.__delitem__("Content-Type")
            self.error(204)
            return

        try:
            key = self.request.path[len(WORKER["subbub"]) :]
            ch = Channel.get(key)
        except (db.KindError, db.BadKeyError):
            logging.error("Broken Key at notification: %s" % self.request.url)
            self.response.headers.__delitem__("Content-Type")
            self.response.set_status(204)
        except:
            # Datastore Error, please retry notification
            self.error(500)
        else:
            body = self.request.body.decode("utf-8")
            if not (ch and body):
                if not ch:
                    logging.error("Key Not Found at notification: %s" % self.request.url)
                self.response.headers.__delitem__("Content-Type")
                self.response.set_status(204)
            else:
                taskqueue.Task(body, url=WORKER["parser"] + key, headers={"Content-Type": type}).add(queue_name="parse")
                logging.info("Upon notifications: %s from %s" % (self.request.url, self.request.remote_addr))
                self.response.set_status(202)
Ejemplo n.º 9
0
    def save_channel_in_database(self, name, type, selected_image):
        mainwindow = App.get_running_app().root

        #try:
        if Channel.select().count() > 0:
            selected_channel = Channel.get(Channel.selected == True)
            if selected_channel:
                selected_channel.selected = False
                print("tinha um canal selecionado anteriormente")

        self.gridchannels.channel_master = Channel.create(
            name=name,
            type=type,
            pin=1,
            note=38,
            threshold=10,
            scan=20,
            mask=20,
            retrigger=7,
            gain=15,
            curve=0,
            curveform=100,
            xtalk=0,
            xtalkgroup=0,
            image="resources/images/PNG/" + selected_image + ".png",
            x=0.0,
            y=0.0,
            width=0.0,
            height=0.0,
            selected=True,
            active=True)

        self.dismiss()
        self.gridchannels.list_channels = Channel.select().order_by(Channel.id)
        #adiciona canal no grid
        self.gridchannels.insert_channel_in_grid(
            self.gridchannels.channel_master)
        self.gridchannels.set_values_selected()
Ejemplo n.º 10
0
def get_channel():
    from model import Channel
    try:
        return Channel.get(Channel.username == SELF_CHANNEL_USERNAME)
    except Channel.DoesNotExist:
        return False
Ejemplo n.º 11
0
    def post(self):
        """Parsing queued feeds"""
        doc = feedparser.parse(self.request.body)

        # Bozo feed handling
        # stealed from PubSubHubbub subscriber repo
        if doc.bozo:
            logging.error("Bozo feed data. %s: %r", doc.bozo_exception.__class__.__name__, doc.bozo_exception)
            if hasattr(doc.bozo_exception, "getLineNumber") and hasattr(doc.bozo_exception, "getMessage"):
                line = doc.bozo_exception.getLineNumber()
                logging.error("Line %d: %s", line, doc.bozo_exception.getMessage())
                segment = self.request.body.split("\n")[line - 1]
                logging.info("Body segment with error: %r", segment.decode("utf-8"))
            return  # fail fast

        # WORKER['parser'] + `key`
        key = self.request.path[len(WORKER["parser"]) :]
        # Try to get the channel by key;
        # fallback to feed id, if not found;
        # and at last we'll resort to entry source id,
        # to find out the associated channel
        channel = None
        uid = doc.feed.id
        try:
            channel = Channel.get(key)
        except:
            channel = Channel.all().filter("uid =", uid).get()
        else:
            # First time get the notification,
            # so update channel's properties
            if channel and not channel.uid:
                channel.title = doc.feed.title.split(" - ")[0]
                channel.uid = uid
                # Fallback to topic feed, if no link found
                channel.link = doc.feed.get("link", channel.topic)
                channel.put()

        updates = []
        for e in doc.entries:
            author = e.author if e.get("author") else None
            content = e.content[0].value if e.get("content") else e.summary
            # Fallback to published if no updated field.
            t = e.updated_parsed if e.get("updated_parsed") else e.published_parsed
            updated = datetime(t[0], t[1], t[2], t[3], t[4], t[5])

            # If we have this entry already in datastore, then the entry
            # should be updated instead of inserted.
            ent = Entry.all().filter("uid =", e.id).get()
            if not ent:
                if not channel:
                    uid = e.source.id
                    channel = Channel.all().filter("uid =", uid).get()
                ent = Entry(
                    title=e.title,
                    link=e.link,
                    content=content,
                    author=author,
                    updated=updated,
                    uid=e.id,
                    channel=channel,
                )
                logging.info("Get new entry: %s" % e.id)
            else:
                ent.title = e.title
                ent.link = e.link
                ent.content = content
                ent.author = author
                ent.updated = updated
                logging.info("Get updated entry: %s" % e.id)

            updates.append(ent)

        db.put(updates)