예제 #1
0
 def get_config_file(self, configfile):
     import ConfigParser
     profilefile = os.path.join(configfile, 'profiles.ini')
     if os.path.isfile(profilefile):
         cp = ConfigParser.ConfigParser()
         cp.read(profilefile)
         profiles = {}  # dict of founded profiles
         # get profiles from profiles.ini in thunderbird directory
         for sec in cp.sections():
             if sec.lower().startswith("profile"):
                 profiles[sec] = {}
                 for opt in cp.options(sec):
                     profiles[sec][opt.lower()] = cp.get(sec, opt)
         # get all data from profiles.ini
         for profile in profiles:
             if profiles[profile]['isrelative']:
                 profile_location = os.path.join(configfile,
                                                 profiles[profile]['path'])
             else:
                 profile_location = profiles[profile]['path']
             #look for calendar-data/local.sqlite first
             #(new in sunbird/lightning 1.0)
             location = os.path.join(profile_location,
                                     'calendar-data/local.sqlite')
             print location
             if os.path.exists(location):
                 self.parse_birthday(location)
                 return
             # ... and now the old one
             location = os.path.join(profile_location, 'storage.sdb')
             print location
             if os.path.exists(location):
                 self.parse_birthday(location)
                 return
     show_error_msg(_('Error reading profile file: %s' % configfile))
예제 #2
0
    def parse(self, addressbook=None, conf=None):
        '''load and parse parse Evolution data files'''
        # XXX: set addressbook in __init__?
        self.ab = addressbook
        try:
            import evolution
            # When there is no evolution addressbook, silently abort
            # parsing.
            if not evolution.ebook:
                return
        except ImportError:
            show_error_msg(
                _("You need to install python-evolution to use the evolution module"
                  ))
            return

        for book in evolution.ebook.list_addressbooks():
            ebook = evolution.ebook.open_addressbook(book[1])
            if not ebook:
                continue
            for contact in ebook.get_all_contacts():
                # contact.props.birth_date{.year, .month, .day} non-existing
                # -> using vcard
                vcard = contact.get_vcard_string()
                self.parse_birthday((contact.props.full_name, vcard),
                                    addressbook)
예제 #3
0
 def get_config_file(self, configfile):
     import ConfigParser
     profilefile = os.path.join(configfile, 'profiles.ini')
     if os.path.isfile(profilefile):
         cp = ConfigParser.ConfigParser()
         cp.read(profilefile)
         profiles = {} # dict of founded profiles
         # get profiles from profiles.ini in thunderbird directory
         for sec in cp.sections():
             if sec.lower().startswith("profile"):
                 profiles[sec] = {}
                 for opt in cp.options(sec):
                     profiles[sec][opt.lower()] = cp.get(sec, opt)
         # get all data from profiles.ini
         for profile in profiles:
             if profiles[profile]['isrelative']:
                 profile_location = os.path.join(configfile,
                                     profiles[profile]['path'])
             else:
                 profile_location = profiles[profile]['path']
             #look for calendar-data/local.sqlite first 
             #(new in sunbird/lightning 1.0)
             location = os.path.join(profile_location, 'calendar-data/local.sqlite')
             print location
             if os.path.exists(location):
                 self.parse_birthday(location)
                 return
             # ... and now the old one
             location = os.path.join(profile_location, 'storage.sdb')
             print location
             if os.path.exists(location):
                 self.parse_birthday(location)
                 return
     show_error_msg(_('Error reading profile file: %s' % configfile))
예제 #4
0
 def connect(self, filename):
     '''"connect" to sqlite3-database'''
     try:
         import sqlite3
     except:
         show_error_msg(_("Package %s is not installed." % "SQLite3"))
     try:
         self.conn = sqlite3.connect(filename)
         self.cursor = self.conn.cursor()
     except Exception as msg:
         show_error_msg(_('sqlite3 could not connect: %s' % str(msg)))
예제 #5
0
 def connect(self, filename):
     '''"connect" to sqlite3-database'''
     try:
         import sqlite3
     except:
         show_error_msg(_("Package %s is not installed." % "SQLite3"))
     try:
         self.conn = sqlite3.connect(filename)
         self.cursor = self.conn.cursor()
     except Exception as msg:
         show_error_msg(_('sqlite3 could not connect: %s' % str(msg)))
예제 #6
0
    def add(self, name, birthday):
        import time, uuid
        # create new uuid
        event_date = int(birthday.strftime("%s"))
        event_start = (event_date + 86400) * 1000000
        event_end = (event_date + 172800) * 1000000
        uid = str(uuid.uuid4())
        create_time = str(int(time.time()) * 1000000)
        try:
            qry = '''SELECT id from cal_calendars LIMIT 1;'''
            self.cursor.execute(qry)
            rows = self.cursor.fetchall()
            calender_id = rows[0][0]
            # lets assume there is at least one calendar
            # TODO: implement code to insert new calendar if it none exists!

            qry = '''INSERT INTO "cal_events"
                (cal_id, id, time_created, last_modified, title, flags,
                event_start, event_start_tz, event_end, event_end_tz)
                VALUES
                ('%s', '%s', '%s', '%s', '%s', 28, '%s', 'floating', '%s',
                 'floating'); ''' % (calender_id, uid, create_time,
                                     create_time, name, event_start, event_end)
            self.cursor.execute(qry)

            qry = '''INSERT INTO cal_properties
                     (item_id, key, value)
                     VALUES
                     ('%s', 'CATEGORIES', 'Birthday');''' % uid
            self.cursor.execute(qry)
            qry = '''INSERT INTO cal_properties
                     (item_id, key, value)
                     VALUES
                     ('%s', 'TRANSP', 'TRANSPARENT');''' % uid
            self.cursor.execute(qry)
            qry = '''INSERT INTO cal_properties
                     (item_id, key, value)
                     VALUES
                     ('%s', 'X-MOZ-GENERATION', '1');''' % uid
            self.cursor.execute(qry)
            # birthday repeats yearly
            qry = '''INSERT INTO "cal_recurrence"
                     (item_id, recur_index, recur_type, is_negative, count,
                     interval)
                     VALUES
                     ('%s', 1, 'YEARLY', 0, -1, 1);''' % uid
            self.cursor.execute(qry)
            self.conn.commit()
        except Exception as msg:
            show_error_msg(
                _('Could not execute SQLite-query') + ': %s\n %s' %
                (qry, str(msg)))
        self.ab.add(name, str(birthday))
예제 #7
0
    def add(self, name, birthday):
        import time, uuid
        # create new uuid
        event_date = int(birthday.strftime("%s"))
        event_start = (event_date + 86400) * 1000000
        event_end = (event_date + 172800) * 1000000
        uid = str(uuid.uuid4())
        create_time = str(int(time.time()) * 1000000)
        try:
            qry = '''SELECT id from cal_calendars LIMIT 1;'''
            self.cursor.execute(qry)
            rows = self.cursor.fetchall()
            calender_id = rows[0][0]
            # lets assume there is at least one calendar
            # TODO: implement code to insert new calendar if it none exists!

            qry = '''INSERT INTO "cal_events"
                (cal_id, id, time_created, last_modified, title, flags,
                event_start, event_start_tz, event_end, event_end_tz)
                VALUES
                ('%s', '%s', '%s', '%s', '%s', 28, '%s', 'floating', '%s',
                 'floating'); ''' % (calender_id, uid, create_time,
                              create_time, name, event_start, event_end)
            self.cursor.execute(qry)

            qry = '''INSERT INTO cal_properties
                     (item_id, key, value)
                     VALUES
                     ('%s', 'CATEGORIES', 'Birthday');''' % uid
            self.cursor.execute(qry)
            qry = '''INSERT INTO cal_properties
                     (item_id, key, value)
                     VALUES
                     ('%s', 'TRANSP', 'TRANSPARENT');''' % uid
            self.cursor.execute(qry)
            qry = '''INSERT INTO cal_properties
                     (item_id, key, value)
                     VALUES
                     ('%s', 'X-MOZ-GENERATION', '1');''' % uid
            self.cursor.execute(qry)
            # birthday repeats yearly
            qry = '''INSERT INTO "cal_recurrence"
                     (item_id, recur_index, recur_type, is_negative, count,
                     interval)
                     VALUES
                     ('%s', 1, 'YEARLY', 0, -1, 1);''' % uid
            self.cursor.execute(qry)
            self.conn.commit()
        except Exception as msg:
            show_error_msg(_('Could not execute SQLite-query')
                            + ': %s\n %s' % (qry, str(msg)))
        self.ab.add(name, str(birthday))
예제 #8
0
파일: mysql.py 프로젝트: lafrech/gbirthday
 def add(self, name, birthday):
     '''insert new Birthday to database'''
     birthday = str(birthday)
     self.connect()
     try:
         qry = ("INSERT INTO %s (%s, %s) VALUES ('%s', '%s')" %
             (self.table, self.name_row, self.date_row, name, birthday))
         self.cursor.execute(qry)
     except Exception as msg:
         show_error_msg(_('Could not execute MySQL-query')
                         + ': %s\n %s' % (qry, str(msg)))
     self.conn.close()
     self.ab.add(name, birthday)
예제 #9
0
    def parse(self, addressbook, conf):
        # XXX: set addressbook in __init__?
        self.ab = addressbook
        '''load file / open database connection'''
        sunbird = os.path.join(self.mozilla_location, 'sunbird')
        iceowl = os.path.join(self.mozilla_location, 'iceowl')

        if (os.path.exists(sunbird)):
            # extract path from profiles.ini
            self.get_config_file(sunbird)
        elif (os.path.exists(iceowl)):
            self.get_config_file(iceowl)
        else:
            show_error_msg(_('Neither iceowl nor sunbird is installed'))
예제 #10
0
 def add(self, name, birthday):
     '''insert new Birthday to database'''
     birthday = str(birthday)
     self.connect()
     try:
         qry = ("INSERT INTO %s (%s, %s) VALUES ('%s', '%s')" %
                (self.table, self.name_row, self.date_row, name, birthday))
         self.cursor.execute(qry)
     except Exception as msg:
         show_error_msg(
             _('Could not execute MySQL-query') + ': %s\n %s' %
             (qry, str(msg)))
     self.conn.close()
     self.ab.add(name, birthday)
예제 #11
0
    def parse(self, addressbook, conf):
        # XXX: set addressbook in __init__?
        self.ab = addressbook
        '''load file / open database connection'''
        sunbird = os.path.join(self.mozilla_location, 'sunbird')
        iceowl = os.path.join(self.mozilla_location, 'iceowl')

        if (os.path.exists(sunbird)):
            # extract path from profiles.ini
            self.get_config_file(sunbird)
        elif (os.path.exists(iceowl)):
            self.get_config_file(iceowl)
        else:
            show_error_msg(_('Neither iceowl nor sunbird is installed'))
예제 #12
0
 def add(self, name, birthday):
     '''add new person with birthday to end of csv-file'''
     birthday = str(birthday)
     # TODO: show menu to select file?
     if len(self.conf.csv_files) == 0:
         show_error_msg(_('CSV-file does not exist'))
         return
     filename = self.conf.csv_files[0]
     if (os.path.exists(filename)):
         output_file = file(self.conf.csv_files[0], 'a')
     else:
         output_file = file(self.conf.csv_files[0], 'w')
     output_file.write(birthday + ', ' + name + '\n')
     output_file.close()
     self.addressbook.add(name, birthday)
예제 #13
0
 def connect(self):
     '''establish connection'''
     try:
         import MySQLdb
     except:
         show_error_msg(_("Package %s is not installed." % "MySQLdb"))
     try:
         self.conn = MySQLdb.connect(host=self.host,
                                     port=int(self.port),
                                     user=self.username,
                                     passwd=self.password,
                                     db=self.database)
         self.cursor = self.conn.cursor()
     except Exception as msg:
         show_error_msg(_('Could not connect to MySQL-Server') + str(msg))
         return False
     return True
예제 #14
0
파일: mysql.py 프로젝트: lafrech/gbirthday
 def parse(self, addressbook, conf):
     '''connect to mysql-database and get data'''
     # XXX: set addressbook in __init__?
     self.ab = addressbook
     if not self.connect():
         return
     try:
         qry = ("SELECT %s, %s FROM %s"
                     % (self.name_row, self.date_row, self.table))
         self.cursor.execute(qry)
         rows = self.cursor.fetchall()
         for row in rows:
             addressbook.add(row[0], str(row[1]))
     except Exception as msg:
         show_error_msg(_('Could not execute MySQL-query')
                         + ': %s\n %s' % (qry, str(msg)))
     self.conn.close()
예제 #15
0
 def parse(self, addressbook, conf):
     '''connect to mysql-database and get data'''
     # XXX: set addressbook in __init__?
     self.ab = addressbook
     if not self.connect():
         return
     try:
         qry = ("SELECT %s, %s FROM %s" %
                (self.name_row, self.date_row, self.table))
         self.cursor.execute(qry)
         rows = self.cursor.fetchall()
         for row in rows:
             addressbook.add(row[0], str(row[1]))
     except Exception as msg:
         show_error_msg(
             _('Could not execute MySQL-query') + ': %s\n %s' %
             (qry, str(msg)))
     self.conn.close()
예제 #16
0
파일: mysql.py 프로젝트: lafrech/gbirthday
 def connect(self):
     '''establish connection'''
     try:
         import MySQLdb
     except:
         show_error_msg(_("Package %s is not installed." % "MySQLdb"))
     try:
         self.conn = MySQLdb.connect(host=self.host,
                                 port=int(self.port),
                                 user=self.username,
                                 passwd=self.password,
                                 db=self.database)
         self.cursor = self.conn.cursor()
     except Exception as msg:
         show_error_msg(_('Could not connect to MySQL-Server')
                         + str(msg))
         return False
     return True
예제 #17
0
 def parse(self, addressbook, conf):
     '''open and parse file'''
     # XXX: set addressbook in __init__?
     self.ab = addressbook
     self.addressbook = addressbook
     self.conf = conf
     if not conf.csv_files:
         return
     for filename in conf.csv_files:
         if (os.path.exists(filename)):
             for line in file(filename):
                 # check, if any of the seperators are in the text
                 for sep in self._seperators:
                     if len(line.split(sep)) > 1:
                         date = line.split(sep, 1)[0]
                         name = line.split(sep, 1)[1][:-1]
                         addressbook.add(name, date)
                         break
         else:
             show_error_msg(_('Could not load CSV-file:') + filename)