def __init__ (self): log.initialize_logging('BlockKeys') self.logger = logging.getLogger('BlockKeys') self.logger.debug("blocking keys") self.keylist = {} self.blockkeys = ['f1','f2','f3','f4','f5','f6','f7','f8','f9','f10', 'f11','f12','escape','lwin','rwin','lmenu','rmenu']
def main(self): # config config_file_name = 'conf/config.json' try: with open(config_file_name) as config_data: configs = json.load(config_data) except: print('failed to load config from config.json.') return # log init log.initialize_logging(configs['enable_log'].lower() == 'true') log.info('Main: start') # threads self.basestation_server = BaseStationThread( ('localhost', configs['basestation_port']), BaseStationHandler(self.got_data_cb)) server_thread = threading.Thread( target=self.basestation_server.serve_forever) server_thread.setDaemon(True) server_thread.start() self.basestation_server.serve_forever() self.controller = ControlThread(configs['control_port'], self.got_command_cb) self.dispatcher = DispatcherThread() self.gps_server = GPSThread(configs['gps_port'], self.got_client_cb) #self.basestation_server.start() self.controller.start() self.dispatcher.start() self.gps_server.start() # keyboard try: print("enter 'q' to quit") while input() != 'q': print("enter 'q' to quit. rcv count: %d, client count: %d" % (self.basestation_server.recv_count, len(self.dispatcher.clients))) if not self.basestation_server.running or not self.gps_server.running: break except KeyboardInterrupt: pass # quit & clean up self.controller.running = False self.controller.join() self.basestation_server.running = False #self.basestation_server.join() self.gps_server.running = False self.gps_server.join() self.dispatcher.running = False self.dispatcher.join() log.info('Main: bye')
def main(self): # config config_file_name = 'conf/config.json' try: with open(config_file_name) as config_data: configs = json.load(config_data) except: print ('failed to load config from config.json.') return # log init log.initialize_logging(configs['enable_log'].lower() == 'true') log.info('Main: start') # threads self.basestation_server = BaseStationThread(('localhost', configs['basestation_port']), BaseStationHandler(self.got_data_cb)) server_thread = threading.Thread(target=self.basestation_server.serve_forever) server_thread.setDaemon(True) server_thread.start() self.basestation_server.serve_forever() self.controller = ControlThread(configs['control_port'], self.got_command_cb) self.dispatcher = DispatcherThread() self.gps_server = GPSThread(configs['gps_port'], self.got_client_cb) #self.basestation_server.start() self.controller.start() self.dispatcher.start() self.gps_server.start() # keyboard try: print("enter 'q' to quit") while input() != 'q': print("enter 'q' to quit. rcv count: %d, client count: %d" % (self.basestation_server.recv_count, len(self.dispatcher.clients))) if not self.basestation_server.running or not self.gps_server.running: break except KeyboardInterrupt: pass # quit & clean up self.controller.running = False self.controller.join() self.basestation_server.running = False #self.basestation_server.join() self.gps_server.running = False self.gps_server.join() self.dispatcher.running = False self.dispatcher.join() log.info('Main: bye')
def main(): """主函数""" # config script_dir = os.path.join(os.path.dirname(watcher.__file__), os.path.pardir) root_dir = os.path.abspath(os.path.join(script_dir, os.path.pardir)) config_file_name = os.path.abspath( os.path.join(os.path.join(root_dir, 'conf'), 'watcher_config.json')) configs = load_config(config_file_name) if configs is None: return # log init enable_log = configs.get('enableLog', 'True').lower() == 'true' log_path = os.path.abspath(os.path.join(root_dir, 'logs')) log.initialize_logging('watcher', log_path, enable_log) log.info('watcher main: start') warn.initialize_warn(configs['httpServer']) # threads mail_sender = MailSenderThread(configs['email']) file_checker = FileCheckerThread(configs['httpServer'], configs['files']) mail_sender.start() file_checker.start() # keyboard try: print("enter 'q' to quit") while input() != 'q': print("enter 'q' to quit.") except KeyboardInterrupt: pass # quit & clean up mail_sender.running = False file_checker.running = False mail_sender.join() file_checker.join() warn.stop_warn() log.info('watcher main: bye')
def main(): """主函数""" # config script_dir = os.path.join(os.path.dirname(watcher.__file__), os.path.pardir) root_dir = os.path.abspath(os.path.join(script_dir, os.path.pardir)) config_file_name = os.path.abspath(os.path.join(os.path.join(root_dir, 'conf'), 'watcher_config.json')) configs = load_config(config_file_name) if configs is None: return # log init enable_log = configs.get('enableLog', 'True').lower() == 'true' log_path = os.path.abspath(os.path.join(root_dir, 'logs')) log.initialize_logging('watcher', log_path, enable_log) log.info('watcher main: start') warn.initialize_warn(configs['httpServer']) # threads mail_sender = MailSenderThread(configs['email']) file_checker = FileCheckerThread(configs['httpServer'], configs['files']) mail_sender.start() file_checker.start() # keyboard try: print("enter 'q' to quit") while input() != 'q': print("enter 'q' to quit.") except KeyboardInterrupt: pass # quit & clean up mail_sender.running = False file_checker.running = False mail_sender.join() file_checker.join() warn.stop_warn() log.info('watcher main: bye')
def __init__(self): log.initialize_logging("SLController") self.logger = logging.getLogger("SLController") self.config = SLConfig() self.lockerProc = [] # determine if application is a script file or frozen exe if getattr(sys, 'frozen', False): application_path = os.path.dirname(sys.executable) self.app_init = [os.path.join(application_path, "screenlockApp.exe")] self.appname="screenlockApp.exe" elif __file__: application_path = os.path.dirname(__file__) self.app_init = ["python.exe", os.path.join(application_path, "screenlockApp.py")] self.appname="screenlockApp.py" self.logger.debug("Screenlock Controller Initialized, path: %s, appName: %s" % (application_path, self.appname))
def main(): """主函数""" # config script_dir = os.path.join(os.path.dirname(server.__file__), os.path.pardir) root_dir = os.path.abspath(os.path.join(script_dir, os.path.pardir)) config_file_name = os.path.abspath(os.path.join(os.path.join(root_dir, 'conf'), 'server_config.json')) configs = load_config(config_file_name) if configs is None: return # log init enable_log = configs.get('enableLog', 'True').lower() == 'true' log_path = os.path.abspath(os.path.join(root_dir, 'logs')) log.initialize_logging('server', log_path, enable_log) log.info('server main: start') warn_server_config = {'ipAddress': '127.0.0.1', 'port': configs['httpServer']['port']} warn.initialize_warn(warn_server_config) # threads http_server = HttpThread(configs['httpServer']) http_server.start() # keyboard try: print("enter 'q' to quit") while input() != 'q': print("enter 'q' to quit.") except KeyboardInterrupt: pass # quit & clean up warn.stop_warn() http_server.running = False http_server.shutdown() http_server.join() log.info('server main: bye')
def cleanup(): """ Clean expired builds in the image directory Builds are considered expired, when their age is more than config.keep_images hours. Returns: mixed -- Number of deleted images if successful or False if there was an error. """ from gluon import current import log logger = log.initialize_logging(current.request.folder, __name__) config = current.config out_dir = config.images_output_dir if not out_dir: logger.critical("Missing variable config.images_output_dir.") return False delete_before_time = time.time() - (config.keep_images * 3600) if os.access(out_dir, os.R_OK): i = 0 for filename in os.listdir(out_dir): dir = os.path.join(out_dir, filename) stat = os.stat(dir) if stat.st_mtime < delete_before_time: try: shutil.rmtree(dir) i = i + 1 except OSError: logger.error("Could not delete %s" % dir) if i == 0: logger.debug("Cleanup image dir: No builds deleted.") else: logger.info("Cleanup image dir: Deleted %s builds." % i) return i else: logger.warning("%s does not exist." % out_dir) return False
import os import re from gluon import current import log logger = log.initialize_logging(current.request.folder, __name__) class UCI(object): """ Class used to work with uci files. At this time only reading of uci files is supported Args: config_path: Path where the uci config files are stored config_file: filename of the config file """ def __init__(self, config_path="/etc/config", config_file="Freifunk"): self.Path = config_path self.File = config_file def read(self): """Reads a uci file into a nested tuple Note: this only works with named sections, i.e. it will work with config 'foo' 'bar' (bar is the name of the section here) but not with config 'foo' Returns: A nested tuple with all settings from the uci config, e.g.:
return def openKeysBlock (self): keyBlocker = blockKeys.BlockKeys() keyBlocker.beginBlocking() class NullProcess(object): def __init__(self): self.pid = False self.logger = logging.getLogger("NullProcess") def send_signal(self, sig): self.logger.error("NullProcess Received sig: %s" % sig) if __name__ == '__main__' : log.initialize_logging('screenlockApp') logger = logging.getLogger("Main Method") app = wx.App( False ) frm = OverlayFrame() frm.Show() frameController = ControlFrameThread() frameController.start() #taskmgrController = TaskManagerHider(frameController.logger) #taskmgrController.start() app.MainLoop() logger.debug("main loop exited") #taskmgrController.stopRunning()
import os import re from gluon import current import log logger = log.initialize_logging(current.request.folder, __name__) class UCI(object): """ Class used to work with uci files. At this time only reading of uci files is supported Args: config_path: Path where the uci config files are stored config_file: filename of the config file """ def __init__(self, config_path="/etc/config", config_file="Freifunk"): self.Path = config_path self.File = config_file def read(self): """Reads a uci file into a nested tuple Note: this only works with named sections, i.e. it will work with config 'foo' 'bar' (bar is the name of the section here) but not with config 'foo' Returns:
# This file is part of fail2ban-p2p. # # Licensed under the GNU GENERAL PUBLIC LICENSE Version 3. For details # see the file COPYING or http://www.gnu.org/licenses/gpl-3.0.en.html. import util import config import log import crypto import M2Crypto import json import util import version logger = log.initialize_logging("fail2ban-p2p." + __name__) class Command: ''' Handle command objects. Kwargs: * protocolVersion (int): Protocol version number * msgType (int): message type * parameter (dict): Parameters to send in the message * signature (string): The messages signature * hops (array): Hops that previously have relayed this message '''
if __name__ == "__main__": parser = argparse.ArgumentParser(description='fail2ban-p2p help.') parser.add_argument('-K', action='store_true', help='Create private/public keypair') parser.add_argument('-c', default='/etc/fail2ban-p2p/', help='Read configuration from DIR.', metavar='DIR') args = parser.parse_args() c = config.Config() c.configPath = args.c or "/etc/fail2ban-p2p" c.privkey = os.path.join(c.configPath, 'private.pem') c.pubkey = os.path.join(c.configPath, 'public.pem') if c.loadConfig() == False: raise OSError #, 'Config error, check log.' logger = log.initialize_logging("fail2ban-p2p") if args.K: crypto.create_keys() exit() # make sure the keys exist if not os.path.isfile(c.privkey) or not os.path.isfile(c.pubkey): logger.warning('Private or public key not found, creating them') crypto.create_keys() n = None try: n = node.Node() n.loadConfig() n.getFriends() n.requestBanlist()
import os import errno import subprocess from datetime import datetime try: import json except ImportError: import simplejson as json import shutil import mkutils from gluon.scheduler import Scheduler from gluon.fileutils import abspath import processupload import log logger = log.initialize_logging(request.folder, __name__) class BuildImages(object): """ This class is for configuring and building the images """ def __init__(self, row=None): """ Init Args: row -- a web2py DAL row (object) """ def _get(option): ret = None
@self.app.route('/enable', methods=['POST']) @self.requires_auth def enable(): return unlock() #Alias for lock @self.app.route('/disable', methods=['POST']) @self.requires_auth def disable(): return lock() #Alias for status @self.app.route('/sense', methods=['POST', 'GET']) @self.requires_auth def sense(): return status() @self.app.route('/version') def versionPath(): return json.dumps({"version": version.VERSION}) if __name__ == '__main__': PATH = os.path.dirname(os.path.abspath(sys.argv[0])) os.chdir(PATH) log.initialize_logging("screenlockServer") server = screenlockFlaskServer() server.run()
if self.readmeCheckbox.IsChecked(): path = self.config.get('post-install') os.startfile(path) self.logger.debug(str(datetime.now()) + ' Postinstall: post-install.txt Opened') if self.setPasswordCheckbox.IsChecked(): path = self.config.get('setAdminPsw') self.logger.debug( str(datetime.now()) + ' Postinstall: Set Passwords Opened' ) self.p = subprocess.Popen(path) try: if self.setCoralRadioBtn.GetValue(): self.config.writeKey('true','coral') self.logger.debug( str(datetime.now()) + ' Postinstall: \'coral\' has been updated to \'true\'') else: self.config.writeKey('false','coral') self.logger.debug(str(datetime.now()) + ' Postinstall: \'coral\' has been updated to \'false\'') except Exception, e: self.logger.debug(str(datetime.now()) + ' Postinstall: ' + str(e)) sys.exit() #=======================================================# if __name__ == '__main__' : log.create_log_folder() log.initialize_logging('postInstall') app = wx.App( False ) frm = PostInstallFrame() frm.Show() app.MainLoop()
import logging, sys import screenlockConfig,log,screenlockController from twisted.internet import protocol, reactor, endpoints log.initialize_logging("NCD Server") logger = logging.getLogger() class OptimisticCoralResponse(protocol.Protocol): #def __init__(self, *args, **kwargs): #self.lockControl = screenlockController.SLController() #super(protocol.Protocol, self).__init__(*args, **kwargs) def dataReceived(self, data): global lockControl global logger logger.debug("got a command! first byte: %s, second byte: %s" % (ord(data[0]), ord(data[1]))) response = 0 if ord(data[1]) == 17: #SENSE COMMAND logger.debug("sense command") if lockControl.is_running(): response = chr(0) else: response = chr(1) elif ord(data[1]) == 1: #TURN OFF COMMAND logger.debug("disable command") lockControl.lock_screen() response = chr(1) elif ord(data[1]) == 9: #TURN ON COMMAND logger.debug("enable command")
help='Create private/public keypair') parser.add_argument('-c', default='/etc/fail2ban-p2p/', help='Read configuration from DIR.', metavar='DIR') args = parser.parse_args() c = config.Config() c.configPath = args.c or "/etc/fail2ban-p2p" c.privkey = os.path.join(c.configPath, 'private.pem') c.pubkey = os.path.join(c.configPath, 'public.pem') if c.loadConfig() == False: raise OSError #, 'Config error, check log.' logger = log.initialize_logging("fail2ban-p2p") if args.K: crypto.create_keys() exit() # make sure the keys exist if not os.path.isfile(c.privkey) or not os.path.isfile(c.pubkey): logger.warning('Private or public key not found, creating them') crypto.create_keys() n = None try: n = node.Node() n.loadConfig() n.getFriends() n.requestBanlist()
import subprocess import sys try: import json except ImportError: import simplejson as json import shutil sys.path.append(os.path.join(request.folder, "private", "modules")) import mkutils import processupload import log import distutils from distutils.dir_util import copy_tree logger = log.initialize_logging(request.folder, 'build_queue') def mkdir_p(path): try: os.makedirs(path) return True except OSError, e: if e.errno == errno.EEXIST: pass else: logger.critical("Error: Could not create directory %s" % path) return False def cptree(src,dst): try: ct = copy_tree(src, dst, preserve_symlinks=0)
import os import errno import subprocess from datetime import datetime try: import json except ImportError: import simplejson as json import shutil import mkutils from gluon.scheduler import Scheduler from gluon.fileutils import abspath import processupload import log logger = log.initialize_logging(request.folder, __name__) class BuildImages(object): """ This class is for configuring and building the images """ def __init__(self, row=None): """ Init Args: row -- a web2py DAL row (object) """ def _get(option): ret = None try: ret = row[option] except KeyError:
import log import os import re import friend import hashlib import json import version from select import select from time import time import crypto import M2Crypto import customexceptions import validators logger = log.initialize_logging("fail2ban-p2p." + __name__) class Node: """Handles the self-awareness of the program.""" __shared_state = {} # config attributes uid = 0 name = "" addresses = [] port = 0 ownerMail = "" banTime = 0 # working attributes banList = []
import errno import subprocess import sys try: import json except ImportError: import simplejson as json import shutil sys.path.append(os.path.join(request.folder, "private", "modules")) import mkutils import processupload import log import distutils from distutils.dir_util import copy_tree logger = log.initialize_logging(request.folder, 'build_queue') def mkdir_p(path): try: os.makedirs(path) return True except OSError, e: if e.errno == errno.EEXIST: pass else: logger.critical("Error: Could not create directory %s" % path) return False def cptree(src, dst):