Example #1
0
def _init(pic_path, config_location,is_start_up):
    logging.info("------------------------------------")
    logging.info("System initing....\r")

    logging.info("System init will start in 5 s")
    time.sleep(5)
    #write_notation()

    files_list = []
    current_files_size = 0
    attachment_size = 0

    for path in pic_path:
        logging.info("Working dir is %s" %path)
        for root, dirs, files in os.walk(path):
            for name in files:
                full_name = root + '/' + name
                logging.info("File %s add to list" %full_name)
                files_list.append(full_name)

                attachment_size += 1
                #transfer to MB
                current_files_size += files_filter.get_file_mb_size(full_name)

                #if the current files size bigger than 20MB It will send and files_list will init to []
                if current_files_size <=20:
                    if attachment_size == ATTACHMENT_SIZE:
                        logging.warning("FILE SIZE LIMIT %s AND WILL SEND"%attachment_size)
                        logging.info("SEND %s" %files_list)
                        email_client.mail(target_email,
                                           subject,
                                           content,
                                           files_list)
                        logging.info("System pause for 5 seconds")
                        time.sleep(5)
                        files_list = []
                        current_files_size = 0
                        attachment_size = 0
    global config_utils
    files_list = FileFilter(config_utils,files_list)

    if files_list != []:  #to avoid email without attachment
        email_client.mail(target_email,
               subject,
               content,
               files_list)

    sys_init_time = time.time()
    global last_send_time
    last_send_time = sys_init_time

    Config(config_location)._update_config('filesys','is_first_time','false')
    if _add_to_startup(is_start_up):
        logging.info("System initing send time %s" %last_send_time)
        logging.info("System inited at %s." %time.strftime("%Y-%m-%d %H:%M:%S"))
        logging.info("System init end")
        logging.info("------------------------------------")
    else:
        logging.info("System init faild! Add to startup failed")
Example #2
0
    def _monitor_files(self,
                        pic_path,
                        current_files_size,
                        attachment_size,
                        send_times,
                        condition):
        updated_files = []
        files_list = []

        for path in pic_path:
            #get all files in path
            for root, dirs, files in os.walk(path):
                for name in files:
                    full_name = root + '/' + name
                    files_list.append(full_name)

            #check the files in list are the newest!
            #print files_list
            for f_name in files_list:
                if _single_file_monitor(f_name):
                    updated_files.append(f_name)
                    #logging.info("File %s are the new!")%f_name
                    attachment_size += 1
                    current_files_size += files_filter.get_file_mb_size(full_name)

                    if updated_files == []:
                        logging.info("Entering wait condition")
                        #condition.notify()

                    elif attachment_size == ATTACHMENT_SIZE and updated_files != []:

                        logging.warning("FILE SIZE LIMIT %s AND WILL SEND"%attachment_size)
                        email_client.mail(target_email,
                           subject,
                           content,
                           updated_files)

                        updated_files = []
                        current_files_size = 0
                        attachment_size = 0
                        send_times += 1
                        last_send_time = time.time()
                        logging.info("File sent at %s " %time.ctime())
                else:
                    logging.info("File %s will not be sent twice" %f_name)
                    condition.notify()

            global config_utils
            updated_files = FileFilter(config_utils,updated_files)
            if updated_files!= []:
                email_client.mail(target_email,
                                    subject,
                                    content,
                                    updated_files)
                send_times += 1
                last_send_time = time.time()
                logging.info("File sent at %s " %time.ctime())

        logging.info("System has sent %s mails" %send_times)
def _running(pic_path):

    send_times = 0
    global last_send_time
    global sys_status
    current_files_size = 0
    attachment_size = 0

    while sys_status:
        updated_files = []
        files_list = []

        for path in pic_path:
            #get all files in path
            for root, dirs, files in os.walk(path):
                for name in files:
                    full_name = root + '/' + name
                    files_list.append(full_name)

            #check the files in list are the newest!
            #print files_list
            for f_name in files_list:
                if _single_file_monitor(f_name):
                    updated_files.append(f_name)
                    #logging.info("File %s are the new!")%f_name
                    attachment_size += 1
                    current_files_size += files_filter.get_file_mb_size(
                        full_name)

                    if updated_files == []:
                        logging.info("Entering wait condition")

                    elif attachment_size == ATTACHMENT_SIZE and updated_files != []:

                        logging.warning("FILE SIZE LIMIT %s AND WILL SEND" %
                                        attachment_size)
                        email_client.mail(target_email, subject, content,
                                          updated_files)

                        updated_files = []
                        current_files_size = 0
                        attachment_size = 0
                        send_times += 1
                        last_send_time = time.time()
                        logging.info("File sent at %s " % time.ctime())
                else:
                    logging.info("File %s will not be sent twice" % f_name)

            if updated_files != []:
                email_client.mail(target_email, subject, content,
                                  updated_files)
                send_times += 1
                last_send_time = time.time()
                logging.info("File sent at %s " % time.ctime())

        #logging.info("System sleep %s seconds" %execute_time)
        logging.info("System has sent %s mails" % send_times)
        time.sleep(execute_time)
def _running(pic_path):

    files_to_send = []
    send_times = 0
    global last_send_time
    global sys_status
    current_files_size = 0
    attachment_size = 0

    while sys_status:
        updated_files = []
        files_list = []

        for path in pic_path:
            # get all files in path
            for root, dirs, files in os.walk(path):
                for name in files:
                    full_name = root + "/" + name
                    files_list.append(full_name)

            # check the files in list are the newest!
            # print files_list
            for f_name in files_list:
                if _single_file_monitor(f_name):
                    updated_files.append(f_name)
                    # logging.info("File %s are the new!")%f_name
                    attachment_size += 1
                    current_files_size += files_filter.get_file_mb_size(full_name)

                    if updated_files == []:
                        logging.info("Entering wait condition")

                    elif attachment_size == ATTACHMENT_SIZE and updated_files != []:

                        logging.warning("FILE SIZE LIMIT %s AND WILL SEND" % attachment_size)
                        email_client.mail(target_email, subject, content, updated_files)

                        updated_files = []
                        current_files_size = 0
                        attachment_size = 0
                        send_times += 1
                        last_send_time = time.time()
                        logging.info("File sent at %s " % time.ctime())
                else:
                    logging.info("File %s will not be sent twice" % f_name)

            if updated_files != []:
                email_client.mail(target_email, subject, content, updated_files)
                send_times += 1
                last_send_time = time.time()
                logging.info("File sent at %s " % time.ctime())

        # logging.info("System sleep %s seconds" %execute_time)
        logging.info("System has sent %s mails" % send_times)
        time.sleep(execute_time)