def main(argv):
    # camera info - read it in
    status, cam_info = cameras_get_info()

    # My code here
    fs_info = []

    # get the file system info
    index = 0
    files_unchanged = []
    status_re = re.compile("online",re.IGNORECASE)
    for i in cam_info:
        status = i['status']

        if status_re.match(status):
            dir = i['disk_location']
            number_of_cams = len(cam_info)
            file_re = ".*%s\.m.*" % i['id']
            f_re = re.compile(file_re)
            # used in file size comparison
            file_before = ""
            file_after = ""
            # get an initial snapshot of the file sizes
            file_info_first = files_get_info(dir)
            for j in sorted(file_info_first,
                    key=itemgetter('name'),
                    reverse=True):
                if f_re.match(j['name']):
                    file_before = j
                    break
            # delay some time so that the files can grow
            time.sleep(2)
            file_info_last = files_get_info(dir)
            for j in sorted(file_info_last,
                    key=itemgetter('time_mod'),
                    reverse=True):
                if j['name'] == file_before['name']:
                    file_after = j
                    break
            # list of dead camera files
            if file_before['size'] == file_after['size']:
                files_unchanged.append(file_after)
        else:
            print "%s is offline" % i['id']
    # file names - pull these out for the email text
    file_names = ""
    for k in files_unchanged:
        file_names = "%s\n%s" % (file_names, k['name'])
    if len(file_names) > 0:
        subject = "Warning: cameras may not be storing data"
        text = "Camera files:\n%s" % file_names
        emailMessage("*****@*****.**", subject, text)
    return 0
Example #2
0
def main(argv):
    # My code here
    fs_info = []

    # get the file system info
    index = 0
    for i in DIRS_CAMERA:
        dir = i['dir']
        fs_info.append(i)
        fs_info[index].update(path_get_size(dir))
        print fs_info[index]
        # get the bytes to delete based on THRESHOLD_CLEAN
        bytes_to_delete = int(disk_get_amount_to_cleanup(fs_info[index]))
        print bytes_to_delete
        #
        # cleanup?
        if bytes_to_delete > 0:
            file_info = files_get_info(dir)
            file_info = sorted(file_info, key=itemgetter('time_mod'))
            count_byte = int(0)
            files_to_delete = []
            for j in file_info:
                files_to_delete.append(j)
                count_byte += int(j['size'])
                print "%s : %s" % (bytes_to_delete, count_byte)
                if count_byte >= bytes_to_delete:
                    break
            text = ("The following files will be deleted from: %s\n" %
                    dir)
            for j in files_to_delete:
                text += "%s:%s\n" % (j['name'], j['size'])
                path_full = "%s/%s" % (dir, j['name'])
                os.remove(path_full)
            subject = ("%s has reached it''s threshold and files "
                "will be deleted. %s bytes will be deleted." %
                (dir, bytes_to_delete))
            emailMessage("*****@*****.**", subject, text)

        index += 1
    return 0