Пример #1
0
def get_duplicate_files(db_location=None):
    ret_list = []
    try:
        if not db_location:
            db_location, err = get_db_location()
            if err:
                raise Exception(err)
        query = 'select checksum, size, count(checksum) as dup_count from file_info group by checksum, size order by size desc, dup_count desc'
        results, err = db.get_multiple_rows(db_location, query)
        if err:
            raise Exception(err)
        #print results[:5]
        for result in results:
            dup_dict = {}
            if result['checksum'] == None:
                continue
            query = 'select * from file_info where checksum = "%s"' % result[
                'checksum']
            checksum_results, err = db.get_multiple_rows(db_location, query)
            if err:
                raise Exception(err)
            dup_list = []
            for checksum_result in checksum_results:
                dup_list.append({
                    'file_name': checksum_result['path'],
                    'size': checksum_result['size']
                })
            dup_dict['count'] = result['dup_count']
            dup_dict['size'] = result['size']
            dup_dict['dup_list'] = dup_list
            ret_list.append(dup_dict)

    except Exception, e:
        return None, 'Error retrieving duplicate files : %s' % str(e)
Пример #2
0
def get_pending_events(db_path):
    event_rows = False
    try:
        query = 'select * from inotify_events'
        event_rows, err = db.get_multiple_rows(db_path, query)
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error retrieving pending events from the database: %s' % str(
            e)
Пример #3
0
def load_shares_list():
    l = []
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        l, err = db.get_multiple_rows(db_path, 'select * from rsync_shares')
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error loading RSYNC shares list : %s' % str(e)
Пример #4
0
def get_files_by_extension(extension='', db_location=None):
    ret_list = []
    try:
        if not db_location:
            db_location, err = get_db_location()
            if err:
                raise Exception(err)
        query = 'select * from file_info where id != 0 and extension = "%s"' % extension
        ret_list, err = db.get_multiple_rows(db_location, query)
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error retrieving files by  extension : %s' % str(e)
Пример #5
0
def get_extension_count(db_location=None):
    ret_list = []
    try:
        if not db_location:
            db_location, err = get_db_location()
            if err:
                raise Exception(err)
        query = 'select extension, count(*) as count from file_info group by extension having (count(*) > 0 and id != 0) order by count desc'
        ret_list, err = db.get_multiple_rows(db_location, query)
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error retrieving file extension counts : %s' % str(e)
Пример #6
0
def simple_file_info_query(query_type, db_location=None, limit=10):
    ret_list = []
    try:
        if query_type not in [
                'NEWEST_READ_TIME', 'NEWEST_MODIFY_TIME', 'NEWEST_ACCESS_TIME',
                'OLDEST_READ_TIME', 'OLDEST_MODIFY_TIME', 'OLDEST_ACCESS_TIME',
                'MOST_RECENTLY_ATTRIB', 'LARGEST'
        ]:
            raise Exception('Unknown query type')
        if not db_location:
            db_location, err = get_db_location()
            if err:
                raise Exception(err)
        query_mapping = {
            'NEWEST_READ_TIME':
            'select * from file_info where id != 0 and last_read_time is not null order by last_read_time desc limit %d'
            % limit,
            'OLDEST_READ_TIME':
            'select * from file_info where id != 0 and last_read_time is not null order by last_read_time limit %d'
            % limit,
            'NEWEST_MODIFY_TIME':
            'select * from file_info where id != 0 and last_modify_time is not null order by last_modify_time desc limit %d'
            % limit,
            'OLDEST_MODIFY_TIME':
            'select * from file_info where id != 0 and last_modify_time is not null order by last_modify_time limit %d'
            % limit,
            'NEWEST_ACCESS_TIME':
            'select * from file_info where id != 0 and last_access_time is not null order by last_access_time desc limit %d'
            % limit,
            'OLDEST_ACCESS_TIME':
            'select * from file_info where id != 0 and last_access_time is not null order by last_access_time limit %d'
            % limit,
            'MOST_RECENTLY_ATTRIB':
            'select * from file_info where id != 0 and last_attrib_modify_time is not null order by last_attrib_modify_time limit %d'
            % limit,
            'LARGEST':
            'select * from file_info where id != 0 and size is not null order by size desc limit %d'
            % limit
        }
        query = query_mapping[query_type]
        ret_list, err = db.get_multiple_rows(db_location, query)
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error querying the database : %s' % str(e)