Example #1
0
 def record(self):
     if type(self.option['logfile']) == str:
         log.basicConfig(filename=self.option['logfile'])
     log.info('started ' + self.option['input'])
     if self.option['workdir'] != None and os.getenv('PWD') != self.option['workdir']:
         log.info('Cambiando al directorio ' + self.option['workdir'])
         os.chdir(self.option['workdir'])
     logfile = open(self.option['logfile'],'a')
     while 1:
         i = 1
         while not self.test_camara():
             self.OK = False
             time.sleep(5 * i)
             if i < 12:
                 i += 1
             log.error('intentando reconectar...')
         self.OK = True
         av_options = [self.AV]
         av_options += ['-loglevel 16 -i ' + self.option['input']+' -map 0'] 
         # opciones para  flujos
         try: # aƱadimos la fecha
             gr = re.match('((.*/)*)*(.+)(\..+)',self.option['output']).groups()
             output = gr[-2]+'['+self.fecha()+']'+gr[-1]
         except:
             output = self.option['output']
         av_options += [output]
         # tiempo
         if self.option['timerecord'] != None:
             av_options += ['-t '+str(self.option['timerecord'])+":00:00"]
         print(' '.join(av_options))
         log.info('Iniciando la grabaciĆ³n')
         err = subprocess.call(' '.join(av_options), stdout=logfile, stderr=logfile, shell=True)
     logfile.close()
     if type(self.option['logfile']) == str:
         log.close()
Example #2
0
    def shutdown(self):
        """
        Shutdown subsytems before stopping.

        """
        # self.f.close()
        logging.close()
        self.tracker.kill_sensor()
        self.motion.join()
        self.location.join()  # shut this down last
Example #3
0
    def shutdown(self):
        """
        Shutdown subsytems before stopping.

        """
        # self.f.close()
        logging.close()
        self.tracker.kill_sensor()
        self.motion.join()
        self.location.join()  # shut this down last
Example #4
0
 def exec_com(self, cycle, i, logging):
     s_checkcm = self.get_checkcom(cycle, i, logging)
     for n in s_checkcm:
         type = n[0]
         com = n[1]
         logging.info(com)
         ex_result = self.sock_fn(i, com, logging)
         a = self.insert_checkresult(i, type, ex_result, logging)
         logging.info("check data insert database status:" + str(a))
     #print(logging.echo_h)
     logging.close()
Example #5
0
 def sock_fn(self, host, command, logging):
     sk = socket.socket()
     port = 9527
     s_command = bytes(command)
     try:
         sk.connect((host, port))
         sk.send(s_command)
         result = str(sk.recv(1024))
         result = result.split('|')
         check_status = result[0]
         check_result = result[1]
         logging.info(check_status)
         logging.info(check_result)
     except:
         logging.close()
         logging.error(traceback.print_exception(*sys.exc_info()))
     sk.close()
     return check_result
Example #6
0
            #p.map(run_single_block,block_input_list)
            time_lists = p.map(run_single_block, block_input_list)
            #p.close()
            #p.terminate()
            #p.join()

        for i, input_list in enumerate(block_input_list):
            baseName = input_list[0]
            gw_time, ev_time, ps_time = time_lists[i]
            log.write('%s\t%s\t%s\t%s\n' %
                      (baseName, str(gw_time), str(ev_time), str(ps_time)))
            #    print('%s\t%s\t%s\t%s\n'%(baseName,str(gw_time),str(ev_time),str(ps_time)))
        pred_end_time = datetime.datetime.now()
        print("Prediction used time: {}".format(pred_end_time -
                                                pred_start_time))
    log.close()
    out_file = '%s/%s.predicted.txt' % (out_dir, name)
    ww = open(out_file, 'w')
    if (DB_file is not None):
        ww.write('predicted_pasid\tdb_pasid\tdb_diff\tscore\n')
    else:
        ww.write('predicted_pasid\tscore\n')
    ww.close()
    os.system('cat %s/maxSum/*bidirection* >>%s' % (out_dir, out_file))
    if (keep_temp != 'yes'):
        os.system('rm -rf  %s/predict %s/maxSum' % (out_dir, out_dir))

    print("Job Done!")

#if __name__ == '__main__':
#    main(*args())
def main(out_dir, input_file, input_plus, input_minus, fa_file, keep_temp,
         window, name, model, rst, threshold, penality, DB_file, depth,
         thread):

    if (out_dir[-1] == '/'):
        out_dir = out_dir[0:-1]

    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    out_dir = out_dir + '/' + name
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    if input_file is not None:
        input_plus = input_file
        input_minus = input_file

    files = (input_plus, input_minus)
    strands = ('+', '-')

    log = open('%s/%s.log' % (out_dir, name), 'w')
    for i in range(2):
        input_file = files[i]
        strand = strands[i]
        print("Processing %s strand" % strand)
        blocks = Get_block_position(out_dir, input_file, strand, window, 1e6)
        block_input_list = []
        for chromosome, strand, block_num, start, end in blocks:
            baseName = '%s.%s_%s_%s' % (name, chromosome, strand, block_num)
            print('%s\t%d\t%d' % (baseName, start, end))
            block_input_list.append([
                baseName, model, out_dir, rst, window, keep_temp, threshold,
                penality, DB_file, input_file, chromosome, strand, fa_file,
                depth, start, end
            ])
        print("Predicting results ...")
        pred_start_time = datetime.datetime.now()
        #block_out_indic = []

        with Pool(thread) as p:
            #p.map(run_single_block,block_input_list)
            time_lists = p.map(run_single_block, block_input_list)
            #p.close()
            p.terminate()
            p.join()

            for i, input_list in enumerate(block_input_list):
                baseName = input_list[0]
                gw_time, ev_time, ps_time = time_lists[i]
                log.write('%s\t%s\t%s\t%s\n' %
                          (baseName, str(gw_time), str(ev_time), str(ps_time)))
            #	print('%s\t%s\t%s\t%s\n'%(baseName,str(gw_time),str(ev_time),str(ps_time)))

        pred_end_time = datetime.datetime.now()
        print("Prediction used time: {}".format(pred_end_time -
                                                pred_start_time))

    log.close()
    out_file = '%s/%s.predicted.txt' % (out_dir, name)
    ww = open(out_file, 'w')
    if (DB_file is not None):
        ww.write('predicted_pasid\tdb_pasid\tdb_diff\tscore\n')
    else:
        ww.write('predicted_pasid\tscore\n')
    ww.close()
    os.system('cat %s/maxSum/*bidirection* >>%s' % (out_dir, out_file))
    if (keep_temp != 'yes'):
        os.system('rm -rf  %s/predict %s/maxSum' % (out_dir, out_dir))

    print("Job Done!")
Example #8
0
def close_log():
	"""Closes logging."""
	logging.close()
Example #9
0
            if record[GID] is None:	
                log("Null GID, skipping")
                continue
            
            process_city(record[GID], record[CITY_NAME], record[CV_HULL], record[XMIN:], location)

        except AssertionError as e:
            log(e)
        except Exception as e:
            log("Proccsing", record[CITY_NAME], "with error", str(e))

    del pgConn
    return len(records)



if __name__ == '__main__':

    servname = socket.gethostname()

    logging.start()
    
    log("Starting Green Cities on", servname)
    
    os.chdir(settings.TEMP_FILE_DIR)

    try:
        proc = main('all')
    finally:
        logging.close()