This file is indexed.

/usr/bin/opimd_convert_db is in fso-frameworkd 0.10.1-3.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
opimd before redesign to after redesign db convert "
(C) Tom 'TAsn' Hacohen <tom@stosb.com>
license: GPL2 or later
"""

import os
import sqlite3
import pickle

from dbus import Array
from sys import exit
try:
    import phoneutils
    from phoneutils import normalize_number
    #Old versions do not include compare yet
    try:
        from phoneutils import numbers_compare
    except:
        def numbers_compare(a, b):
            a = normalize_number(str(a))
            b = normalize_number(str(b)) 
            return cmp(a, b)
    phoneutils.init()
except:
    print """Unable to find phoneutils, creating a database without indexes on phonenumbers,
             It's strongly advised to stop the conversion, fix the problems, and try again."""

from framework.subsystems.opimd.pimd_contacts import ContactsDbHandler
from framework.subsystems.opimd.pimd_calls import CallsDbHandler
from framework.subsystems.opimd.pimd_messages import MessagesDbHandler
from framework.subsystems.opimd.pimd_dates import DatesDbHandler
from framework.subsystems.opimd.pimd_tasks import TasksDbHandler
from framework.subsystems.opimd.pimd_notes import NotesDbHandler

from framework.subsystems.opimd.pimd_generic import GenericDomain
from framework.config import rootdir
rootdir = os.path.join( rootdir, 'opim' )

class OldDb(object):
    entries = None
    fields = None
    def __init__(self):
        self.entries = {}
        self.fields = {}
        try:
            
            
            self.load_entries_from_db('task', {1:'Timestamp', 2:'Timezone', 3:'Title', 4:'Content', 5:'Started', 6:'Finished'})
            self.load_entries_from_db('note', {1:'Timestamp', 2:'Timezone', 3:'Title', 4:'Content'})
            self.load_entries_from_db('message', {1:'Source', 2:'Timestamp', 3:'Timezone', 4:'Direction', 5:'Title', 6:'Sender', 7:'TransmitLoc', 8:'Content', 9:'MessageRead', 10:'MessageSent', 11:'Processing'})
            self.load_entries_from_db('date', {1:'Begin', 2:'End', 3:'Message'})
            self.load_entries_from_db('contact', {1:'Name', 2:'Surname', 3:'Nickname', 4:'Birthdate', 5:'MarrDate', 6:'Partner', 7:'Spouse', 8:'MetAt', 9:'HomeLoc', 10:'Department'})
            self.load_entries_from_db('call', {1:'Type', 2:'Timestamp', 3:'Timezone', 4:'Direction', 5:'Duration', 6:'Cost', 7:'Answered', 8:'New', 9:'Replied'})

            self.load_fields('task')
            self.load_fields('note')
            self.load_fields('message')
            self.load_fields('date')
            self.load_fields('contact')
            self.load_fields('call')
        except Exception as exp:
            print exp

    def load_entries_from_db(self, prefix, keys):
        """Loads all entries from db"""
        con = sqlite3.connect(os.path.join(rootdir, 'sqlite-' + prefix + 's.db'), isolation_level=None)
        con.text_factory = sqlite3.OptimizedUnicode
        cur = con.cursor()
        self.entries[prefix] = []
        try:
            cur.execute('SELECT * FROM ' + prefix + 's')
            lines = cur.fetchall()
        except Exception as exp:
            print "In domain: " + prefix
            raise 

        for line in lines:
            entry = {}
            for key in keys:
                if line[key]:
                    entry[keys[key]] = line[key]
            try:
                cur.execute('SELECT Field, Value FROM ' + prefix + '_values WHERE ' + prefix + 'Id=?',(line[0],))
                for pair in cur:
                    if not pair[1]:
                        continue
                    if entry.has_key(pair[0]):
                        if type(entry[pair[0]]) == list:
                            entry[pair[0]].append(pair[1])
                        else:
                            entry[pair[0]]=[entry[pair[0]], pair[1]]
                    else:
                        entry[pair[0]]=pair[1]
            except:
                print "In domain: " + prefix
                raise 

            if entry.get('Timestamp'):
                entry['Timestamp']=int(float(entry['Timestamp']))
            #Remove bad fields
            for field in entry.keys():
                #convert those nulls to false
                if field in ('Answered', 'New', 'Duration') and not entry[field]:
                    entry[field] = 0
                #Don't delete empty fields
                elif not entry[field]:
                    del entry[field]
            self.entries[prefix].append(entry)
        cur.close()
    def load_fields(self, prefix):
        name = prefix.capitalize() + "s"
        path = os.path.join(rootdir, name + 'Fields.pickle')
        if os.path.exists(path):
            pickleFile = open(path, "r")
            self.fields[prefix] = pickle.load(pickleFile)
            pickleFile.close()
        if not self.fields.get(prefix):
            self.fields[prefix] = {}
            
class NewDb(object):
    old_db = None
    def __init__(self, old_db):
        self.old_db = old_db
        dom = GenericDomain()
        dom.db_handler = TasksDbHandler(dom)
        self.save_entries_to_db('task', dom.db_handler)
        
        dom = GenericDomain()
        dom.db_handler = NotesDbHandler(dom)
        self.save_entries_to_db('note', dom.db_handler)
        
        dom = GenericDomain()
        dom.db_handler = MessagesDbHandler(dom)
        self.save_entries_to_db('message', dom.db_handler)
        
        dom = GenericDomain()
        dom.db_handler = DatesDbHandler(dom)
        self.save_entries_to_db('date', dom.db_handler)
        
        dom = GenericDomain()
        dom.db_handler = ContactsDbHandler(dom)
        #Adding default fields to contact:
        print "Adding default fields for contacts:"
        fields = {
                'Name'          : 'name',
                'Nickname'      : 'name',
                'Surname'       : 'name',
                'Home phone'    : 'phonenumber',
                'Mobile phone'  : 'phonenumber',
                'Work phone'    : 'phonenumber',
                'Phone'         : 'phonenumber',

                'Address'       : 'address',
                'Birthday'      : 'date',
                'E-mail'        : 'email',
                'Photo'         : 'photo',
                'Affiliation'   : 'text',
                'Note'          : 'text'
                }
        for field in fields:
            if not self.old_db.fields['contact'].has_key(field):
                self.old_db.fields['contact'][field] = fields[field]
        self.save_entries_to_db('contact', dom.db_handler)
        
        dom = GenericDomain()
        dom.db_handler = CallsDbHandler(dom)
        self.save_entries_to_db('call', dom.db_handler)

    def save_entries_to_db(self, prefix, handler):
        print "Initializing new " + prefix + " db"
        print "Adding fields"
        for field in self.old_db.fields[prefix]:
            if handler.domain.is_reserved_field(field):
                print "Not adding reserved field: " + field
                continue
            handler.domain.add_new_field(field, self.old_db.fields[prefix][field])
        print "Adding entries"
        try:
            for entry in self.old_db.entries[prefix]:
                handler.add_entry(entry)
        except:
            print "Failed on: " + str(entry)
            raise

if os.path.exists(os.path.join(rootdir, 'pim.db')):
    print "DB file (" + os.path.join(rootdir, 'pim.db') + ") already exists, aborting..."
    print "This usually means you already converted your db to the new format."
    print "If you want to convert again, remove pim.db and restart this script"
    exit(1)
print "Attempting to convert old pim database, any errors will be written in frameworkd's log (mostly resides in: /var/log/frameworkd.log)"
print "You can stop the conversion script whenever you want to, just send a keyboard interrupt (^C).\nAlthough the conversion is not resumable, you can stop when you feel you converted all you needed to convert.\nThis is useful for stopping the conversion if converting the calls domain takes too long,\n and you don't want to save all your of your call history."
old_db = OldDb()

new_db = NewDb(old_db)