def __init__(self): self.__db_manager = DBManager() self.__helper = GeneralHelpers() self.__plot_manager = PlotManager() self.__import_manager = ImportManager() self.__feature_manager = FeatureManager() self.years = ("2012", "2013", "2014", "2015")
def __init__(self, path=None): """Sets up and starts the `AppServer`. `path` is the working directory for the AppServer (directory in which AppServer is contained, by default) This method loads plugins, creates the Application object, and starts the request handling loop. """ self._running = 0 self._startTime = time() global globalAppServer if globalAppServer: raise ProcessRunning('More than one AppServer' ' or __init__() invoked more than once.') globalAppServer = self # Set up the import manager: self._imp = ImportManager() ConfigurableForServerSidePath.__init__(self) if path is None: path = os.path.dirname(__file__) # os.getcwd() self._serverSidePath = os.path.abspath(path) self._webKitPath = os.path.abspath(os.path.dirname(__file__)) self._webwarePath = os.path.dirname(self._webKitPath) self.recordPID() self._verbose = self.setting('Verbose') if self._verbose: self._silentURIs = self.setting('SilentURIs') if self._silentURIs: import re self._silentURIs = re.compile(self._silentURIs) else: self._silentURIs = None self._plugIns = [] self._requestID = 0 self.checkForInstall() self.config() # cache the config self.printStartUpMessage() if self.setting('CheckInterval') is not None: sys.setcheckinterval(self.setting('CheckInterval')) self._app = self.createApplication() self.loadPlugIns() # @@ 2003-03 ib: shouldn't this just be in a subclass's __init__? if self.isPersistent(): self._closeEvent = Event() self._closeThread = Thread(target=self.closeThread, name="CloseThread") # self._closeThread.setDaemon(1) self._closeThread.start() self._running = 1
def userConfig(self): """Return the user config overrides. These settings can be found in the optional config file. Returns {} if there is no such file. The config filename is taken from configFilename(). """ # pylint: disable=assignment-from-no-return filename = self.configFilename() if not filename: return {} try: with open(filename) as f: contents = f.read() except IOError as e: print('WARNING: Config file', filename, 'not loaded:', e.strerror) print() return {} if contents.lstrip().startswith('{'): raise ConfigurationError( 'Configuration via a dict literal is not supported anymore.') try: from ImportManager import ImportManager ImportManager().watchFile(filename) except Exception as e: print('WARNING: Config file', filename, 'cannot be watched:', e) print() config = self.configReplacementValues().copy() try: exec(contents, config) keys = [key for key in config if key.startswith('_')] for key in keys: del config[key] except Exception as e: raise ConfigurationError( f'Invalid configuration file, {filename} ({e}).') return config
def main(args): if len(args) < 3: sys.stderr.write("usage: {} <directories> <output.json>\n".format( args[0])) sys.stderr.write( "\t<directories>: list of space-separated directories to examine\n" ) sys.stderr.write( "\t<output>: json file describing graphs, interpreted by doc_grapher.html\n" ) sys.exit(1) directories = args[1:-1] outfname = args[-1] # for each file in each directory, recursively on down, # search for doc annotations and create objects appropriately docnodes = collections.OrderedDict() filecount = 0 for directory in directories: for root, dirs, files in os.walk(directory): for fname in files: filecount += 1 path = os.path.join(root, fname) docnode = parse_docfile(path) if docnode is None: # sys.stderr.write("Error! File is not annotated: {}\n" # .format(path)) continue docnodes[docnode.name] = docnode # if any docnodes have auto import set up, take care of that import_manager = ImportManager() import_manager.add_auto_imports(list(docnodes.values())) # validate all parents & siblings - make sure they actually exist rejectedEdges = [] for name in docnodes: docnode = docnodes[name] verified_edges = [] for edge in docnode.edges: if edge['id'] in docnodes: verified_edges.append(edge) else: rejectedEdges.append(edge) docnode.edges = verified_edges # print any rejected edges print('Rejected {} edge{}'.format(len(rejectedEdges), 's' if len(rejectedEdges) != 1 else '')) if len(rejectedEdges) > 0: print(rejectedEdges) ## assign colors to distinct segments ## we do this as follows: #### climb up chain of parents #### if parent has color assigned, assign same color to all children #### if we reach the top of the chain without having assigned a color, assign a color and bubble down #### IMPORTANT: remember to mark nodes as "seen" as we do this! #### (because we don't necessary want to force links as a tree structure) assigner = ColorAssigner() assigner.assign_colors(docnodes) nodes = [] edges = [] node_config = {'size': 10} edge_config = {'size': 3} for name in docnodes: docnode = docnodes[name] nodes.append(docnode.graph_node(node_config)) edges += docnode.graph_edges(edge_config) if len(nodes) == 0: sys.stderr.write( "No annotated files found! Not writing output file.\n") sys.exit(1) print("Extracted {} nodes with {} edges from {} files".format( len(nodes), len(edges), filecount)) graph = {'nodes': nodes, 'edges': edges} # pprint(graph) with open(outfname, 'w') as f: json.dump(graph, f, indent=4)
def __init__(self, path=None, settings=None, development=None): """Sets up the Application. You can specify the path of the application working directory, a dictionary of settings to override in the configuration, and whether the application should run in development mode. """ ConfigurableForServerSidePath.__init__(self) if path is None: path = os.getcwd() self._serverSidePath = os.path.abspath(path) self._webwarePath = os.path.abspath(os.path.dirname(__file__)) if not os.path.isfile(self.configFilename()): print("ERROR: The application cannot be started:") print(f"Configuration file {self.configFilename()} not found.") raise RuntimeError('Configuration file not found') if development is None: development = bool(os.environ.get('WEBWARE_DEVELOPMENT')) self._development = development self.initVersions() self._shutDownHandlers = [] self._plugIns = {} self._requestID = 0 self._imp = ImportManager() appConfig = self.config() # get and cache the configuration if settings: appConfig.update(settings) self._verbose = self.setting('Verbose') if self._verbose: self._silentURIs = self.setting('SilentURIs') if self._silentURIs: import re self._silentURIs = re.compile(self._silentURIs) else: self._silentURIs = None self._outputEncoding = self.setting('OutputEncoding') self._responseBufferSize = self.setting('ResponseBufferSize') self._wsgiWrite = self.setting('WSGIWrite') if self.setting('CheckInterval') is not None: sys.setswitchinterval(self.setting('CheckInterval')) logFilename = self.setting('AppLogFilename') if logFilename: sys.stderr = sys.stdout = open(logFilename, 'a', buffering=1) self.initErrorPage() self.printStartUpMessage() # Initialize task manager: if self.setting('RunTasks'): self._taskManager = Scheduler( daemon=True, exceptionHandler=self.handleException) self._taskManager.start() else: self._taskManager = None # Define this before initializing URLParser, so that contexts have a # chance to override this. Also be sure to define it before loading the # sessions, in case the loading of the sessions causes an exception. self._exceptionHandlerClass = ExceptionHandler self.makeDirs() self.initSessions() URLParser.initApp(self) self._rootURLParser = URLParser.ContextParser(self) self._startTime = time() if self.setting('UseSessionSweeper'): self.startSessionSweeper() self._plugInLoader = None self.loadPlugIns() self._needsShutDown = [True] atexit.register(self.shutDown) self._sigTerm = signal.signal(signal.SIGTERM, self.sigTerm) try: self._sigHup = signal.signal(signal.SIGHUP, self.sigTerm) except AttributeError: pass # SIGHUP does not exist on Windows