def check_options_validity(args): # Args must has workspace and dbaddress if args.workspace and not util.is_localhost(args.dbaddress): LOG.info("Workspace is not required when postgreSql server run on remote host.") sys.exit(1) if not args.workspace and util.is_localhost(args.dbaddress): LOG.info("Workspace is required when postgreSql server run on localhost.") sys.exit(1)
def start_postgres(cls, context, init_db=True): """ init_db : Initialize database locally if possible """ dbusername = context.db_username LOG.info("Checking for database") if not database_handler.is_database_running(cls.database_host, cls.database_port, dbusername, cls.run_env): LOG.info("Database is not running yet") # On remote host we cannot initialize a new database if not util.is_localhost(cls.database_host): sys.exit(1) db_path = context.database_path if init_db: if not database_handler.is_database_exist(db_path) and not database_handler.initialize_database( db_path, dbusername, cls.run_env ): # The database does not exist and cannot create LOG.error("Database is missing and the initialization " "of a new failed!") LOG.error("Please check your configuration!") sys.exit(1) else: if not database_handler.is_database_exist(db_path): # The database does not exists LOG.error("Database is missing!") LOG.error("Please check your configuration!") sys.exit(1) LOG.info("Starting database") cls._database = database_handler.start_database(db_path, cls.database_host, cls.database_port, cls.run_env) atexit.register(cls._database.terminate)
def start(self, db_version_info, wait_for_start=True, init=False): ''' Start a PostgreSQL instance with given path, host and port. Return with process instance ''' LOG.debug('Starting/connecting to database') if not self._is_running(): if not util.is_localhost(self.host): LOG.info('Database is not running yet') sys.exit(1) if not self._is_database_data_exist(): if not init: # The database does not exists LOG.error('Database data is missing!') LOG.error('Please check your configuration!') sys.exit(1) elif not self._initialize_database_data(): # The database does not exist and cannot create LOG.error( 'Database data is missing and the initialization ' 'of a new failed!') LOG.error('Please check your configuration!') sys.exit(1) LOG.info('Starting database') LOG.debug('Starting database at ' + self.host + ':' + str(self.port) + ' ' + self.path) db_logfile = os.path.join(self.workspace, 'postgresql.log') \ if logger.get_log_level() == logger.DEBUG else os.devnull self._db_log = open(db_logfile, 'wb') start_db = [ 'postgres', '-i', '-D', self.path, '-p', str(self.port), '-h', self.host ] self.proc = subprocess.Popen(start_db, bufsize=-1, env=self.run_env, stdout=self._db_log, stderr=subprocess.STDOUT) add_version = False if init: self._wait_or_die() self._create_database() add_version = not self.check_db_version(db_version_info) self._create_or_update_schema() elif wait_for_start: self._wait_or_die() add_version = not self.check_db_version(db_version_info) if add_version: self._add_version(db_version_info) atexit.register(self.stop) LOG.debug('Done')
def start(self, db_version_info, wait_for_start=True, init=False): """ Start a PostgreSQL instance with given path, host and port. Return with process instance. """ LOG.debug('Starting/connecting to database.') if not self._is_running(): if not util.is_localhost(self.host): LOG.info('Database is not running yet.') sys.exit(1) if not self._is_database_data_exist(): if not init: # The database does not exists. LOG.error('Database data is missing!') LOG.error('Please check your configuration!') sys.exit(1) elif not self._initialize_database_data(): # The database does not exist and cannot create. LOG.error('Database data is missing and ' 'the initialization of a new failed!') LOG.error('Please check your configuration!') sys.exit(1) LOG.info('Starting database') LOG.debug('Starting database at ' + self.host + ':' + str( self.port) + ' ' + self.path) db_logfile = os.path.join(self.workspace, 'postgresql.log') \ if LoggerFactory.get_log_level() == logger.DEBUG \ else os.devnull self._db_log = open(db_logfile, 'wb') start_db = ['postgres', '-i', '-D', self.path, '-p', str(self.port), '-h', self.host] self.proc = subprocess.Popen(start_db, bufsize=-1, env=self.run_env, stdout=self._db_log, stderr=subprocess.STDOUT) add_version = False if init: self._wait_or_die() self._create_database() add_version = not self.check_db_version(db_version_info) self._create_or_update_schema() elif wait_for_start: self._wait_or_die() add_version = not self.check_db_version(db_version_info) if add_version: self._add_version(db_version_info) atexit.register(self.stop) LOG.debug('Done')
def start(self, db_version_info, wait_for_start=True, init=False): """ Start a PostgreSQL instance with given path, host and port. Return with process instance. """ LOG.debug("Starting/connecting to database.") if not self._is_running(): if not util.is_localhost(self.host): LOG.info("Database is not running yet.") sys.exit(1) if not self._is_database_data_exist(): if not init: # The database does not exists. LOG.error("Database data is missing!") LOG.error("Please check your configuration!") sys.exit(1) elif not self._initialize_database_data(): # The database does not exist and cannot create. LOG.error("Database data is missing and the initialization " "of a new failed!") LOG.error("Please check your configuration!") sys.exit(1) LOG.info("Starting database") LOG.debug("Starting database at " + self.host + ":" + str(self.port) + " " + self.path) db_logfile = ( os.path.join(self.workspace, "postgresql.log") if logger.get_log_level() == logger.DEBUG else os.devnull ) self._db_log = open(db_logfile, "wb") start_db = ["postgres", "-i", "-D", self.path, "-p", str(self.port), "-h", self.host] self.proc = subprocess.Popen( start_db, bufsize=-1, env=self.run_env, stdout=self._db_log, stderr=subprocess.STDOUT ) add_version = False if init: self._wait_or_die() self._create_database() add_version = not self.check_db_version(db_version_info) self._create_or_update_schema() elif wait_for_start: self._wait_or_die() add_version = not self.check_db_version(db_version_info) if add_version: self._add_version(db_version_info) atexit.register(self.stop) LOG.debug("Done")
def start(self, db_version_info, wait_for_start=True, init=False): ''' Start a PostgreSQL instance with given path, host and port. Return with process instance ''' LOG.debug('Starting/connecting to database') if not self._is_running(): if not util.is_localhost(self.host): LOG.info('Database is not running yet') sys.exit(1) if not self._is_database_data_exist(): if not init: # The database does not exists LOG.error('Database data is missing!') LOG.error('Please check your configuration!') sys.exit(1) elif not self._initialize_database_data(): # The database does not exist and cannot create LOG.error('Database data is missing and the initialization ' 'of a new failed!') LOG.error('Please check your configuration!') sys.exit(1) LOG.info('Starting database') LOG.debug('Starting database at ' + self.host + ':' + str(self.port) + ' ' + self.path) devnull = open(os.devnull, 'wb') start_db = ['postgres', '-i', '-D', self.path, '-p', str(self.port), '-h', self.host] self.proc = subprocess.Popen(start_db, bufsize=-1, env=self.run_env, stdout=devnull, stderr=subprocess.STDOUT) add_version = False if init: self._wait_or_die() self._create_database() add_version = not self.check_db_version(db_version_info) self._create_or_update_schema() elif wait_for_start: self._wait_or_die() add_version = not self.check_db_version(db_version_info) if add_version: self._add_version(db_version_info) atexit.register(self.stop) LOG.debug('Done')
def handle_server(args): """ Starts the report viewer server. """ if not host_check.check_zlib(): sys.exit(1) workspace = args.workspace # WARNING # In case of SQLite args.dbaddress default value is used # for which the is_localhost should return true. if util.is_localhost(args.dbaddress) and not os.path.exists(workspace): os.makedirs(workspace) suppress_handler = generic_package_suppress_handler.\ GenericSuppressHandler() if args.suppress is None: LOG.warning('No suppress file was given, suppressed results will ' 'be only stored in the database.') else: if not os.path.exists(args.suppress): LOG.error('Suppress file ' + args.suppress + ' not found!') sys.exit(1) context = generic_package_context.get_context() context.codechecker_workspace = workspace session_manager.SessionManager.CodeChecker_Workspace = workspace context.db_username = args.dbusername check_env = analyzer_env.get_check_env(context.path_env_extra, context.ld_lib_path_extra) sql_server = SQLServer.from_cmdline_args(args, context.codechecker_workspace, context.migration_root, check_env) conn_mgr = client.ConnectionManager(sql_server, args.check_address, args.check_port) if args.check_port: LOG.debug('Starting CodeChecker server and database server.') sql_server.start(context.db_version_info, wait_for_start=True, init=True) conn_mgr.start_report_server() else: LOG.debug('Starting database.') sql_server.start(context.db_version_info, wait_for_start=True, init=True) # Start database viewer. db_connection_string = sql_server.get_connection_string() suppress_handler.suppress_file = args.suppress LOG.debug('Using suppress file: ' + str(suppress_handler.suppress_file)) checker_md_docs = os.path.join(context.doc_root, 'checker_md_docs') checker_md_docs_map = os.path.join(checker_md_docs, 'checker_doc_map.json') with open(checker_md_docs_map, 'r') as dFile: checker_md_docs_map = json.load(dFile) package_data = { 'www_root': context.www_root, 'doc_root': context.doc_root, 'checker_md_docs': checker_md_docs, 'checker_md_docs_map': checker_md_docs_map } client_db_access_server.start_server(package_data, args.view_port, db_connection_string, suppress_handler, args.not_host_only, context.db_version_info)
def handle_server(args): """ Starts the report viewer server. """ if not host_check.check_zlib(): LOG.error("zlib error") sys.exit(1) try: workspace = args.workspace except AttributeError: # If no workspace value was set for some reason # in args set the default value. workspace = util.get_default_workspace() # WARNING # In case of SQLite args.dbaddress default value is used # for which the is_localhost should return true. local_db = util.is_localhost(args.dbaddress) if local_db and not os.path.exists(workspace): os.makedirs(workspace) if args.suppress is None: LOG.warning( "WARNING! No suppress file was given, suppressed results will " + 'be only stored in the database.') else: if not os.path.exists(args.suppress): LOG.error('Suppress file ' + args.suppress + ' not found!') sys.exit(1) context = generic_package_context.get_context() context.codechecker_workspace = workspace session_manager.SessionManager.CodeChecker_Workspace = workspace context.db_username = args.dbusername check_env = analyzer_env.get_check_env(context.path_env_extra, context.ld_lib_path_extra) sql_server = SQLServer.from_cmdline_args(args, context.codechecker_workspace, context.migration_root, check_env) conn_mgr = client.ConnectionManager(sql_server, args.check_address, args.check_port) if args.check_port: LOG.debug('Starting CodeChecker server and database server.') sql_server.start(context.db_version_info, wait_for_start=True, init=True) conn_mgr.start_report_server() else: LOG.debug('Starting database.') sql_server.start(context.db_version_info, wait_for_start=True, init=True) # Start database viewer. db_connection_string = sql_server.get_connection_string() suppress_handler = generic_package_suppress_handler.GenericSuppressHandler() try: suppress_handler.suppress_file = args.suppress LOG.debug('Using suppress file: ' + str(suppress_handler.suppress_file)) except AttributeError as aerr: # Suppress file was not set. LOG.debug(aerr) package_data = {'www_root': context.www_root, 'doc_root': context.doc_root} checker_md_docs = os.path.join(context.doc_root, 'checker_md_docs') checker_md_docs_map = os.path.join(checker_md_docs, 'checker_doc_map.json') package_data['checker_md_docs'] = checker_md_docs with open(checker_md_docs_map, 'r') as dFile: checker_md_docs_map = json.load(dFile) package_data['checker_md_docs_map'] = checker_md_docs_map client_db_access_server.start_server(package_data, args.view_port, db_connection_string, suppress_handler, args.not_host_only, context.db_version_info)
def handle_server(args): """ starts the report viewer server """ if not host_check.check_zlib(): LOG.error("zlib error") sys.exit(1) try: workspace = args.workspace except AttributeError: # if no workspace value was set for some reason # in args set the default value workspace = util.get_default_workspace() # WARNING # in case of SQLite args.dbaddress default value is used # for which the is_localhost should return true local_db = util.is_localhost(args.dbaddress) if local_db and not os.path.exists(workspace): os.makedirs(workspace) if args.suppress is None: LOG.warning( 'WARNING! No suppress file was given, suppressed results will be only stored in the database.' ) else: if not os.path.exists(args.suppress): LOG.error('Suppress file ' + args.suppress + ' not found!') sys.exit(1) context = generic_package_context.get_context() context.codechecker_workspace = workspace context.db_username = args.dbusername check_env = analyzer_env.get_check_env(context.path_env_extra, context.ld_lib_path_extra) sql_server = SQLServer.from_cmdline_args(args, context.codechecker_workspace, context.migration_root, check_env) conn_mgr = client.ConnectionManager(sql_server, args.check_address, args.check_port) if args.check_port: LOG.debug('Starting codechecker server and database server.') sql_server.start(context.db_version_info, wait_for_start=True, init=True) conn_mgr.start_report_server(context.db_version_info) else: LOG.debug('Starting database.') sql_server.start(context.db_version_info, wait_for_start=True, init=True) # start database viewer db_connection_string = sql_server.get_connection_string() suppress_handler = generic_package_suppress_handler.GenericSuppressHandler( ) try: suppress_handler.suppress_file = args.suppress LOG.debug('Using suppress file: ' + str(suppress_handler.suppress_file)) except AttributeError as aerr: # suppress file was not set LOG.debug(aerr) package_data = {} package_data['www_root'] = context.www_root package_data['doc_root'] = context.doc_root checker_md_docs = os.path.join(context.doc_root, 'checker_md_docs') checker_md_docs_map = os.path.join(checker_md_docs, 'checker_doc_map.json') package_data['checker_md_docs'] = checker_md_docs with open(checker_md_docs_map, 'r') as dFile: checker_md_docs_map = json.load(dFile) package_data['checker_md_docs_map'] = checker_md_docs_map client_db_access_server.start_server(package_data, args.view_port, db_connection_string, suppress_handler, args.not_host_only, context.db_version_info)