示例#1
0
    def do_test(self, name, old_msg, new_msg):
        # Name the bags
        oldbag = "%s/test/%s_old.bag" % (self.pkg_dir, name)
        newbag = "%s/test/%s_new.bag" % (self.pkg_dir, name)

        # Create an old message
        bag = rosbag.Bag(oldbag, 'w')
        bag.write("topic", old_msg(), roslib.rostime.Time())
        bag.close()

        # Check and migrate
        res = rosbagmigration.checkbag(migrator, oldbag)
        self.assertTrue(not False in [m[1] == [] for m in res],
                        'Bag not ready to be migrated')
        res = rosbagmigration.fixbag(migrator, oldbag, newbag)
        self.assertTrue(res, 'Bag not converted successfully')

        # Pull the first message out of the bag
        topic, msg, t = rosbag.Bag(newbag).read_messages().next()

        # Reserialize the new message so that floats get screwed up, etc.
        m = new_msg()
        buff = StringIO()
        m.serialize(buff)
        m.deserialize(buff.getvalue())

        # Strifying them helps make the comparison easier until I figure out why the equality operator is failing
        self.assertTrue(
            roslib.message.strify_message(msg) ==
            roslib.message.strify_message(m))
        #    self.assertTrue(msgs[0][1] == m)

        #Cleanup
        os.remove(oldbag)
        os.remove(newbag)
  def do_test(self, name, old_msg, new_msg):
    # Name the bags
    oldbag = "%s/test/%s_old.bag"%(self.pkg_dir,name)
    newbag = "%s/test/%s_new.bag"%(self.pkg_dir,name)

    # Create an old message
    bag = rosbag.Bag(oldbag, 'w')
    bag.write("topic", old_msg(), roslib.rostime.Time())
    bag.close()

    # Check and migrate
    res = rosbagmigration.checkbag(migrator, oldbag)
    self.assertTrue(not False in [m[1] == [] for m in res], 'Bag not ready to be migrated')
    res = rosbagmigration.fixbag(migrator, oldbag, newbag)
    self.assertTrue(res, 'Bag not converted successfully')

    # Pull the first message out of the bag
    topic, msg, t = rosbag.Bag(newbag).read_messages().next()

    # Reserialize the new message so that floats get screwed up, etc.
    m = new_msg()
    buff = StringIO()
    m.serialize(buff)
    m.deserialize(buff.getvalue())
    
    # Strifying them helps make the comparison easier until I figure out why the equality operator is failing
    self.assertTrue(roslib.message.strify_message(msg) == roslib.message.strify_message(m))
#    self.assertTrue(msgs[0][1] == m)

    #Cleanup
    os.remove(oldbag)
    os.remove(newbag)
示例#3
0
    def do_test_renamed(self, N):
        tmp_rule_files = [
            'migrated_explicit_rules.py', 'migrated_mixed_rules.py',
            'migrated_addsub_rules.py', 'renamed_rules.py'
        ]
        rule_files = ["%s/test/%s" % (self.pkg_dir, r) for r in tmp_rule_files]

        inbag = "%s/test/renamed_gen%d.bag" % (self.pkg_dir, N)
        outbag = "%s/test/renamed_gen%d.fixed.bag" % (self.pkg_dir, N)

        mm = rosbagmigration.MessageMigrator(rule_files, False)
        res = rosbagmigration.checkbag(mm, inbag)
        self.assertTrue(not False in [m[1] == [] for m in res],
                        'Bag not ready to be migrated')
        res = rosbagmigration.fixbag(mm, inbag, outbag)
        self.assertTrue(res, 'Bag not converted successfully')

        msgs = [msg for msg in rosrecord.logplayer(outbag)]

        self.assertTrue(len(msgs) > 0)

        self.assertEqual(msgs[0][1]._type, 'test_rosbagmigration/Renamed4',
                         'Type name is wrong')
        self.assertEqual(msgs[0][1].foo,
                         struct.unpack('<d', struct.pack('<d', 2.17))[0])
        self.assertEqual(msgs[0][1].bar, (8, 2, 5, 1))
示例#4
0
    def do_test_migrated_mixed(self, N):
        tmp_rule_files = [
            'migrated_explicit_rules.py', 'migrated_mixed_rules.py',
            'migrated_addsub_rules.py'
        ]
        rule_files = ["%s/test/%s" % (self.pkg_dir, r) for r in tmp_rule_files]

        inbag = "%s/test/migrated_mixed_gen%d.bag" % (self.pkg_dir, N)
        outbag = "%s/test/migrated_mixed_gen%d.fixed.bag" % (self.pkg_dir, N)

        mm = rosbagmigration.MessageMigrator(rule_files, False)
        res = rosbagmigration.checkbag(mm, inbag)

        self.assertTrue(not False in [m[1] == [] for m in res],
                        'Bag not ready to be migrated')
        res = rosbagmigration.fixbag(mm, inbag, outbag)
        self.assertTrue(res, 'Bag not converted successfully')

        msgs = [msg for msg in rosrecord.logplayer(outbag)]

        self.assertTrue(len(msgs) > 0)

        self.assertEqual(msgs[0][1].field1.field4.afield2,
                         struct.unpack('<f', struct.pack('<f', 58.2))[0])
        self.assertEqual(msgs[0][1].field1.field4.combo_field3, "aldfkja 17")
        self.assertEqual(msgs[0][1].field1.field4.afield4, 82)

        self.assertEqual(msgs[0][1].field1.field1, 34)
        self.assertEqual(msgs[0][1].field1.field2,
                         struct.unpack('<f', struct.pack('<f', 16.32))[0])
        self.assertEqual(msgs[0][1].field1.field3, "kljene")

        self.assertEqual(msgs[0][1].field2, 59)
    def do_test(self, name, old_msg, new_msg):
        # Name the bags
        oldbag = "%s/test/%s_old.bag" % (self.pkg_dir, name)
        newbag = "%s/test/%s_new.bag" % (self.pkg_dir, name)

        # Create an old message
        bag = rosrecord.Rebagger(oldbag)
        bag.add("topic", old_msg(), roslib.rostime.Time())
        bag.close()

        # Check and migrate
        res = rosbagmigration.checkbag(oldbag, [])
        self.assertTrue(res is None or res == [],
                        'Bag not ready to be migrated')
        res = rosbagmigration.fixbag(oldbag, newbag, [])
        self.assertTrue(res, 'Bag not converted successfully')

        # Pull the first message out of the bag
        msgs = [msg for msg in rosrecord.logplayer(newbag)]

        # Reserialize the new message so that floats get screwed up, etc.
        m = new_msg()
        buff = StringIO()
        m.serialize(buff)
        m.deserialize(buff.getvalue())

        #Compare
        #    print "old"
        #    print roslib.message.strify_message(msgs[0][1])
        #    print "new"
        #    print roslib.message.strify_message(m)

        # Strifying them helps make the comparison easier until I figure out why the equality operator is failing
        self.assertTrue(
            roslib.message.strify_message(msgs[0][1]) ==
            roslib.message.strify_message(m))
        #    self.assertTrue(msgs[0][1] == m)

        #Cleanup
        os.remove(oldbag)
        os.remove(newbag)
示例#6
0
def fixbag_batch(inbags):
    mm = rosbagmigration.MessageMigrator()

    for b in inbags:
        print "Trying to migrate: %s" % b
        outbag = b + '.tmp'

        if rosbagmigration.fixbag(mm, b, outbag):
            oldnamebase = b + '.old'
            oldname = oldnamebase
            i = 1
            while os.path.isfile(oldname):
                i = i + 1
                oldname = oldnamebase + str(i)
            os.rename(b, oldname)
            os.rename(outbag, b)
            print " Migration successful.  Original stored as: %s" % oldname

        else:
            os.remove(outbag)
            print " Migration failed."
示例#7
0
    def do_test_constants_rules(self, N):
        tmp_rule_files = ['constants.bmr']
        rule_files = ["%s/test/%s" % (self.pkg_dir, r) for r in tmp_rule_files]

        inbag = "%s/test/constants_gen%d.bag" % (self.pkg_dir, N)
        outbag = "%s/test/constants_gen%d.fixed.bag" % (self.pkg_dir, N)

        mm = rosbagmigration.MessageMigrator(rule_files, False)
        res = rosbagmigration.checkbag(mm, inbag)

        self.assertTrue(not False in [m[1] == [] for m in res],
                        'Bag not ready to be migrated')
        res = rosbagmigration.fixbag(mm, inbag, outbag)
        self.assertTrue(res, 'Bag not converted successfully')

        msgs = [msg for msg in rosrecord.logplayer(outbag)]

        self.assertTrue(len(msgs) > 0)

        self.assertEqual(msgs[0][1]._type, 'test_rosbagmigration/Constants',
                         'Type name is wrong')
        self.assertEqual(msgs[0][1].value, msgs[0][1].CONSTANT)
示例#8
0
    def do_test_convergent(self, N):
        tmp_rule_files = [
            'migrated_explicit_rules.py', 'migrated_mixed_rules.py',
            'migrated_addsub_rules.py', 'renamed_rules.py',
            'simple_migrated_rules.py', 'converged_rules.py'
        ]
        rule_files = ["%s/test/%s" % (self.pkg_dir, r) for r in tmp_rule_files]

        inbag = "%s/test/convergent_gen%d.bag" % (self.pkg_dir, N)
        outbag = "%s/test/convergent_gen%d.fixed.bag" % (self.pkg_dir, N)

        mm = rosbagmigration.MessageMigrator(rule_files, False)
        res = rosbagmigration.checkbag(mm, inbag)

        self.assertTrue(not False in [m[1] == [] for m in res],
                        'Bag not ready to be migrated')
        res = rosbagmigration.fixbag(mm, inbag, outbag)
        self.assertTrue(res, 'Bag not converted successfully')

        msgs = [msg for msg in rosrecord.logplayer(outbag)]

        self.assertTrue(len(msgs) > 0)

        self.assertEqual(msgs[0][1]._type, 'test_rosbagmigration/Converged',
                         'Type name is wrong')
        self.assertEqual(msgs[0][1].field1[0],
                         struct.unpack('<f', struct.pack('<f', 1.2))[0])
        self.assertEqual(msgs[0][1].field1[1],
                         struct.unpack('<f', struct.pack('<f', 3.4))[0])
        self.assertEqual(msgs[0][1].field1[2],
                         struct.unpack('<f', struct.pack('<f', 5.6))[0])
        self.assertEqual(msgs[0][1].field1[3],
                         struct.unpack('<f', struct.pack('<f', 7.8))[0])

        self.assertEqual(msgs[0][1].field2[0].data, 11)
        self.assertEqual(msgs[0][1].field2[1].data, 22)
        self.assertEqual(msgs[0][1].field2[2].data, 33)
        self.assertEqual(msgs[0][1].field2[3].data, 44)
示例#9
0
    def test_addsub(self):
        tmp_rule_files = [
            'migrated_explicit_rules.py', 'migrated_mixed_rules.py',
            'migrated_addsub_rules.py'
        ]
        rule_files = ["%s/test/%s" % (self.pkg_dir, r) for r in tmp_rule_files]

        inbag = "%s/test/migrated_addsub_gen1.bag" % (self.pkg_dir, )
        outbag = "%s/test/migrated_addsub_gen1.fixed.bag" % (self.pkg_dir, )

        mm = rosbagmigration.MessageMigrator(rule_files, False)
        res = rosbagmigration.checkbag(mm, inbag)

        self.assertTrue(not False in [m[1] == [] for m in res],
                        'Bag not ready to be migrated')
        res = rosbagmigration.fixbag(mm, inbag, outbag)
        self.assertTrue(res, 'Bag not converted successfully')

        msgs = [msg for msg in rosrecord.logplayer(outbag)]

        self.assertTrue(len(msgs) > 0)

        self.assertEqual(msgs[0][1].field1.field1, 42)
        self.assertEqual(msgs[0][1].field2.field1, 42)
示例#10
0
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Revision $Id$

PKG = 'rosbagmigration'
import roslib

roslib.load_manifest(PKG)

import sys
import rosbagmigration

if __name__ == '__main__':
    if len(sys.argv) >= 3:
        if sys.argv[2].split('.')[-1] == "bmr":
            print >> sys.stderr, "Second argument should be a bag, not a rule file."
            exit(1)
        mm = rosbagmigration.MessageMigrator(sys.argv[3:])
        if rosbagmigration.fixbag(mm, sys.argv[1], sys.argv[2]):
            print "Bag migrated successfully."
        else:
            print "Bag could not be migrated"
    else:
        print "usage: fixbag.py <inbag> <outbag> [rulefile1, rulefile2, ...]"