def __init__(self): self.devices = {} self.daemon = Daemon(self) self.build_device_tree() self.opt = Operation(self) self.gui = DeviceManagerGUI(self) self.server = False
def setUpClass(self): self.servConfig = ServerConfig() ds = DataServer("MediaArchiver.db", False) self.daemon = Daemon(self.servConfig, ds) self.client = "test:0000" self.size = 0 return super().setUpClass()
def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null', log=None): Daemon.__init__(self, pidfile, stdin, stdout, stderr) self.logger = log
def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null', withDb=False): Daemon.__init__(self, pidfile, stdin, stdout, stderr) self.withDb = withDb
def __init__(self, pid): Daemon.__init__(self, pid) # Reddit https://praw.readthedocs.io/en/stable/pages/comment_parsing.html self.reddit = {} self.default_subs = 'pollster_bot' self.bot_name = 'pollster_bot' self.version = '1.0' self.touched_comment_ids = [] # create logger self.logger = logging.getLogger('Pollster_Bot') self.logger.setLevel(logging.INFO) # File handler set to DEBUG fh = logging.FileHandler(filename=os.path.join( os.path.dirname(__file__), 'PollsterBotLog.txt')) fh.setLevel(logging.DEBUG) # create console handler and set level to debug ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) # create formatter formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') # add formatter to ch ch.setFormatter(formatter) fh.setFormatter(formatter) # add ch, fh to logger self.logger.addHandler(ch) self.logger.addHandler(fh) self.lock = Lock() self.logger.info('Starting Pollster Bot ver. ' + self.version) # Huffington post http://elections.huffingtonpost.com/pollster/api self.uri = 'http://elections.huffingtonpost.com/pollster/api/charts.json' # Set states self.states = {} self.states = self.load_json_file('data/states.json') # phrases phrases = self.load_json_file('data/phrases.json') self.greetings = phrases['greeting'] self.winning = phrases['winning'] self.losing = phrases['losing'] # keywords to call the pollster bot self.keywords = self.load_json_file('data/keywords.json')['keywords'] # subs subs = self.load_json_file('data/subs.json')['subs'] for sub in subs: self.default_subs += '+' + sub self.log_in_credentials = self.load_json_file( 'data/login_credentials.json')
def __init__(self,\ config_file_path,\ default_values,\ keys_match,\ command_line_match): Daemon.__init__(self,\ config_file_path,\ default_values,\ keys_match,\ command_line_match,\ CompilerDaemonConfiguration.check_values) os.chdir(self.get_config()["temp_dir"]) tempfile.tempdir = self.get_config()["temp_dir"]
def __init__(self, srvName, srvDesc, defCfgFilePath): Singleton.__init__(self) self.workDir = None self.cfgFilePath = None # used by relativePath self.workDir = self.workDir or os.getcwd() self.appDir = os.path.dirname(sys.argv[0]) self.action = self._parseArgs() # what to do pidFilePath = '%s.pid' % self.relativePath(self.workDir, srvName) Daemon.__init__(self, pidFilePath, srvDesc) self.cfgFilePath = self.cfgFilePath or self.relativePath( self.appDir, defCfgFilePath) self.daemonMode = False self.signalMutex = threading.Lock() # signal processing flag
def __init__( self ): self.devices = {} self.daemon = Daemon( self ) self.build_device_tree() self.opt = Operation( self ) self.gui = DeviceManagerGUI( self ) self.server = False
def __init__(self, local_host = "localhost", local_port = 8080, remote_host = "http://localhost:5984", key_file = None, cert_file = None, logger=None, pid_file = "/tmp/couchproxy.pid"): # Construction business Daemon.__init__(self, pid_file) self.logger = logger # Configure the handler self.handler = CouchProxyHandler self.handler.remote_address = remote_host self.handler.client = CouchProxyRequest(remote_host, key_file=key_file, cert_file=cert_file) self.handler.logger = self.logger # Configure the server self.server_address = (local_host, local_port)
def __init__(self): Daemon.__init__(self, pidfile="Bubble_PID", stdout="bubble_stdout.txt", stderr="bubble_stderr.txt") GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) subprocess.call(["sudo", "modprobe", "w1-gpio"]) subprocess.call(["sudo", "modprobe", "w1-therm"]) self.logger = Logger("Bubble", ".", "bubble.log") self.oneTime = 0 self.fiveTime = 0 self.fithteenTime = 0.0 self.oneMinStats = 0 self.fiveMinStats = 0 self.fithteenMinStats = 0 self.oneT = time.time() self.fiveT = time.time() self.fithteenT = time.time() self.oneFile = open("Fermantation/OneMinLog.tsv", 'a') self.fiveFile = open("Fermantation/FiveMinLog.tsv", 'a') self.fithteenFile = open("Fermantation/FithteenMinLog.tsv", 'a')
def __init__(self, local_host="localhost", local_port=8080, remote_host="http://localhost:5984", key_file=None, cert_file=None, logger=None, pid_file="/tmp/couchproxy.pid"): # Construction business Daemon.__init__(self, pid_file) self.logger = logger # Configure the handler self.handler = CouchProxyHandler self.handler.remote_address = remote_host self.handler.client = CouchProxyRequest(remote_host, key_file=key_file, cert_file=cert_file) self.handler.logger = self.logger # Configure the server self.server_address = (local_host, local_port)
def __init__(self): Daemon.__init__(self, pidfile="OpticBubble_PID", stdout="bubble_stdout.txt", stderr="bubble_stderr.txt") GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.OUT) self.bus = smbus.SMBus(1) subprocess.call(["sudo", "modprobe", "w1-gpio"]) subprocess.call(["sudo", "modprobe", "w1-therm"]) self.logger = Logger("OpticBubble", ".", "bubble.log") self.oneTime = 0 self.fiveTime = 0 self.fithteenTime = 0.0 self.oneMinStats = 0 self.fiveMinStats = 0 self.fithteenMinStats = 0 self.oneT = time.time() self.fiveT = time.time() self.fithteenT = time.time() self.oneFile = open("Fermentation/OneMinLog.tsv", 'a') self.fiveFile = open("Fermentation/FiveMinLog.tsv", 'a') self.fithteenFile = open("Fermentation/FithteenMinLog.tsv", 'a')
def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null', redis=None): cfgfile = os.environ.get('AMLST_SETTINGS',False) self.pdir = os.path.dirname(os.path.realpath(__file__)) if not cfgfile and os.path.exists(os.path.join(self.pdir,"webapp","config","active_config.py")): cfgfile = os.path.join(self.pdir,"webapp","config","active_config.py") else: print "Could not find config. Set 'ARTS_SETTINGS' env var to config location. ex:\nexport ARTS_SETTINGS='/home/user/artsapp.cfg'" exit(1) with open(cfgfile,'r') as fil: self.config = {x.split("=")[0].strip().upper():x.split("=",1)[1].strip().strip('"').strip("'") for x in fil if '=' in x and not x.startswith('#')} #check refdir and results folder default to local temp = self.config.get("REF_FOLDER",os.path.join(self.pdir,"reference")) if os.path.exists(temp): self.config["REF_FOLDER"] = temp else: print "Could not find reference folder. Check config" exit(1) temp = self.config.get("RESULTS_FOLDER",os.path.join(self.pdir,"results")) if os.path.exists(temp): self.config["RESULTS_FOLDER"] = temp else: print "Could not find results folder. Storing in /tmp" self.config["RESULTS_FOLDER"] = "/tmp" Daemon.__init__(self,pidfile) if not redis: redis = self.config.get("REDISURL","redis://localhost:6379/0") self.redis = Redis.from_url(redis) self.runningjob = None #Set logging self.log = logging.getLogger("automlstdaemon") formatter = logging.Formatter(fmt='%(asctime)s - %(levelname)s - %(module)s - %(message)s') handler = RotatingFileHandler("%s.log"%pidfile, mode='a', maxBytes=5*1024*1024, backupCount=2, encoding=None, delay=0) handler.setFormatter(formatter) self.log.addHandler(handler) self.log.setLevel(logging.DEBUG)
def getDaemon(self, name="unknown", sslorg=None, ssluser=None, sslkeyvaluestor=None): """ is the basis for every daemon we create which can be exposed over e.g. zmq or sockets or http daemon=j.servers.base.getDaemon() class MyCommands: def __init__(self,daemon): self.daemon=daemon #session always needs to be there def pingcmd(self,session=session): return "pong" def echo(self,msg="",session=session): return msg daemon.addCMDsInterface(MyCommands,category="optional") #pass as class not as object !!! chose category if only 1 then can leave "" #now you need to pass this to a protocol server, its not usable by itself """ zd = Daemon(name=name) if ssluser: zd.ssluser = ssluser zd.sslorg = sslorg zd.keystor = j.sal.ssl.getSSLHandler(sslkeyvaluestor) try: zd.keystor.getPrivKey(sslorg, ssluser) except: zd.keystor.createKeyPair(sslorg, ssluser) else: zd.keystor = None zd.ssluser = None zd.sslorg = None return zd
class DeviceManager(object): def __init__(self): self.devices = {} self.daemon = Daemon(self) self.build_device_tree() self.opt = Operation(self) self.gui = DeviceManagerGUI(self) self.server = False def update(self): self.daemon.update() self.build_device_tree() def build_device_tree(self): for k, device in self.devices.items(): if str(device.get("parent")) == 'None': self.devices["root"] = device else: self.devices[device.get("parent")].append_child(device) print "build tree done!" def append_device(self, device): self.devices[str(device.udi)] = device def update_device(self, device): self.devices[str(device.udi)] = device def get_device(self, udi): return self.devices[str(udi)] def get_device_product(self, udi): return self.devices[udi].get("product") #def loop( self ): # import threading # self.threads = [] # self.threads.append( threading.Thread( target = self.daemon.loop ) ) # for t in self.threads: # t.start() def notify(self, title, info): self.daemon.notify(title, info) def send(self, cmd, title=None, info_succ=None, info_fail=None): self.daemon.send(cmd, title, info_succ, info_fail) def quit(self): sys.exit(0)
class DeviceManager( object ): def __init__( self ): self.devices = {} self.daemon = Daemon( self ) self.build_device_tree() self.opt = Operation( self ) self.gui = DeviceManagerGUI( self ) self.server = False def update(self): self.daemon.update() self.build_device_tree() def build_device_tree( self ): for k, device in self.devices.items(): if str( device.get( "parent" ) ) == 'None': self.devices["root"] = device else: self.devices[device.get( "parent" )].append_child( device ) print "build tree done!" def append_device( self, device ): self.devices[str( device.udi )] = device def update_device( self, device ): self.devices[str( device.udi )] = device def get_device( self, udi ): return self.devices[str( udi )] def get_device_product( self, udi ): return self.devices[udi].get( "product" ) #def loop( self ): # import threading # self.threads = [] # self.threads.append( threading.Thread( target = self.daemon.loop ) ) # for t in self.threads: # t.start() def notify( self, title, info ): self.daemon.notify( title, info ) def send( self, cmd, title = None, info_succ = None, info_fail = None ): self.daemon.send( cmd, title, info_succ, info_fail ) def quit( self ): sys.exit( 0 )
class Test_TestDaemon(unittest.TestCase): @classmethod def setUpClass(self): self.servConfig = ServerConfig() ds = DataServer("MediaArchiver.db", False) self.daemon = Daemon(self.servConfig, ds) self.client = "test:0000" self.size = 0 return super().setUpClass() def test_ReadFile1(self): id, size = self.daemon.GetNextFile(500*1024*1024, self.client) fh = open("tmp.bin", 'wb') currLen = 0 while currLen < size: data = self.daemon.GetFileData(self.client) fh.write(data) currLen = currLen + len(data) fh.close() Test_TestDaemon.size = currLen print ("Uploading...") def test_WriteFile1(self): fh = open("tmp.bin", 'rb') self.daemon.PutFile(EncodingResult(0, Test_TestDaemon.size, ""), self.client) currLen = 0 chunk = 16384 while True: data = fh.read(chunk) self.daemon.PutFileData(data, self.client) if len(data) < chunk: break currLen = currLen + len(data) fh.close() print ("Uploading finished") self.daemon._LoopInside()
def __init__(self, pidfile, inifile, stdin="/dev/null", stdout="/dev/null", stderr="/dev/null"): Daemon.__init__(self, pidfile, stdin, stdout, stderr) self.inifile = inifile
def __init__(self, pidfile, stdin="/dev/null", stdout="/dev/null", stderr="/dev/null", log=None): Daemon.__init__(self, pidfile, stdin, stdout, stderr) self.logger = log
def __init__(self, pidfile, stdin='/dev/null', stdout='/tmp/l1ccalib/std.txt', stderr='/tmp/l1ccalib/err.txt'): Daemon.__init__(self, pidfile, stdin, stdout, stderr)
def __init__(self, name): Application.__init__(self, name, facility='daemon') Stager.__init__(self) ComponentHarness.__init__(self) return
continue if daemon: if not path.isfile(dbName): logger.debug("No Database found") noExistingDB = True forceSearchFiles = True servConfig = ServerConfig() ds = DataServer(dbName, noExistingDB) if daemonize: #with Daemonizer() as (is_setup, daemonizer): # if is_setup: # # This code is run before daemonization. # pass #do_things_here() # # We need to explicitly pass resources to the daemon; other variables # # may not be correct # is_parent = daemonizer(environ["TMP"]+"\\MediaArchiverDaemon.pid") # if is_parent: # # Run code in the parent after daemonization # logger.debug("Main process exit...") # sys.exit() pass # We are now daemonized, and the parent just exited. daemon = Daemon(servConfig, ds) daemon.Main(forceSearchFiles)
# print 'You pressed Ctrl+C!' sys.exit(0) p = pyaudio.PyAudio() stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=2048) stream2 = p.open(format = p.get_format_from_width(f.getsampwidth()), channels = f.getnchannels(), rate = f.getframerate(), output = True) #read data data = f.readframes(chunk) stream.start_stream() in_speech_bf = False decoder.start_utt() daemon = Daemon() daemon.run() signal.signal(signal.SIGINT, signal_handler) go = False while True: buf = stream.read(chunk) if buf: decoder.process_raw(buf, False, False) if decoder.get_in_speech() != in_speech_bf: in_speech_bf = decoder.get_in_speech() if not in_speech_bf: decoder.end_utt() result = decoder.hyp().hypstr #print('Result:[%s]' %result) if go == True: if result == "list":
def __init__(self, pidfile): Daemon.__init__(self, pidfile) self._cpu = False self._network = False self._memory = False
def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null', withDb=False): Daemon.__init__(self,pidfile,stdin,stdout,stderr) self.withDb = withDb
def daemon(name=None): from Daemon import Daemon return Daemon(name)
def __init__(self): Daemon.__init__(self, pidfile='/tmp/floucapt.pid', stdout='/tmp/floucapt.log', stderr='/tmp/floucapt.error') self.quit = False self.logger = Logger() self.cleaner = Cleaner()
def __init__(self, **kwargs): self.serverProcess = None Daemon.__init__(self, **kwargs)
from Daemon import Daemon from BatchListener import BatchListener import logging logging.basicConfig(level=logging.DEBUG, format='[%(levelname)s] %(asctime)s %(name)s - %(module)s.%(funcName)s, %(message)s') daemon = Daemon() daemon += BatchListener() daemon.start()
def __init__(self): Daemon.__init__(self, pidfile="Runner_PID", stdout="runner_stdout.txt", stderr="runner_stderr.txt") self.logger = Logger("Runner", ".", "runner.log")
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=2048) stream2 = p.open(format=p.get_format_from_width(f.getsampwidth()), channels=f.getnchannels(), rate=f.getframerate(), output=True) #read data data = f.readframes(chunk) stream.start_stream() in_speech_bf = False decoder.start_utt() daemon = Daemon() daemon.run() signal.signal(signal.SIGINT, signal_handler) go = False while True: buf = stream.read(chunk) if buf: decoder.process_raw(buf, False, False) if decoder.get_in_speech() != in_speech_bf: in_speech_bf = decoder.get_in_speech() if not in_speech_bf: decoder.end_utt() result = decoder.hyp().hypstr #print('Result:[%s]' %result) if go == True: if result == "list":
def __init__(self): Daemon.__init__(self, pidFile) Rotater.__init__(self)
def main(): logging.basicConfig(level=logging.INFO, handlers=[logging.StreamHandler()]) sevr = Daemon() sevr.run()
from Daemon import Daemon import sys if len(sys.argv) >= 2: ip = sys.argv[1] else: ip = "127.0.0.2" daemon = Daemon(ip) daemon.start()