示例#1
0
    def migrate_from_couch(self):
        try:
            from desktopcouch.records.server import CouchDatabase
            from desktopcouch.records.record import Record
            imported = True
        except ImportError:
            return

        db = 0
        try:
            db = CouchDatabase('indicator-remindor-alarms', create=False)
        except:
            return

        if not db.view_exists("list", "app"):
            map_js = """function(doc) { emit(doc._id, doc) }"""
            db.add_view("list", map_js, None, "app")

        result = db.execute_view("list", "app")
        result_list = list(result)

        for row in result_list:
            time_s = datetimeutil.format_time(row.value["hour"], row.value["minute"], row.value["am_pm"])
            sound_length = 0
            sound_loop = False

            try:
                sound_length = row.value["sound_length"]
            except KeyError:
                sound_length = 0

            try:
                sound_loop = row.value["sound_loop"]
            except KeyError:
                sound_loop = False

            self.execute("""INSERT INTO alarms (label, notes, time, date, sound, sound_length,
                sound_loop, notification, command) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)""",
                (row.value["label"], row.value["notes"], time_s, row.value["date"],
                row.value["sound"], sound_length, sound_loop,
                row.value["notification"], row.value["command"]))