예제 #1
0
    def add(self, prev_hash, next_hash, user_accepted=False):
        """
        Adds an hash couple into the db.

        @param prev_hash: the current hash
        @param next_hash: the next hash
        @param user_accepted:
                    if true set the column type to "useraccept"
                    instead of "commit"
        """

        self._logger.debug(u'Saving following hashes %s %s' %
                           (prev_hash, next_hash))
        if user_accepted:
            record_type = 'useraccept'
        else:
            record_type = 'commit'

        if prev_hash is None:
            prev_hash = 'Unknown'

        unix_gmtime, string_localtime = get_unix_and_local_timestamp()

        self._recreate_db_if_not_exists()

        self.update_record(unix_gmtime, string_localtime, record_type,
                           prev_hash, next_hash)

        self._logger.debug(u'New hash couple saved (%s, %s, %s)' %
                           (record_type, prev_hash, next_hash))
예제 #2
0
    def initialize_new(self):
        ''' Initialize a new local dataset database. '''
        self.logger.debug(u'Creating local_dataset table... ')
        result = self.db.execute('create table %s (%s) ;' % (TABLENAME,
                                                             TABLESCHEMA))
        if result:
            self.logger.debug(u'%s database table successfully created.' %
                              (TABLENAME))
        else:
            self.logger.warning(u'Something went wrong creating \
                                  %s database table... ' % (TABLENAME))
            return False
        unix_gmtime, string_localtime = get_unix_and_local_timestamp()
        result = self.db.execute("INSERT INTO %s VALUES (?,?,?,?,?) ;" %
                                 (TABLENAME), [unix_gmtime,
                                               string_localtime,
                                               'autoinsert',
                                               '',
                                               UNKNOWN_BASIS_STRING
                                               ]
                                 )

        if result:
            self.logger.debug(u'Default entry successfully inserted in \
                                %s database table.' % (TABLENAME))
        else:
            self.logger.warning(u'Something went wrong inserting default \
                                  entry into %s database table... ' %
                                  (TABLENAME))
            return False
        return True
예제 #3
0
    def add(self, prev_hash, next_hash, user_accepted=False):
        self.logger.debug(u'Saving following hashes %s %s' % (prev_hash,
                                                              next_hash))
        if user_accepted:
            record_type = 'useraccept'
        else:
            record_type = 'commit'

        if prev_hash is None:
            prev_hash = UNKNOWN_BASIS_STRING

        unix_gmtime, string_localtime = get_unix_and_local_timestamp()

        if not self.check_database_file():
            self.initialize_new()

        result = self.db.execute("INSERT INTO %s VALUES (?,?,?,?,?) ;" %
                                 (TABLENAME), [unix_gmtime,
                                               string_localtime,
                                               record_type,
                                               prev_hash,
                                               next_hash])
        if result:
            self.logger.debug(u'New hash couple saved (%s, %s, %s)' %
                                     (record_type, prev_hash, next_hash))
        else:
            self.logger.warning(u'Something went wrong saving hashes \
                                    (%s, %s, %s)' % (record_type,
                                                     prev_hash,
                                                     next_hash))
            return False
        self.logger.info('Commit data saved to history')
        return True
예제 #4
0
    def add(self, prev_hash, next_hash, user_accepted=False):
        """
        Adds an hash couple into the db.

        @param prev_hash: the current hash
        @param next_hash: the next hash
        @param user_accepted:
                    if true set the column type to "useraccept"
                    instead of "commit"
        """

        self._logger.debug(u'Saving following hashes %s %s'
                           % (prev_hash, next_hash))
        if user_accepted:
            record_type = 'useraccept'
        else:
            record_type = 'commit'

        if prev_hash is None:
            prev_hash = 'Unknown'

        unix_gmtime, string_localtime = get_unix_and_local_timestamp()

        self._recreate_db_if_not_exists()

        self.update_record(unix_gmtime,
                           string_localtime,
                           record_type,
                           prev_hash,
                           next_hash)

        self._logger.debug(u'New hash couple saved (%s, %s, %s)'
                           % (record_type, prev_hash, next_hash))
예제 #5
0
    def add(self, prev_hash, next_hash, user_accepted=False):
        """
        Adds an hash couple into the db

        @param prev_hash: the current hash
        @param next_hash: the next hash
        @param user_accepted:
                    if true set the column type to "useraccept"
                    instead of "commit"
        """

        self.logger.debug(u'Saving following hashes %s %s' %
                          (prev_hash, next_hash)
                          )
        if user_accepted:
            record_type = 'useraccept'
        else:
            record_type = 'commit'

        if prev_hash is None:
            prev_hash = UNKNOWN_BASIS

        unix_gmtime, string_localtime = get_unix_and_local_timestamp()

        self._recreate_db_if_not_exists()

        result = self.insert_record((unix_gmtime,
                                  string_localtime,
                                  record_type,
                                  prev_hash,
                                  next_hash
                                  ))
        if result:
            self.logger.debug(u'New hash couple saved (%s, %s, %s)' %
                              (record_type, prev_hash, next_hash)
                             )
        else:
            self.logger.warning(u'Something went wrong saving hashes \
                                 (%s, %s, %s)' % (record_type,
                                                  prev_hash,
                                                  next_hash)
                                )
            return False
        self.logger.debug('Commit data saved to history')
        return True