def __init__(self): QMainWindow.__init__(self) self.setObjectName('EzSphinx') self.setWindowTitle('EzSphinx') # TODO: Use setuptools resources here pngpath = os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), 'images', 'ezsphinx.png') self._icon = QIcon(pngpath) self.setWindowIcon(self._icon) QApplication.instance().setWindowIcon(self._icon) QMetaObject.connectSlotsByName(self) self.config = EasyConfigParser() self._setup_ui() # load last user settings self._load_preferences()
def main(): debug = False try: from argparse import ArgumentParser argparser = ArgumentParser(description=sys.modules[__name__].__doc__) argparser.add_argument('-c', '--config', dest='config', default='pybootd/etc/pybootd.ini', help='configuration file') argparser.add_argument('-p', '--pxe', dest='pxe', action='store_true', help='enable BOOTP/DHCP/PXE server only') argparser.add_argument('-t', '--tftp', dest='tftp', action='store_true', help='enable TFTP server only') argparser.add_argument('-d', '--debug', action='store_true', help='enable debug mode') args = argparser.parse_args() debug = args.debug if not os.path.isfile(args.config): argparser.error('Invalid configuration file') if args.pxe and args.tftp: argparser.error('Cannot exclude PXE & TFTP servers altogether') cfgparser = EasyConfigParser() with open(pybootd_path(args.config), 'rt') as config: cfgparser.readfp(config) logger = logger_factory(logtype=cfgparser.get('logger', 'type', 'stderr'), logfile=cfgparser.get('logger', 'file'), level=cfgparser.get('logger', 'level', 'info')) logger.info('-'.join((PRODUCT_NAME, VERSION))) daemon = None if not args.tftp: daemon = BootpDaemon(logger, cfgparser) daemon.start() if not args.pxe: daemon = TftpDaemon(logger, cfgparser, daemon) daemon.start() if daemon: while True: daemon.join(0.5) if not daemon.is_alive(): break except Exception as e: print_('\nError: %s' % e, file=sys.stderr) if debug: import traceback print_(traceback.format_exc(), file=sys.stderr) sys.exit(1) except KeyboardInterrupt: print_("Aborting...")
def main(): usage = 'Usage: %prog [options]\n' \ ' PXE boot up server, a tiny BOOTP/DHCP/TFTP server' optparser = OptionParser(usage=usage) optparser.add_option('-c', '--config', dest='config', default='pybootd/etc/pybootd.ini', help='configuration file') optparser.add_option('-p', '--pxe', dest='pxe', action='store_true', help='enable BOOTP/DHCP/PXE server only') optparser.add_option('-t', '--tftp', dest='tftp', action='store_true', help='enable TFTP server only') (options, args) = optparser.parse_args(sys.argv[1:]) if not options.config: raise AssertionError('Missing configuration file') if options.pxe and options.tftp: raise AssertionError('Cannot exclude both servers') cfgparser = EasyConfigParser() with open(pybootd_path(options.config), 'rt') as config: cfgparser.readfp(config) logger = logger_factory(logtype=cfgparser.get('logger', 'type', 'stderr'), logfile=cfgparser.get('logger', 'file'), level=cfgparser.get('logger', 'level', 'info')) logger.info('-'.join((PRODUCT_NAME, VERSION))) try: if not options.tftp: bt = BootpDaemon(logger, cfgparser) bt.start() else: bt = None if not options.pxe: ft = TftpDaemon(logger, cfgparser, bt) ft.start() while True: import time time.sleep(5) except AssertionError, e: print >> sys.stderr, "Error: %s" % str(e) sys.exit(1)
def start(self): self.serve_forever() if __name__ == "__main__": usage = 'Usage: %prog [options]\n' \ ' HTTPd tiny server to exercise the pybootd daemon' optparser = OptionParser(usage=usage) optparser.add_option('-c', '--config', dest='config', help='configuration file') (options, args) = optparser.parse_args(sys.argv[1:]) if not options.config: raise AssertionError('Missing configuration file') cfgparser = EasyConfigParser() with open(options.config, 'rt') as config: cfgparser.readfp(config) logger = logger_factory(logtype=cfgparser.get('logger', 'type', 'stderr'), logfile=cfgparser.get('logger', 'file'), level=cfgparser.get('logger', 'level', 'info')) try: bt = HttpdDaemon(logger, cfgparser) bt.start() while True: import time time.sleep(5) except KeyboardInterrupt: print "Aborting..."
class EzSphinxWindow(QMainWindow): """Main application window""" def __init__(self): QMainWindow.__init__(self) self.setObjectName('EzSphinx') self.setWindowTitle('EzSphinx') # TODO: Use setuptools resources here pngpath = os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), 'images', 'ezsphinx.png') self._icon = QIcon(pngpath) self.setWindowIcon(self._icon) QApplication.instance().setWindowIcon(self._icon) QMetaObject.connectSlotsByName(self) self.config = EasyConfigParser() self._setup_ui() # load last user settings self._load_preferences() def save_presentation(self, config): self._save_preferences(config) def select_warning(self, line): self.widgets['restedit'].select_line(line) self.widgets['restedit'].set_focus() def render(self, html=''): self.widgets['webview'].refresh(html) # a document would be better self.widgets['warnreport'].refresh() self.widgets['restedit'].refresh() def update(self, what): for w in what: if w in self.widgets: self.widgets[w].update_text() else: print "Invalid widget: %s" % w #------------------------------------------------------------------------- # Private implementation #------------------------------------------------------------------------- def _setup_ui(self): self.widgets = {} mainwidget = QWidget(self) mainwidget.setMouseTracking(True) mainwidget.setObjectName("mainwidget") flayout = QHBoxLayout(mainwidget) flayout.setObjectName("flayout") fsplitter = EzSphinxSplitter(mainwidget, self, 'fsplitter', Qt.Horizontal) ftwidget = QWidget(fsplitter) ftwidget.setObjectName("ftwidget") ftlayout = QVBoxLayout(ftwidget) ftlayout.setObjectName("ftlayout") ftlayout.setContentsMargins(0,4,1,0) filetree = EzSphinxTreeView(ftwidget) ftlayout.addWidget(filetree) vlayout = QVBoxLayout(fsplitter) vlayout.setObjectName("vlayout") vlayout.setContentsMargins(4,0,4,0) vsplitter = EzSphinxSplitter(fsplitter, self, 'vsplitter', Qt.Vertical) editwidget = QWidget(vsplitter) editwidget.setObjectName("editwidget") elayout = QVBoxLayout(editwidget) elayout.setObjectName("elayout") elayout.setContentsMargins(1,4,1,0) hsplitter = EzSphinxSplitter(editwidget, self, 'hsplitter', Qt.Horizontal) elayout.addWidget(hsplitter) textwidget = QWidget(hsplitter) textwidget.setObjectName("textwidget") textlayout = QHBoxLayout(textwidget) textlayout.setObjectName("textlayout") textlayout.setContentsMargins(0,0,2,0) restedit = EzSphinxRestEdit(textwidget, self) textlayout.addWidget(restedit) webwidget = QWidget(hsplitter) webwidget.setObjectName("webwidget") weblayout = QHBoxLayout(webwidget) weblayout.setObjectName("weblayout") weblayout.setContentsMargins(1,0,2,2) webview = EzSphinxWebView(webwidget, self) weblayout.addWidget(webview) tablewidget = QWidget(vsplitter) tablewidget.setObjectName("tablewidget") tablelayout = QHBoxLayout(tablewidget) tablelayout.setObjectName("tablelayout") tablelayout.setContentsMargins(1,0,2,0) vlayout.addWidget(vsplitter) flayout.addWidget(fsplitter) warnreport = EzSphinxWarnReportView(self) tablelayout.addWidget(warnreport) self.setCentralWidget(mainwidget) self.setMenuBar(EzSphinxMenuBar(self)) self.setStatusBar(EzSphinxStatusBar(self)) self._add_widgets((hsplitter, vsplitter, fsplitter)) self._add_widgets((filetree, restedit, webview, warnreport)) def _add_widgets(self, widgets): if not isinstance(widgets, tuple) and not isinstance(widgets, list): widgets = (widgets,) for widget in widgets: name = str(widget.objectName().toUtf8()) self.widgets[name] = widget def _load_preferences(self): """reload previously saved UI configuration from a file""" if not self.config.read(os.path.expanduser('~/.ezsphinxrc')): return self.resize(int(self.config.get('window', 'width', '750')), int(self.config.get('window', 'height', '650'))) config = {} for section in self.config.sections(): for k, v in self.config.items(section): config.setdefault(section, []).append((k.lower(), v)) for widget in self.widgets.values(): if hasattr(widget, 'load_presentation'): widget.load_presentation(config) def _save_preferences(self, config={}): """save current UI configuration into a configuration file""" size = self.size() config['window'] = [('width', size.width()), ('height', size.height())] for section in config: for key, value in config[section]: self.config.set(section, key, value) with open(os.path.expanduser('~/.ezsphinxrc'), 'w') as out_: self.config.write(out_)
if __name__ == "__main__": usage = 'Usage: %prog [options]\n' \ ' HTTPd tiny server to exercise the pybootd daemon' optparser = OptionParser(usage=usage) optparser.add_option('-c', '--config', dest='config', help='configuration file') (options, args) = optparser.parse_args(sys.argv[1:]) if not options.config: raise AssertionError('Missing configuration file') cfgparser = EasyConfigParser() with open(options.config, 'rt') as config: cfgparser.readfp(config) logger = logger_factory(logtype=cfgparser.get('logger', 'type', 'stderr'), logfile=cfgparser.get('logger', 'file'), level=cfgparser.get('logger', 'level', 'info')) try: bt = HttpdDaemon(logger, cfgparser) bt.start() while True: import time time.sleep(5) except KeyboardInterrupt: print "Aborting..."