Exemplo n.º 1
0
 def delete(self, version=0):
     """ Deletes a specific version, or if none is provided
     then all versions will be deleted. If all (or just one version exists) it
     will also delete all comments and any attachments attached to the post. """
     if version:
         sql = "DELETE FROM fullblog_posts WHERE name=%s AND version=%s"
         args = (self.name, version)
     else:
         sql = "DELETE FROM fullblog_posts WHERE name=%s"
         args = (self.name,)
     if hasattr(self.env, 'db_transaction'):
         self.env.db_transaction(sql, args)
         db = None
     else:
         db = self.env.get_db_cnx()
         cursor = db.cursor()
         cursor.execute(sql, args)
         db.commit()
     if not len(self.get_versions()):
         # Delete comments
         for comment in self.get_comments():
             comment.delete()
         # Delete attachments
         if db is not None:
             Attachment.delete_all(self.env, 'blog', self.name, db)
         else:
             Attachment.delete_all(self.env, 'blog', self.name)
     return True
Exemplo n.º 2
0
    def delete(self, db=None):
        """Remove a build configuration and all dependent objects from the
        database."""
        assert self.exists, 'Cannot delete non-existing configuration'
        if not db:
            db = self.env.get_db_cnx()
            handle_ta = True
        else:
            handle_ta = False

        for platform in list(TargetPlatform.select(self.env, self.name,
                                                   db=db)):
            platform.delete(db=db)

        for build in list(Build.select(self.env, config=self.name, db=db)):
            build.delete(db=db)

        # Delete attachments
        Attachment.delete_all(self.env, 'build', self.resource.id, db)

        cursor = db.cursor()
        cursor.execute("DELETE FROM bitten_config WHERE name=%s",
                       (self.name, ))

        if handle_ta:
            db.commit()
        self._old_name = None
Exemplo n.º 3
0
 def delete(self, version=0):
     """ Deletes a specific version, or if none is provided
     then all versions will be deleted. If all (or just one version exists) it
     will also delete all comments and any attachments attached to the post. """
     if version:
         sql = "DELETE FROM fullblog_posts WHERE name=%s AND version=%s"
         args = (self.name, version)
     else:
         sql = "DELETE FROM fullblog_posts WHERE name=%s"
         args = (self.name, )
     if hasattr(self.env, 'db_transaction'):
         self.env.db_transaction(sql, args)
         db = None
     else:
         db = self.env.get_db_cnx()
         cursor = db.cursor()
         cursor.execute(sql, args)
         db.commit()
     if not len(self.get_versions()):
         # Delete comments
         for comment in self.get_comments():
             comment.delete()
         # Delete attachments
         if db is not None:
             Attachment.delete_all(self.env, 'blog', self.name, db)
         else:
             Attachment.delete_all(self.env, 'blog', self.name)
     return True
 def do_delete(db):
     cursor = db.cursor()
     Attachment.delete_all(self.env, self.resource.realm, self.resource.id, db)
     cursor.execute("""
     DELETE FROM mailinglistraw WHERE id IN
     (SELECT raw FROM mailinglistmessages WHERE id = %s)""", (self.id,))
     cursor.execute('DELETE FROM mailinglistmessages WHERE id = %s', (self.id,))
Exemplo n.º 5
0
    def test_rename_page(self):
        data = (1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0)
        self.env.db_transaction(
            "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
            ('TestPage',) + data)
        attachment = Attachment(self.env, 'wiki', 'TestPage')
        attachment.insert('foo.txt', StringIO(), 0, 1)

        page = WikiPage(self.env, 'TestPage')
        page.rename('PageRenamed')
        self.assertEqual('PageRenamed', page.name)
        self.assertEqual('PageRenamed', page.resource.id)

        self.assertEqual([data], self.env.db_query("""
            SELECT version, time, author, ipnr, text, comment, readonly
            FROM wiki WHERE name=%s
            """, ('PageRenamed',)))

        attachments = Attachment.select(self.env, 'wiki', 'PageRenamed')
        self.assertEqual('foo.txt', attachments.next().filename)
        self.assertRaises(StopIteration, attachments.next)
        Attachment.delete_all(self.env, 'wiki', 'PageRenamed')

        old_page = WikiPage(self.env, 'TestPage')
        self.assertFalse(old_page.exists)

        self.assertEqual([], self.env.db_query("""
            SELECT version, time, author, ipnr, text, comment, readonly
            FROM wiki WHERE name=%s
            """, ('TestPage',)))

        listener = TestWikiChangeListener(self.env)
        self.assertEqual((page, 'TestPage'), listener.renamed[0])
Exemplo n.º 6
0
    def delete(self, db=None):
        """Remove a build configuration and all dependent objects from the
        database."""
        assert self.exists, "Cannot delete non-existing configuration"
        if not db:
            db = self.env.get_db_cnx()
            handle_ta = True
        else:
            handle_ta = False

        for platform in list(TargetPlatform.select(self.env, self.name, db=db)):
            platform.delete(db=db)

        for build in list(Build.select(self.env, config=self.name, db=db)):
            build.delete(db=db)

        # Delete attachments
        Attachment.delete_all(self.env, "build", self.resource.id, db)

        cursor = db.cursor()
        cursor.execute("DELETE FROM bitten_config WHERE name=%s", (self.name,))

        if handle_ta:
            db.commit()
        self._old_name = None
Exemplo n.º 7
0
    def test_rename_page(self):
        cursor = self.db.cursor()
        data = (1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0)
        cursor.execute("INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
                       ('TestPage', ) + data)
        attachment = Attachment(self.env, 'wiki', 'TestPage')
        attachment.insert('foo.txt', StringIO(), 0, 1)

        page = WikiPage(self.env, 'TestPage')
        page.rename('PageRenamed')
        self.assertEqual('PageRenamed', page.name)

        cursor.execute(
            "SELECT version,time,author,ipnr,text,comment,"
            "readonly FROM wiki WHERE name=%s", ('PageRenamed', ))
        self.assertEqual(data, cursor.fetchone())
        self.assertEqual(None, cursor.fetchone())

        attachments = Attachment.select(self.env, 'wiki', 'PageRenamed')
        self.assertEqual('foo.txt', attachments.next().filename)
        self.assertRaises(StopIteration, attachments.next)
        Attachment.delete_all(self.env, 'wiki', 'PageRenamed', self.db)

        old_page = WikiPage(self.env, 'TestPage')
        self.assertEqual(False, old_page.exists)

        cursor.execute(
            "SELECT version,time,author,ipnr,text,comment,"
            "readonly FROM wiki WHERE name=%s", ('TestPage', ))
        self.assertEqual(None, cursor.fetchone())

        listener = TestWikiChangeListener(self.env)
        self.assertEqual((page, 'TestPage'), listener.renamed[0])
Exemplo n.º 8
0
    def test_rename_page(self):
        data = (1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0)
        self.env.db_transaction(
            "INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
            ('TestPage',) + data)
        attachment = Attachment(self.env, 'wiki', 'TestPage')
        attachment.insert('foo.txt', StringIO(), 0, 1)

        page = WikiPage(self.env, 'TestPage')
        page.rename('PageRenamed')
        self.assertEqual('PageRenamed', page.name)

        self.assertEqual([data], self.env.db_query("""
            SELECT version, time, author, ipnr, text, comment, readonly
            FROM wiki WHERE name=%s
            """, ('PageRenamed',)))

        attachments = Attachment.select(self.env, 'wiki', 'PageRenamed')
        self.assertEqual('foo.txt', attachments.next().filename)
        self.assertRaises(StopIteration, attachments.next)
        Attachment.delete_all(self.env, 'wiki', 'PageRenamed')

        old_page = WikiPage(self.env, 'TestPage')
        self.assertEqual(False, old_page.exists)


        self.assertEqual([], self.env.db_query("""
            SELECT version, time, author, ipnr, text, comment, readonly
            FROM wiki WHERE name=%s
            """, ('TestPage',)))

        listener = TestWikiChangeListener(self.env)
        self.assertEqual((page, 'TestPage'), listener.renamed[0])
Exemplo n.º 9
0
    def test_rename_page(self):
        cursor = self.db.cursor()
        data = (1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0)
        cursor.execute("INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
                       ('TestPage',) + data)
        attachment = Attachment(self.env, 'wiki', 'TestPage')
        attachment.insert('foo.txt', StringIO(), 0, 1)
        
        page = WikiPage(self.env, 'TestPage')
        page.rename('PageRenamed')
        self.assertEqual('PageRenamed', page.name)
        
        cursor.execute("SELECT version,time,author,ipnr,text,comment,"
                       "readonly FROM wiki WHERE name=%s", ('PageRenamed',))
        self.assertEqual(data, cursor.fetchone())
        self.assertEqual(None, cursor.fetchone())
        
        attachments = Attachment.select(self.env, 'wiki', 'PageRenamed')
        self.assertEqual('foo.txt', attachments.next().filename)
        self.assertRaises(StopIteration, attachments.next)
        Attachment.delete_all(self.env, 'wiki', 'PageRenamed', self.db)

        old_page = WikiPage(self.env, 'TestPage')
        self.assertEqual(False, old_page.exists)
        
        cursor.execute("SELECT version,time,author,ipnr,text,comment,"
                       "readonly FROM wiki WHERE name=%s", ('TestPage',))
        self.assertEqual(None, cursor.fetchone())
        
        listener = TestWikiChangeListener(self.env)
        self.assertEqual((page, 'TestPage'), listener.renamed[0])
Exemplo n.º 10
0
 def do_delete(db):
     Attachment.delete_all(self.env, 'ticket', self.id, db)
     cursor = db.cursor()
     cursor.execute("DELETE FROM ticket WHERE id=%s", (self.id,))
     cursor.execute("DELETE FROM ticket_change WHERE ticket=%s",
                    (self.id,))
     cursor.execute("DELETE FROM ticket_custom WHERE ticket=%s",
                    (self.id,))
Exemplo n.º 11
0
    def delete(self):
        """Delete the ticket.
        """
        with self.env.db_transaction as db:
            Attachment.delete_all(self.env, self.realm, self.id)
            db("DELETE FROM ticket WHERE id=%s", (self.id,))
            db("DELETE FROM ticket_change WHERE ticket=%s", (self.id,))
            db("DELETE FROM ticket_custom WHERE ticket=%s", (self.id,))

        for listener in TicketSystem(self.env).change_listeners:
            listener.ticket_deleted(self)
Exemplo n.º 12
0
    def delete(self):
        """Delete the ticket.
        """
        with self.env.db_transaction as db:
            Attachment.delete_all(self.env, self.realm, self.id)
            db("DELETE FROM ticket WHERE id=%s", (self.id, ))
            db("DELETE FROM ticket_change WHERE ticket=%s", (self.id, ))
            db("DELETE FROM ticket_custom WHERE ticket=%s", (self.id, ))

        for listener in TicketSystem(self.env).change_listeners:
            listener.ticket_deleted(self)
Exemplo n.º 13
0
    def delete(self, db=None):
        db, handle_ta = self._get_db_for_write(db)
        Attachment.delete_all(self.env, 'ticket', self.id, db)
        cursor = db.cursor()
        cursor.execute("DELETE FROM ticket WHERE id=%s", (self.id,))
        cursor.execute("DELETE FROM ticket_change WHERE ticket=%s", (self.id,))
        cursor.execute("DELETE FROM ticket_custom WHERE ticket=%s", (self.id,))

        if handle_ta:
            db.commit()

        for listener in TicketSystem(self.env).change_listeners:
            listener.ticket_deleted(self)
Exemplo n.º 14
0
    def delete(self, db=None):
        """Delete the ticket.

        :since 1.0: the `db` parameter is no longer needed and will be removed
        in version 1.1.1
        """
        with self.env.db_transaction as db:
            Attachment.delete_all(self.env, 'ticket', self.id, db)
            db("DELETE FROM ticket WHERE id=%s", (self.id, ))
            db("DELETE FROM ticket_change WHERE ticket=%s", (self.id, ))
            db("DELETE FROM ticket_custom WHERE ticket=%s", (self.id, ))

        for listener in TicketSystem(self.env).change_listeners:
            listener.ticket_deleted(self)
Exemplo n.º 15
0
    def delete(self, db=None):
        """Delete the ticket.

        :since 1.0: the `db` parameter is no longer needed and will be removed
        in version 1.1.1
        """
        with self.env.db_transaction as db:
            Attachment.delete_all(self.env, 'ticket', self.id, db)
            db("DELETE FROM ticket WHERE id=%s", (self.id,))
            db("DELETE FROM ticket_change WHERE ticket=%s", (self.id,))
            db("DELETE FROM ticket_custom WHERE ticket=%s", (self.id,))

        for listener in TicketSystem(self.env).change_listeners:
            listener.ticket_deleted(self)
 def do_delete(db):
     cursor = db.cursor()
     cursor.execute('SELECT conversation, id FROM mailinglistmessages WHERE list = %s', (self.id,))
     for row in cursor:
         Attachment.delete_all(self.env, self.resource.realm,
                               "%s/%d/%d" % (self.emailaddress, row[0], row[1]),
                               db)
     cursor.execute('DELETE FROM mailinglist WHERE id = %s', (self.id,))
     cursor.execute('DELETE FROM mailinglistconversations WHERE list = %s', (self.id,))
     cursor.execute('DELETE FROM mailinglistraw WHERE list = %s', (self.id,))
     cursor.execute('DELETE FROM mailinglistmessages WHERE list = %s', (self.id,))
     cursor.execute('DELETE FROM mailinglistusersubscription WHERE list = %s', (self.id,))
     cursor.execute('DELETE FROM mailinglistgroupsubscription WHERE list = %s', (self.id,))
     cursor.execute('DELETE FROM mailinglistuserdecline WHERE list = %s', (self.id,))
Exemplo n.º 17
0
    def remove(self, build):
        """Delete what is linked to the build."""
        print "Deleting items for build %r" % (build, )

        db = self.env.get_db_cnx()
        cursor = db.cursor()

        print "Determining associated config."
        cursor.execute("SELECT config FROM bitten_build WHERE id=%s",
                       (build, ))
        config = cursor.fetchone()[0]

        print "Collecting log files."
        filenames = self._log_files(cursor, build)

        try:
            print "Deleting bitten_log entries."
            cursor.execute("DELETE FROM bitten_log WHERE build=%s", (build, ))

            print "Deleting bitten_report_item_entries."
            cursor.execute(
                "DELETE FROM bitten_report_item WHERE report IN ("
                "SELECT bitten_report.id FROM bitten_report "
                "WHERE bitten_report.build=%s"
                ")", (build, ))

            print "Deleting bitten_report entires."
            cursor.execute("DELETE FROM bitten_report WHERE build=%s",
                           (build, ))

            print "Deleting bitten_step entries."
            cursor.execute("DELETE FROM bitten_step WHERE build=%s", (build, ))

            print "Delete bitten_build entry."
            cursor.execute("DELETE FROM bitten_build WHERE id=%s", (build, ))
        except:
            db.rollback()
            print "Build deletion failed. Database rolled back."
            raise

        print "Bitten database changes committed."
        db.commit()

        print "Removing log files."
        for filename in filenames:
            os.remove(filename)

        print "Removing attachments."
        resource = Resource('build', '%s/%s' % (config, build))
        Attachment.delete_all(self.env, 'build', resource.id, db)
Exemplo n.º 18
0
    def delete(self, db=None):
        db, handle_ta = self._get_db_for_write(db)
        Attachment.delete_all(self.env, 'ticket', self.id, db)
        cursor = db.cursor()
        cursor.execute("DELETE FROM ticket WHERE id=%s", (self.id, ))
        cursor.execute("DELETE FROM ticket_change WHERE ticket=%s",
                       (self.id, ))
        cursor.execute("DELETE FROM ticket_custom WHERE ticket=%s",
                       (self.id, ))

        if handle_ta:
            db.commit()

        for listener in TicketSystem(self.env).change_listeners:
            listener.ticket_deleted(self)
 def do_delete(db):
     # could implement the message deleting part by
     # instantiating and calling delete() on each,
     # but that sounds pretty slower.
     cursor = db.cursor()
     cursor.execute('SELECT id FROM mailinglistmessages WHERE conversation = %s', (self.id,))
     for row in cursor:
         Attachment.delete_all(self.env, self.resource.realm, "%s/%d/%d" % (self.mailinglist.emailaddress,
                                                                            self.id,
                                                                            row[0]), db)
     cursor.execute('DELETE FROM mailinglistconversations WHERE id = %s', (self.id,))
     cursor.execute("""
     DELETE FROM mailinglistraw WHERE id IN
     (SELECT raw FROM mailinglistmessages WHERE conversation = %s)""", (self.id,))
     cursor.execute('DELETE FROM mailinglistmessages WHERE conversation = %s', (self.id,))
Exemplo n.º 20
0
    def remove(self, build):
        """Delete what is linked to the build."""
        print "Deleting items for build %r" % (build,)

        db = self.env.get_db_cnx()
        cursor = db.cursor()

        print "Determining associated config."
        cursor.execute("SELECT config FROM bitten_build WHERE id=%s", (build,))
        config = cursor.fetchone()[0]

        print "Collecting log files."
        filenames = self._log_files(cursor, build)

        try:
            print "Deleting bitten_log entries."
            cursor.execute("DELETE FROM bitten_log WHERE build=%s", (build,))

            print "Deleting bitten_report_item_entries."
            cursor.execute("DELETE FROM bitten_report_item WHERE report IN ("
                "SELECT bitten_report.id FROM bitten_report "
                "WHERE bitten_report.build=%s"
                ")", (build,))

            print "Deleting bitten_report entires."
            cursor.execute("DELETE FROM bitten_report WHERE build=%s",
                (build,))

            print "Deleting bitten_step entries."
            cursor.execute("DELETE FROM bitten_step WHERE build=%s", (build,))

            print "Delete bitten_build entry."
            cursor.execute("DELETE FROM bitten_build WHERE id=%s", (build,))
        except:
            db.rollback()
            print "Build deletion failed. Database rolled back."
            raise

        print "Bitten database changes committed."
        db.commit()

        print "Removing log files."
        for filename in filenames:
            os.remove(filename)

        print "Removing attachments."
        resource = Resource('build', '%s/%s' % (config, build))
        Attachment.delete_all(self.env, 'build', resource.id, db)
Exemplo n.º 21
0
 def delete(self, version=0):
     """ Deletes a specific version, or if none is provided
     then all versions will be deleted. If all (or just one version exists) it
     will also delete all comments and any attachments attached to the post. """
     if version:
         sql = "DELETE FROM fullblog_posts WHERE name=%s AND version=%s"
         args = (self.name, version)
     else:
         sql = "DELETE FROM fullblog_posts WHERE name=%s"
         args = (self.name, )
     with self.env.db_transaction as db:
         db(sql, args)
         if not len(self.get_versions()):
             # Delete comments
             for comment in self.get_comments():
                 comment.delete()
             Attachment.delete_all(self.env, 'blog', self.name)
     return True
Exemplo n.º 22
0
    def _do_invalidate(self, req, build, db):
        self.log.info('Invalidating build %d', build.id)

        for step in BuildStep.select(self.env, build=build.id, db=db):
            step.delete(db=db)

        build.slave = None
        build.started = 0
        build.stopped = 0
        build.last_activity = 0
        build.status = Build.PENDING
        build.slave_info = {}
        build.update()

        Attachment.delete_all(self.env, 'build', build.resource.id, db)

        db.commit()

        req.redirect(req.href.build(build.config))
Exemplo n.º 23
0
    def _do_invalidate(self, req, build, db):
        self.log.info('Invalidating build %d', build.id)

        for step in BuildStep.select(self.env, build=build.id, db=db):
            step.delete(db=db)

        build.slave = None
        build.started = 0
        build.stopped = 0
        build.last_activity = 0
        build.status = Build.PENDING
        build.slave_info = {}
        build.update()

        Attachment.delete_all(self.env, 'build', build.resource.id, db)

        db.commit()

        req.redirect(req.href.build(build.config))
Exemplo n.º 24
0
    def _process_build_cancellation(self, req, config, build):
        self.log.info('Build slave %r cancelled build %d', build.slave,
                      build.id)
        build.status = Build.PENDING
        build.slave = None
        build.slave_info = {}
        build.started = 0
        db = self.env.get_db_cnx()
        for step in list(BuildStep.select(self.env, build=build.id, db=db)):
            step.delete(db=db)
        build.update(db=db)

        Attachment.delete_all(self.env, 'build', build.resource.id, db)

        db.commit()

        for listener in BuildSystem(self.env).listeners:
            listener.build_aborted(build)

        self._send_response(req, 204, '', {})
Exemplo n.º 25
0
    def _process_build_cancellation(self, req, config, build):
        self.log.info('Build slave %r cancelled build %d', build.slave,
                      build.id)
        build.status = Build.PENDING
        build.slave = None
        build.slave_info = {}
        build.started = 0
        db = self.env.get_db_cnx()
        for step in list(BuildStep.select(self.env, build=build.id, db=db)):
            step.delete(db=db)
        build.update(db=db)

        Attachment.delete_all(self.env, 'build', build.resource.id, db)

        db.commit()

        for listener in BuildSystem(self.env).listeners:
            listener.build_aborted(build)

        self._send_response(req, 204, '', {})
Exemplo n.º 26
0
    def delete(self, retarget_to=None, author=None):
        """Delete the milestone.

        :since 1.0.2: the `retarget_to` and `author` parameters are
                      deprecated and will be removed in Trac 1.3.1. Tickets
                      should be moved to another milestone by calling
                      `move_tickets` before `delete`.
        """
        with self.env.db_transaction as db:
            self.env.log.info("Deleting milestone %s", self.name)
            db("DELETE FROM milestone WHERE name=%s", (self.name,))
            Attachment.delete_all(self.env, self.realm, self.name)
            # Don't translate ticket comment (comment:40:ticket:5658)
            self.move_tickets(retarget_to, author, "Milestone deleted")
            self._old['name'] = None
            del self.cache.milestones
            TicketSystem(self.env).reset_ticket_fields()

        for listener in TicketSystem(self.env).milestone_change_listeners:
            listener.milestone_deleted(self)
Exemplo n.º 27
0
    def delete(self, retarget_to=None, author=None):
        """Delete the milestone.

        :since 1.0.2: the `retarget_to` and `author` parameters are
                      deprecated and will be removed in Trac 1.3.1. Tickets
                      should be moved to another milestone by calling
                      `move_tickets` before `delete`.
        """
        with self.env.db_transaction as db:
            self.env.log.info("Deleting milestone %s", self.name)
            db("DELETE FROM milestone WHERE name=%s", (self.name, ))
            Attachment.delete_all(self.env, self.realm, self.name)
            # Don't translate ticket comment (comment:40:ticket:5658)
            self.move_tickets(retarget_to, author, "Milestone deleted")
            self._old['name'] = None
            del self.cache.milestones
            TicketSystem(self.env).reset_ticket_fields()

        for listener in TicketSystem(self.env).milestone_change_listeners:
            listener.milestone_deleted(self)
Exemplo n.º 28
0
    def delete(self, version=None, db=None):
        """Delete one or all versions of a page.

        :since 1.0: the `db` parameter is no longer needed and will be removed
        in version 1.1.1
        """
        if not self.exists:
            raise TracError(_("Cannot delete non-existent page"))

        with self.env.db_transaction as db:
            if version is None:
                # Delete a wiki page completely
                db("DELETE FROM wiki WHERE name=%s", (self.name, ))
                self.env.log.info("Deleted page %s", self.name)
            else:
                # Delete only a specific page version
                db("DELETE FROM wiki WHERE name=%s and version=%s",
                   (self.name, version))
                self.env.log.info("Deleted version %d of page %s", version,
                                  self.name)

            if version is None or version == self.version:
                self._fetch(self.name, None)

            if not self.exists:
                # Invalidate page name cache
                del WikiSystem(self.env).pages
                # Delete orphaned attachments
                from trac.attachment import Attachment
                Attachment.delete_all(self.env, 'wiki', self.name)

        # Let change listeners know about the deletion
        if not self.exists:
            for listener in WikiSystem(self.env).change_listeners:
                listener.wiki_page_deleted(self)
            ResourceSystem(self.env).resource_deleted(self)
        else:
            for listener in WikiSystem(self.env).change_listeners:
                if hasattr(listener, 'wiki_page_version_deleted'):
                    listener.wiki_page_version_deleted(self)
            ResourceSystem(self.env).resource_version_deleted(self)
Exemplo n.º 29
0
    def delete(self, db=None):
        """Remove the build from the database."""
        assert self.exists, 'Cannot delete a non-existing build'
        if not db:
            db = self.env.get_db_cnx()
            handle_ta = True
        else:
            handle_ta = False

        for step in list(BuildStep.select(self.env, build=self.id)):
            step.delete(db=db)

        # Delete attachments
        Attachment.delete_all(self.env, 'build', self.resource.id, db)

        cursor = db.cursor()
        cursor.execute("DELETE FROM bitten_slave WHERE build=%s", (self.id, ))
        cursor.execute("DELETE FROM bitten_build WHERE id=%s", (self.id, ))

        if handle_ta:
            db.commit()
Exemplo n.º 30
0
    def delete(self, db=None):
        """Remove the build from the database."""
        assert self.exists, "Cannot delete a non-existing build"
        if not db:
            db = self.env.get_db_cnx()
            handle_ta = True
        else:
            handle_ta = False

        for step in list(BuildStep.select(self.env, build=self.id)):
            step.delete(db=db)

        # Delete attachments
        Attachment.delete_all(self.env, "build", self.resource.id, db)

        cursor = db.cursor()
        cursor.execute("DELETE FROM bitten_slave WHERE build=%s", (self.id,))
        cursor.execute("DELETE FROM bitten_build WHERE id=%s", (self.id,))

        if handle_ta:
            db.commit()
Exemplo n.º 31
0
        def do_delete(db):
            cursor = db.cursor()
            if version is None:
                # Delete a wiki page completely
                cursor.execute("DELETE FROM wiki WHERE name=%s", (self.name,))
                self.env.log.info("Deleted page %s" % self.name)
            else:
                # Delete only a specific page version
                cursor.execute("DELETE FROM wiki WHERE name=%s and version=%s", (self.name, version))
                self.env.log.info("Deleted version %d of page %s" % (version, self.name))

            if version is None or version == self.version:
                self._fetch(self.name, None, db)

            if not self.exists:
                # Invalidate page name cache
                del WikiSystem(self.env).pages
                # Delete orphaned attachments
                from trac.attachment import Attachment

                Attachment.delete_all(self.env, "wiki", self.name, db)
Exemplo n.º 32
0
    def delete(self, version=None, db=None):
        """Delete one or all versions of a page.

        :since 1.0: the `db` parameter is no longer needed and will be removed
        in version 1.1.1
        """
        assert self.exists, "Cannot delete non-existent page"

        with self.env.db_transaction as db:
            if version is None:
                # Delete a wiki page completely
                db("DELETE FROM wiki WHERE name=%s", (self.name,))
                self.env.log.info("Deleted page %s", self.name)
            else:
                # Delete only a specific page version
                db("DELETE FROM wiki WHERE name=%s and version=%s",
                   (self.name, version))
                self.env.log.info("Deleted version %d of page %s", version,
                                  self.name)

            if version is None or version == self.version:
                self._fetch(self.name, None)

            if not self.exists:
                # Invalidate page name cache
                del WikiSystem(self.env).pages
                # Delete orphaned attachments
                from trac.attachment import Attachment
                Attachment.delete_all(self.env, 'wiki', self.name)

        # Let change listeners know about the deletion
        if not self.exists:
            for listener in WikiSystem(self.env).change_listeners:
                listener.wiki_page_deleted(self)
            ResourceSystem(self.env).resource_deleted(self)
        else:
            for listener in WikiSystem(self.env).change_listeners:
                if hasattr(listener, 'wiki_page_version_deleted'):
                    listener.wiki_page_version_deleted(self)
            ResourceSystem(self.env).resource_version_deleted(self)
Exemplo n.º 33
0
    def delete(self, version=None, db=None):
        assert self.exists, u'Impossible de supprimer une page inexistante'
        if not db:
            db = self.env.get_db_cnx()
            handle_ta = True
        else:
            handle_ta = False

        page_deleted = False
        cursor = db.cursor()
        if version is None:
            # Delete a wiki page completely
            cursor.execute("DELETE FROM wiki WHERE name=%s", (self.name,))
            self.env.log.info('Deleted page %s' % self.name)
        else:
            # Delete only a specific page version
            cursor.execute("DELETE FROM wiki WHERE name=%s and version=%s",
                           (self.name, version))
            self.env.log.info('Deleted version %d of page %s'
                              % (version, self.name))

        if version is None or version == self.version:
            self._fetch(self.name, None, db)

        if not self.exists:
            from trac.attachment import Attachment
            # Delete orphaned attachments
            Attachment.delete_all(self.env, 'wiki', self.name, db)

        if handle_ta:
            db.commit()

        # Let change listeners know about the deletion
        if not self.exists:
            for listener in WikiSystem(self.env).change_listeners:
                listener.wiki_page_deleted(self)
        else:
            for listener in WikiSystem(self.env).change_listeners:
                if hasattr(listener, 'wiki_page_version_deleted'):
                    listener.wiki_page_version_deleted(self)
Exemplo n.º 34
0
    def delete(self, version=None, db=None):
        assert self.exists, 'Cannot delete non-existent page'
        if not db:
            db = self.env.get_db_cnx()
            handle_ta = True
        else:
            handle_ta = False

        page_deleted = False
        cursor = db.cursor()
        if version is None:
            # Delete a wiki page completely
            cursor.execute("DELETE FROM wiki WHERE name=%s", (self.name, ))
            self.env.log.info('Deleted page %s' % self.name)
        else:
            # Delete only a specific page version
            cursor.execute("DELETE FROM wiki WHERE name=%s and version=%s",
                           (self.name, version))
            self.env.log.info('Deleted version %d of page %s' %
                              (version, self.name))

        if version is None or version == self.version:
            self._fetch(self.name, None, db)

        if not self.exists:
            from trac.attachment import Attachment
            # Delete orphaned attachments
            Attachment.delete_all(self.env, 'wiki', self.name, db)

        if handle_ta:
            db.commit()

        # Let change listeners know about the deletion
        if not self.exists:
            for listener in WikiSystem(self.env).change_listeners:
                listener.wiki_page_deleted(self)
        else:
            for listener in WikiSystem(self.env).change_listeners:
                if hasattr(listener, 'wiki_page_version_deleted'):
                    listener.wiki_page_version_deleted(self)
Exemplo n.º 35
0
 def delete(self, version=0):
     """ Deletes a specific version, or if none is provided
     then all versions will be deleted. If all (or just one version exists) it
     will also delete all comments and any attachments attached to the post. """
     cnx = self.env.get_db_cnx()
     cursor = cnx.cursor()
     if version:
         cursor.execute("DELETE FROM fullblog_posts "
                 "WHERE name=%s AND version=%s",
                 (self.name, version))
     else:
         cursor.execute("DELETE FROM fullblog_posts "
                 "WHERE name=%s", (self.name,))
     cnx.commit()
     if not len(self.get_versions()):
         # Delete comments
         for comment in self.get_comments():
             comment.delete()
         # Delete attachments
         Attachment.delete_all(self.env, 'blog', self.name, cnx)
         cnx.commit()
     return True
Exemplo n.º 36
0
 def delete(self, version=0):
     """ Deletes a specific version, or if none is provided
     then all versions will be deleted. If all (or just one version exists) it
     will also delete all comments and any attachments attached to the post. """
     cnx = self.env.get_db_cnx()
     cursor = cnx.cursor()
     if version:
         cursor.execute(
             "DELETE FROM fullblog_posts "
             "WHERE name=%s AND version=%s", (self.name, version))
     else:
         cursor.execute("DELETE FROM fullblog_posts "
                        "WHERE name=%s", (self.name, ))
     cnx.commit()
     if not len(self.get_versions()):
         # Delete comments
         for comment in self.get_comments():
             comment.delete()
         # Delete attachments
         Attachment.delete_all(self.env, 'blog', self.name, cnx)
         cnx.commit()
     return True
Exemplo n.º 37
0
        def do_delete(db):
            cursor = db.cursor()
            if version is None:
                # Delete a wiki page completely
                cursor.execute("DELETE FROM wiki WHERE name=%s", (self.name, ))
                self.env.log.info('Deleted page %s' % self.name)
            else:
                # Delete only a specific page version
                cursor.execute("DELETE FROM wiki WHERE name=%s and version=%s",
                               (self.name, version))
                self.env.log.info('Deleted version %d of page %s' %
                                  (version, self.name))

            if version is None or version == self.version:
                self._fetch(self.name, None, db)

            if not self.exists:
                # Invalidate page name cache
                del WikiSystem(self.env).pages
                # Delete orphaned attachments
                from trac.attachment import Attachment
                Attachment.delete_all(self.env, 'wiki', self.name, db)
Exemplo n.º 38
0
    def reset_orphaned_builds(self):
        """Reset all in-progress builds to ``PENDING`` state if they've been
        running so long that the configured timeout has been reached.
        
        This is used to cleanup after slaves that have unexpectedly cancelled
        a build without notifying the master, or are for some other reason not
        reporting back status updates.
        """
        if not self.timeout:
            # If no timeout is set, none of the in-progress builds can be
            # considered orphaned
            return

        db = self.env.get_db_cnx()
        now = int(time.time())
        for build in Build.select(self.env, status=Build.IN_PROGRESS, db=db):
            if now - build.last_activity < self.timeout:
                # This build has not reached the timeout yet, assume it's still
                # being executed
                continue

            self.log.info('Orphaning build %d. Last activity was %s (%s)' % \
                              (build.id, format_datetime(build.last_activity),
                               pretty_timedelta(build.last_activity)))

            build.status = Build.PENDING
            build.slave = None
            build.slave_info = {}
            build.started = 0
            build.stopped = 0
            build.last_activity = 0
            for step in list(BuildStep.select(self.env, build=build.id,
                                              db=db)):
                step.delete(db=db)
            build.update(db=db)

            Attachment.delete_all(self.env, 'build', build.resource.id, db)
        db.commit()
Exemplo n.º 39
0
    def reset_orphaned_builds(self):
        """Reset all in-progress builds to ``PENDING`` state if they've been
        running so long that the configured timeout has been reached.
        
        This is used to cleanup after slaves that have unexpectedly cancelled
        a build without notifying the master, or are for some other reason not
        reporting back status updates.
        """
        if not self.timeout:
            # If no timeout is set, none of the in-progress builds can be
            # considered orphaned
            return

        db = self.env.get_db_cnx()
        now = int(time.time())
        for build in Build.select(self.env, status=Build.IN_PROGRESS, db=db):
            if now - build.last_activity < self.timeout:
                # This build has not reached the timeout yet, assume it's still
                # being executed
                continue

            self.log.info('Orphaning build %d. Last activity was %s (%s)' % \
                              (build.id, format_datetime(build.last_activity),
                               pretty_timedelta(build.last_activity)))

            build.status = Build.PENDING
            build.slave = None
            build.slave_info = {}
            build.started = 0
            build.stopped = 0
            build.last_activity = 0
            for step in list(BuildStep.select(self.env, build=build.id, db=db)):
                step.delete(db=db)
            build.update(db=db)

            Attachment.delete_all(self.env, 'build', build.resource.id, db)
        db.commit()
Exemplo n.º 40
0
    def delete(self, version=None):
        """Delete one or all versions of a page.
        """
        if not self.exists:
            raise TracError(_("Cannot delete non-existent page"))

        with self.env.db_transaction as db:
            if version is None:
                # Delete a wiki page completely
                db("DELETE FROM wiki WHERE name=%s", (self.name,))
                self.env.log.info("Deleted page %s", self.name)
            else:
                # Delete only a specific page version
                db("DELETE FROM wiki WHERE name=%s and version=%s",
                   (self.name, version))
                self.env.log.info("Deleted version %d of page %s", version,
                                  self.name)

            if version is None or version == self.version:
                self._fetch(self.name, None)

            if not self.exists:
                # Invalidate page name cache
                del WikiSystem(self.env).pages
                # Delete orphaned attachments
                from trac.attachment import Attachment
                Attachment.delete_all(self.env, self.realm, self.name)

        # Let change listeners know about the deletion
        if not self.exists:
            for listener in WikiSystem(self.env).change_listeners:
                listener.wiki_page_deleted(self)
        else:
            for listener in WikiSystem(self.env).change_listeners:
                if hasattr(listener, 'wiki_page_version_deleted'):
                    listener.wiki_page_version_deleted(self)
Exemplo n.º 41
0
def _upload_attachment(env, req, uploadfile):     
        sid = req.session.sid
        
        parent_id = None
        parent_realm = 'build'
        filename = None        
        parent_realm = Resource(parent_realm)          
           
        Attachment.delete_all(env, 'iTest', sid) 
        attachment = Attachment(env, 'iTest', sid)
        attachment.description = sid

        if not hasattr(uploadfile, 'filename') or not uploadfile.filename:            
            raise TracError(_('No file uploaded1'))
        if hasattr(uploadfile.file, 'fileno'):
            size = os.fstat(uploadfile.file.fileno())[6]
        else:
            uploadfile.file.seek(0, 2) # seek to end of file
            size = uploadfile.file.tell()
            uploadfile.file.seek(0)
        
        if size == 0:
            raise TracError(_("Can't upload empty file"))

        # We try to normalize the filename to unicode NFC if we can.
        # Files uploaded from OS X might be in NFD.
        filename = unicodedata.normalize('NFC', unicode(uploadfile.filename,
                                                        'utf-8'))
        filename = filename.replace('\\', '/').replace(':', '/')
        filename = os.path.basename(filename)
        
        if not filename:
            raise TracError(_('No file uploaded2'))
        
        attachment.insert(filename, uploadfile.file, size)  
        return attachment
Exemplo n.º 42
0
    def _parse_multipart(self, author, msg):
        body = ''
        # delete all attachement at message-id
        Attachment.delete_all(self.env, 'mailarchive', self.id, self.db)

        for part in msg.walk():
            content_type = part.get_content_type()
            self.log.debug('Content-Type:' + content_type)
            file_counter = 1

            if content_type == 'multipart/mixed':
                pass
            
            elif content_type == 'text/html' and self._is_file(part) == False:
                if body != '':
                    body += "\n------------------------------\n\n"
                    
                body = part.get_payload(decode=True)
                charset = part.get_content_charset()
                
                self.log.debug('charset:' + str(charset))
                # Todo:need try
                if charset != None:
                    body = self._to_unicode(body, charset)
                
            elif content_type == 'text/plain' and self._is_file(part) == False:
                #body = part.get_payload(decode=True)
                if body != '':
                    body += "\n------------------------------\n\n"
                    
                current_body = part.get_payload(decode=True)
                charset = part.get_content_charset()
                
                self.log.debug('charset:' + str(charset))
                # Todo:need try
                if charset != None:
                    #body = self._to_unicode(body, charset)
                    body += self._to_unicode(current_body, charset)
                else:
                    body += current_body
                
            elif part.get_payload(decode=True) == None:
                pass
            
            # file attachment
            else:
                self.log.debug(part.get_content_type())
                # get filename
                # Applications should really sanitize the given filename so that an
                # email message can't be used to overwrite important files
                
                filename = self._get_filename(part)
                if not filename:
                    import mimetypes
                    
                    ext = mimetypes.guess_extension(part.get_content_type())
                    if not ext:
                        # Use a generic bag-of-bits extension
                        ext = '.bin'
                    filename = 'part-%03d%s' % (file_counter, ext)
                    file_counter += 1

                self.log.debug("filename:" + filename.encode(OUTPUT_ENCODING))

                # make attachment
                tmp = os.tmpfile()
                tempsize = len(part.get_payload(decode=True))
                tmp.write(part.get_payload(decode=True))

                tmp.flush()
                tmp.seek(0,0)

                attachment = Attachment(self.env, 'mailarchive', self.id)

                attachment.description = '' # req.args.get('description', '')
                attachment.author = author #req.args.get('author', '')
                attachment.ipnr = '127.0.0.1'

                try:
                    attachment.insert(filename,
                            tmp, tempsize, None, self.db)
                except Exception, e:
                    try:
                        ext = filename.split('.')[-1]
                        if ext == filename:
                            ext = '.bin'
                        else:
                            ext = '.' + ext
                        filename = 'part-%03d%s' % (file_counter, ext)
                        file_counter += 1
                        attachment.description += ', Original FileName: %s' % filename
                        attachment.insert(filename,
                                tmp, tempsize, None, self.db)
                        self.log.warn('As name is too long, the attached file is renamed : ' + filename)

                    except Exception, e:
                        self.log.error('Exception at attach file of Message-ID:' + self.messageid)
                        traceback.print_exc(e)

                tmp.close()