Example #1
0
    def post(self, **kw):
        helper = RequestHelper(self)
        results = {}
        source_q = ArtifactSource.all()
        for s in source_q:
            artifact_q = ArtifactInfo.find_by_source(s)
            count = len([a for a in artifact_q])
            counter = Counters.source_counter(s.name)
            old_count = counter.count()
            counter.set(count)

            source_result = {'old': old_count}

            # if source is linked to a feed, I can't delete it
            feed = Feed.get_by_source(s, return_none=True)
            if feed:
                source_result['feed'] = feed.url

            if not count and not feed:
                s.delete()
                source_result['deleted'] = True

            if count:
                source_result['new'] = count

            results[s.name] = source_result
        helper.write_json(results)
Example #2
0
    def delete_by_name(cls, source_name):
        source = ArtifactSource.get_by_name(source_name)
        logging.debug("delete_by_name source: %s" % source)
        if not source:
            raise NotFoundException('ArtifactSource %s' % source_name)

        # checks for feeds linked to source
        feed = FeedAccessor.get_by_source_name(source_name, return_none=True)
        if feed:
            raise ConflictingDataException(
                "ArtifactSource '%s' is referenced by Feed '%s'" %
                (source_name, feed.url))

        # finds and deletes artifacts for source
        info_keys = ArtifactInfo.find_by_source(source, keys_only=True)
        content_keys = ArtifactContent.find_by_source(source)

        # zips keys to delete info/content pairs back-to-back
        for artifact_keys in zip(info_keys, content_keys):
            db.delete(artifact_keys)

        # deletes extras if info/content sizes don't match
        # (this would be a data bug somewhere)
        content_len = content_keys.count()
        info_len = info_keys.count()
        if content_len < info_len:
            db.delete(content_keys[info_len:])
        elif info_len > content_len:
            db.delete(info_keys[content_len:])

        # deletes source
        db.delete(source)
Example #3
0
    def post(self, **kw):
        helper = RequestHelper(self)
        results = {}
        source_q = ArtifactSource.all()
        for s in source_q:
            artifact_q = ArtifactInfo.find_by_source(s)
            count = len([a for a in artifact_q])
            counter = Counters.source_counter(s.name)
            old_count = counter.count()
            counter.set(count)
            
            source_result = { 'old': old_count }
            
            # if source is linked to a feed, I can't delete it
            feed = Feed.get_by_source(s, return_none=True)
            if feed:
                source_result['feed'] = feed.url

            if not count and not feed:
                s.delete()
                source_result['deleted'] = True
            
            if count:
                source_result['new'] = count
                
            results[s.name] = source_result
        helper.write_json(results)
Example #4
0
    def delete_by_name(cls, source_name):
        source = ArtifactSource.get_by_name(source_name)
        logging.debug("delete_by_name source: %s" % source)
        if not source:
            raise NotFoundException("ArtifactSource %s" % source_name)

        # checks for feeds linked to source
        feed = FeedAccessor.get_by_source_name(source_name, return_none=True)
        if feed:
            raise ConflictingDataException("ArtifactSource '%s' is referenced by Feed '%s'" % (source_name, feed.url))

        # finds and deletes artifacts for source
        info_keys = ArtifactInfo.find_by_source(source, keys_only=True)
        content_keys = ArtifactContent.find_by_source(source)

        # zips keys to delete info/content pairs back-to-back
        for artifact_keys in zip(info_keys, content_keys):
            db.delete(artifact_keys)

        # deletes extras if info/content sizes don't match
        # (this would be a data bug somewhere)
        content_len = content_keys.count()
        info_len = info_keys.count()
        if content_len < info_len:
            db.delete(content_keys[info_len:])
        elif info_len > content_len:
            db.delete(info_keys[content_len:])

        # deletes source
        db.delete(source)
Example #5
0
 def test_delete_by_name_deletes_source_with_no_referencing_feed(self):
     self.m.StubOutWithMock(ArtifactSource, "get_by_name")
     self.m.StubOutWithMock(FeedAccessor, "get_by_source_name")
     self.m.StubOutWithMock(ArtifactInfo, "find_by_source")
     self.m.StubOutWithMock(ArtifactContent, "find_by_source")
     self.m.StubOutWithMock(db, "delete")
     self.m.StubOutWithMock(memcache, "delete")
     
     name = "mhawthorne"
     source = MockEntity(key_name=name)
     ArtifactSource.get_by_name(name).AndReturn(source)
     FeedAccessor.get_by_source_name(name, return_none=True)
     ArtifactInfo.find_by_source(source, keys_only=True).AndReturn(MockQuery(range(0,0)))
     ArtifactContent.find_by_source(source).AndReturn(MockQuery(range(0,0)))
     db.delete(source)
     memcache.delete(IsA(str)).AndReturn(1)
     
     self.m.ReplayAll()
     ArtifactSourceAccessor.delete_by_name(name)
     self.m.VerifyAll()
Example #6
0
    def test_delete_by_name_deletes_source_with_no_referencing_feed(self):
        self.m.StubOutWithMock(ArtifactSource, "get_by_name")
        self.m.StubOutWithMock(FeedAccessor, "get_by_source_name")
        self.m.StubOutWithMock(ArtifactInfo, "find_by_source")
        self.m.StubOutWithMock(ArtifactContent, "find_by_source")
        self.m.StubOutWithMock(db, "delete")
        self.m.StubOutWithMock(memcache, "delete")

        name = "mhawthorne"
        source = MockEntity(key_name=name)
        ArtifactSource.get_by_name(name).AndReturn(source)
        FeedAccessor.get_by_source_name(name, return_none=True)
        ArtifactInfo.find_by_source(source, keys_only=True).AndReturn(
            MockQuery(range(0, 0)))
        ArtifactContent.find_by_source(source).AndReturn(MockQuery(range(0,
                                                                         0)))
        db.delete(source)
        memcache.delete(IsA(str)).AndReturn(1)

        self.m.ReplayAll()
        ArtifactSourceAccessor.delete_by_name(name)
        self.m.VerifyAll()
Example #7
0
 def count_infos(cls, source):
     return ArtifactInfo.find_by_source(source, keys_only=True).count()
Example #8
0
 def count_infos(cls, source):
     return ArtifactInfo.find_by_source(source, keys_only=True).count()