示例#1
0
import time
import multiprocessing
import cloud_router
import cloud_data_proc
import cloud_forward
import cloud_reg_proc
from commands import getoutput as bash
from cloud_localconfig import *


if __name__ == '__main__':
    bash('mkdir '+LOCAL_DIR)
    funcs = [cloud_router.run,
         cloud_data_proc.run,
         cloud_forward.run,
         cloud_reg_proc.run]
    process_list = {}
    #start all the processes
    for procs in funcs:
        process_list[procs] = multiprocessing.Process(target = procs)
        process_list[procs].start()

    #auto restart processes if they die
    while 1:
        time.sleep(5)
        print time.asctime(), "I am alive and watching..."
        for procs in process_list:
            if process_list[procs].is_alive() == False:
                print procs
                process_list[procs] = multiprocessing.Process(target = procs)
                process_list[procs].start()
示例#2
0
from os.path import dirname, basename, isdir, realpath
from commands import getstatusoutput as bash

#
import os
verbose = not True
if not (  os.environ.get("koala_verbose",'') == '' or os.environ.get("koala_verbose",'').lower() == 'true'  ):
    verbose = False


# Search recurssively within the config's sim_dir for files matching the config's metadata_id
this_file = realpath(__file__)
if verbose: print "The highest level init for nrutils is located at: %s" % this_file
if this_file[-1] == 'c': this_file = this_file[:-1]
cmd = 'find %s -maxdepth 2 -name "__init__.py"' % dirname(this_file)
status, output = bash(cmd)

# make a list of all packages within the directory which contains this file
dir_list = output.split(chr(10))
internal_packages = [ basename(dirname(p)) for p in dir_list if not (p == this_file) ]

# Throw error is internal_packages is empty
if len(internal_packages) == 0:
    msg = '(!!) Unable to automatically find internal packages. Please report this bug to the developers. (https://github.com/llondon6/nrutils_dev/tree/master/nrutils)'
    raise ValueError(msg)

# Store package settings (useful directories etc) to a settings field
# NOTE that the __pathsfile__ variable is no longer used in favor of automatic directory assignments based in install location
# __pathsfile__ = [dirname(realpath(__file__))+'/settings/paths.ini']

# The instal path will be stored, but not used here. NOTE that the paths.ini file is technically not
示例#3
0
from commands import getstatusoutput as bash

#
import os
verbose = not True
if not (os.environ.get("koala_verbose", '') == ''
        or os.environ.get("koala_verbose", '').lower() == 'true'):
    verbose = False

# Search recurssively within the config's sim_dir for files matching the config's metadata_id
this_file = realpath(__file__)
if verbose:
    print "The highest level init for nrutils is located at: %s" % this_file
if this_file[-1] == 'c': this_file = this_file[:-1]
cmd = 'find %s -maxdepth 2 -name "__init__.py"' % dirname(this_file)
status, output = bash(cmd)

# make a list of all packages within the directory which contains this file
dir_list = output.split(chr(10))
internal_packages = [
    basename(dirname(p)) for p in dir_list if not (p == this_file)
]

# Throw error is internal_packages is empty
if len(internal_packages) == 0:
    msg = '(!!) Unable to automatically find internal packages. Please report this bug to the developers. (https://github.com/llondon6/nrutils_dev/tree/master/nrutils)'
    raise ValueError(msg)

# Store package settings (useful directories etc) to a settings field
# NOTE that the __pathsfile__ variable is no longer used in favor of automatic directory assignments based in install location
# __pathsfile__ = [dirname(realpath(__file__))+'/settings/paths.ini']
示例#4
0
def num_lines_to_process():
    # Get number of lines that have been processed
    num_lines = int(bash("cat /tmp/wag/lines_processed.in"))
    return num_lines
示例#5
0
def touch(inst_id):
    bash("touch " + inst_id)
示例#6
0
    with open(fname) as f:
        try:
            for i, l in enumerate(f):
                pass
            return i + 1
        except:
            return 0
    return 0

on_break = False
sleep_time = 1.0
i = 0


#create local directory if not present.
bash('mkdir '+LOCAL_DIR)
bash('mkdir '+WORKING_CACHE_DIR)
bash('touch '+SENSOR_DATA_EXCHANGE_FILE)
bash("touch"+COUNTER_FILE)
#bash("echo '0' > "+COUNTER_FILE)


while 1:
    time.sleep(0.01)
    #checking how many lines have been processed
    try:
        linecache.checkcache(COUNTER_FILE)
        lines_proc = int(linecache.getline(COUNTER_FILE, 1))
        print lines_proc
    except:
        bash("echo '0' > "+COUNTER_FILE)