def main(): parser = OptionParser() parser.add_option("-V", "--verbose", action="store_true", dest="verbose", default=False, help="Print more informations") parser.add_option("-a", "--address", action="store_true", dest="address", default="127.0.0.1", help="TCP Bind ip address") parser.add_option("-p", "--port", action="store_true", dest="port", default=3000, help="TCP port to bind") parser.add_option("-c", "--config", action="store", type="string", dest="config", default=None, help="Json configuration file") parser.add_option("-v", "--value", action="append", nargs=2, type="string", dest="values", default=[], help="Configuration value") options, args = parser.parse_args() if not options.config: parser.error("You must supply a configuration file") loglevel = Logger.ERROR|Logger.WARN if options.verbose: loglevel |= Logger.INFO|Logger.DEBUG|Logger.DEBUG_2|Logger.DEBUG_3 Logger.initialize("WEBAPPS", loglevel, stdout=True) Logger.info("Start webapps") repo = ApplicationsRepository.initialize() SessionsRepository.debug = True sess = SessionsRepository.initialize() sess.start() repo.start() my_sess = {'id': 1, 'published_applications': (1, ), 'login':'******'} for k, v in options.values: my_sess[k] = v SessionsRepository.create(my_sess) SessionsRepository._instance.sessions[1].switch_status(Session.SESSION_STATUS_ACTIVE) server = WebAppsServer(options.address, int(options.port)) try: config = json.load(open(options.config, "r")) for k, v in options.values: config['Configuration'][k]['value'] = v app_id = 1 app_name = "app" appl = setup_app({"app":config}, app_id, app_name, "domain") if not appl: parser.error("Invalid parameters") appl.rule = re.compile('') ApplicationsRepository.register(appl) try: print "Connect to http://%s:%s/" % (options.address, options.port) asyncore.loop() except (InterruptedException, KeyboardInterrupt): Logger.info("interruption") finally: server.close() repo.stop() sess.stop()
def main(queue, config_file, pid_file): daemonize = bool(queue) def _exit(code, msg=''): if daemonize: queue.put((code, msg)) else: return (code, msg) if not Config.read( ConfigReader.process(config_file)) or not Config.is_valid(): return _exit(1, "wrong config file") Logger.initialize("OVD", Config.log_level, Config.log_file, not daemonize, Config.log_threaded) server = SlaveServer(Communication) signal.signal(signal.SIGINT, stop) signal.signal(signal.SIGTERM, stop) try: if pid_file is not None: try: f = open(pid_file, "w") f.write(str(os.getpid())) f.close() except IOError: raise InterruptedException( 2, "Unable to write pid-file '%s'" % pid_file) if not server.load_roles(): raise InterruptedException(3, "Cannot load some Roles") if not server.init(): raise InterruptedException(4, "Server initialization failed") except InterruptedException, e: code, msg = e.args return _exit(code, msg)
def main(queue, config_file, pid_file): daemonize = bool(queue) def _exit(code, msg=''): if daemonize: queue.put((code, msg)) else: return (code, msg) if not Config.read(ConfigReader.process(config_file)) or not Config.is_valid(): return _exit(1, "wrong config file") Logger.initialize("OVD", Config.log_level, Config.log_file, not daemonize, Config.log_threaded) server = SlaveServer(Communication) signal.signal(signal.SIGINT, stop) signal.signal(signal.SIGTERM, stop) try: if pid_file is not None: try: f = open(pid_file, "w") f.write(str(os.getpid())) f.close() except IOError: raise InterruptedException(2, "Unable to write pid-file '%s'" % pid_file) if not server.load_roles(): raise InterruptedException(3, "Cannot load some Roles") if not server.init(): raise InterruptedException(4, "Server initialization failed") except InterruptedException, e: code, msg = e.args return _exit(code, msg)
return None path_len = ctypes.c_uint(4096) path_buffer = ctypes.create_unicode_buffer(4096) status = self.dll.MsiGetComponentPathW(szProductCode.value, szComponentCode.value, ctypes.byref(path_buffer), ctypes.byref(path_len)) if status != self.INSTALLSTATE_LOCAL: Logger.debug2("MsiGetComponentPathW return %d on '%s'"%(status, path)) return None return path_buffer.value if __name__=='__main__': import sys if len(sys.argv) <2: print "Usage: %s file"%(sys.argv[0]) sys.exit(1) Logger.initialize("testMsi", Logger.INFO | Logger.WARN | Logger.ERROR | Logger.DEBUG, None, True, False) try: msi = Msi() except WindowsError,e: print "Unable to init Msi" sys.exit(1) for path in sys.argv[1:]: p = msi.getTargetFromShortcut(path) print " * path of %s is %s"%(path, str(p))
def SvcShutdown(self): # Reinit Logger because the Windows service manager logging system is already down Logger.initialize("OVD", Config.log_level, Config.log_file, False) Logger.info("Stopping SlaveServer (shutdown)") win32event.SetEvent(self.hWaitStop)