def __init__(self): self.start_scan=False self.cfg=sopdscfg.cfgreader() if not (self.cfg.SCAN_DAEMON or self.cfg.HTTP_DAEMON): print('Check configuration file. No daemons enabled.') sys.exit(0) self.logger = logging.getLogger('') self.logger.setLevel(self.cfg.LOGLEVEL) formatter=logging.Formatter('%(asctime)s %(levelname)-8s %(message)s') self.fh = logging.FileHandler(self.cfg.SCAND_LOGFILE) self.fh.setLevel(self.cfg.LOGLEVEL) self.fh.setFormatter(formatter) self.logger.addHandler(self.fh) self.logger.info('sopdsDaemon __init__()...') self.scanner=opdsScanner(self.cfg, self.logger) Daemon.__init__(self, self.cfg.PID_FILE, self.cfg.HTTPD_PID_FILE, '/dev/null', self.cfg.SCAND_LOGFILE,self.cfg.HTTPD_LOGFILE,self.cfg.SCAND_LOGFILE,self.cfg.HTTPD_LOGFILE, self.cfg.SCAN_DAEMON, self.cfg.HTTP_DAEMON)
def __init__(self): self.start_scan = False self.cfg = sopdscfg.cfgreader() if not (self.cfg.SCAN_DAEMON or self.cfg.HTTP_DAEMON): print('Check configuration file. No daemons enabled.') sys.exit(0) self.logger = logging.getLogger('') self.logger.setLevel(self.cfg.LOGLEVEL) formatter = logging.Formatter( '%(asctime)s %(levelname)-8s %(message)s') self.fh = logging.FileHandler(self.cfg.SCAND_LOGFILE) self.fh.setLevel(self.cfg.LOGLEVEL) self.fh.setFormatter(formatter) self.logger.addHandler(self.fh) self.logger.info('sopdsDaemon __init__()...') self.scanner = opdsScanner(self.cfg, self.logger) Daemon.__init__(self, self.cfg.PID_FILE, self.cfg.HTTPD_PID_FILE, '/dev/null', self.cfg.SCAND_LOGFILE, self.cfg.HTTPD_LOGFILE, self.cfg.SCAND_LOGFILE, self.cfg.HTTPD_LOGFILE, self.cfg.SCAN_DAEMON, self.cfg.HTTP_DAEMON)
sopds.setUser(user) sopds.make_response() else: sopds.set_response_status('401 Unauthorized') sopds.add_response_header([('WWW-Authenticate', 'Basic realm=\"%s\"'%cfg.SITE_TITLE)]) sopds.add_response_header([('Content-type', 'text/html')]) start_response(sopds.get_response_status(), sopds.get_response_headers()) return sopds.get_response_body() def start_server(config): global sopds global cfg cfg=config zipf.ZIP_CODEPAGE=cfg.ZIP_CODEPAGE sopds = sopdscli.opdsClient(cfg,sopdscli.modeINT) try: httpd = make_server(cfg.BIND_ADDRESS, cfg.PORT, app) print('Started Simple OPDS server on port ' , cfg.PORT) httpd.serve_forever() except KeyboardInterrupt: print('^C received, shutting down the web server') httpd.socket.close() if __name__ == "__main__": config=sopdscfg.cfgreader() start_server(config)
def start_server(config = None): if not config: config=sopdscfg.cfgreader() server = WebServer(config) server.start()
self.stdout = self.cfg.WEB_LOGFILE self.stderr = self.cfg.WEB_LOGFILE self.enabled = self.cfg.WEB_DAEMON #*************************************** # #*************************************** def _run(self): sopdsweb.start_server(self.cfg) #******************************************* # #******************************************* if __name__ == "__main__": cfg=sopdscfg.cfgreader() daemonTool = DaemonTool(cfg) if len(sys.argv) == 2: if 'start' == sys.argv[1]: daemonTool.start() elif 'stop' == sys.argv[1]: daemonTool.stop() elif 'restart' == sys.argv[1]: daemonTool.restart() elif 'status' == sys.argv[1]:
parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False, help='Enable verbose output') parser.add_option('-c', '--config', dest='configfile', default='', help='Config file pargh') (options, arguments) = parser.parse_args() VERBOSE = options.verbose CFG_FILE = options.configfile if CFG_FILE == '': cfg = sopdscfg.cfgreader() else: cfg = sopdscfg.cfgreader(CFG_FILE) logger = logging.getLogger('') logger.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s') if cfg.LOGLEVEL != logging.NOTSET: # Создаем обработчик для записи логов в файл fh = logging.FileHandler(cfg.LOGFILE) fh.setLevel(cfg.LOGLEVEL) fh.setFormatter(formatter) logger.addHandler(fh) if VERBOSE: # Создадим обработчик для вывода логов на экран с максимальным уровнем вывода
import logging import sopdscfg from sopdscan import opdsScanner from optparse import OptionParser from sys import argv if (__name__=="__main__"): parser=OptionParser(conflict_handler="resolve", version="sopds-scan.py. Version "+sopdscfg.VERSION, add_help_option=True, usage='sopds-scan.py [options]',description='sopds-scan.py: Simple OPDS Scanner - programm for scan your e-books directory and store data to MYSQL database.') parser.add_option('-v','--verbose', action='store_true', dest='verbose', default=False, help='Enable verbose output') parser.add_option('-c','--config',dest='configfile',default='',help='Config file pargh') (options,arguments)=parser.parse_args() VERBOSE=options.verbose CFG_FILE=options.configfile if CFG_FILE=='': cfg=sopdscfg.cfgreader() else: cfg=sopdscfg.cfgreader(CFG_FILE) logger = logging.getLogger('') logger.setLevel(logging.DEBUG) formatter=logging.Formatter('%(asctime)s %(levelname)-8s %(message)s') if cfg.LOGLEVEL!=logging.NOTSET: # Создаем обработчик для записи логов в файл fh = logging.FileHandler(cfg.LOGFILE) fh.setLevel(cfg.LOGLEVEL) fh.setFormatter(formatter) logger.addHandler(fh) if VERBOSE: # Создадим обработчик для вывода логов на экран с максимальным уровнем вывода