def test_connect_to_database(monkeypatch): def mock_fail_connection(self): raise(s.exc.OperationalError("fake", "error", "message")) monkeypatch.setattr(s.engine.Engine, "connect", mock_fail_connection) monkeypatch.setenv("AUGUR_LOG_QUIET", "1") with pytest.raises(s.exc.OperationalError): augur_app = Application(disable_logs=True)
def start(disable_housekeeper, skip_cleanup, logstash, logstash_with_cleanup): """ Start Augur's backend server """ augur_app = Application() logger.info("Augur application initialized") logger.info(f"Using config file: {augur_app.config.config_file_location}") if not skip_cleanup: logger.debug("Cleaning up old Augur processes...") _broadcast_signal_to_processes() time.sleep(2) else: logger.debug("Skipping process cleanup") if logstash or logstash_with_cleanup: augur_home = os.getenv('ROOT_AUGUR_DIRECTORY', "") if logstash_with_cleanup: print("Cleaning old workers errors...") with open(augur_home + "/log_analysis/http/empty_index.html") as f: lines = f.readlines() with open(augur_home + "/log_analysis/http/index.html", "w") as f1: f1.writelines(lines) print("All previous workers errors got deleted.") elasticsearch_path = os.getenv('ELASTIC_SEARCH_PATH', "/usr/local/bin/elasticsearch") subprocess.Popen(elasticsearch_path) logstash_path = os.getenv('LOGSTASH_PATH', "/usr/local/bin/logstash") subprocess.Popen([ logstash_path, "-f", augur_home + "/log_analysis/logstash-filter.conf" ]) master = initialize_components(augur_app, disable_housekeeper) logger.info('Starting Gunicorn webserver...') logger.info( f'Augur is running at: http://127.0.0.1:{augur_app.config.get_value("Server", "port")}' ) logger.info( 'Gunicorn server logs & errors will be written to logs/gunicorn.log') logger.info('Housekeeper update process logs will now take over.') Arbiter(master).run()
def cli(disable_housekeeper, skip_cleanup): """ Start Augur's backend server """ augur_app = Application() logger.info("Augur application initialized") if not skip_cleanup: logger.debug("Cleaning up old Augur processes...") kill_processes() time.sleep(2) else: logger.debug("Skipping process cleanup") master = initialize_components(augur_app, disable_housekeeper) logger.info('Starting Gunicorn server in the background...') if not disable_housekeeper: logger.info('Housekeeper update process logs will now take over.') else: logger.info("Gunicorn server logs will be written to gunicorn.log") logger.info("Augur is still running...don't close this process!") Arbiter(master).run()
def start(disable_housekeeper, skip_cleanup): """ Start Augur's backend server """ augur_app = Application() logger.info("Augur application initialized") logger.info(f"Using config file: {augur_app.config.config_file_location}") if not skip_cleanup: logger.debug("Cleaning up old Augur processes...") _broadcast_signal_to_processes() time.sleep(2) else: logger.debug("Skipping process cleanup") master = initialize_components(augur_app, disable_housekeeper) logger.info('Starting Gunicorn webserver...') logger.info(f"Augur is running at: http://0.0.0.0:5000") logger.info( "Gunicorn server logs & errors will be written to logs/gunicorn.log") logger.info('Housekeeper update process logs will now take over.') Arbiter(master).run()
def test_init_augur_regular(): augur_app = Application(disable_logs=True) assert augur_app is not None
This plugin serves as an example as to how to load plugins into Augur """ def __init__(self, augur): self.__githubapi = None # _augur will be set by the super init super().__init__(augur) def __call__(self): from .githubapi import GitHubAPI if self.__githubapi is None: logger.debug('Initializing GitHub API') api_key = self._augur.read_config('GitHub', 'apikey', 'AUGUR_GITHUB_API_KEY', 'None') self.__githubapi = GitHubAPI(api_key=api_key) return self.__githubapi def create_routes(self, flask_app): """ Responsible for adding this plugin's data sources to the API """ from .routes import create_routes create_routes(flask_app) GitHubAPIPlugin.augur_plugin_meta = { 'datasource': True, 'name': 'githubapi', } Application.register_plugin(GitHubAPIPlugin) __all__ = ['GitHubAPIPlugin']
def augur_app(): augur_app = Application(disable_logs=True) return augur_app
def __call__(self): from .ghtorrent import GHTorrent if self.__ghtorrent is None: logger.debug('Initializing GHTorrent') self.__ghtorrent = GHTorrent( user=self._augur.read_config('GHTorrent', 'user', 'AUGUR_DB_USER', 'root'), password=self._augur.read_config('GHTorrent', 'pass', 'AUGUR_DB_PASS', 'password'), host=self._augur.read_config('GHTorrent', 'host', 'AUGUR_DB_HOST', '127.0.0.1'), port=self._augur.read_config('GHTorrent', 'port', 'AUGUR_DB_PORT', '3306'), dbname=self._augur.read_config('GHTorrent', 'name', 'AUGUR_DB_NAME', 'msr14')) return self.__ghtorrent def create_routes(self, flask_app): """ Responsible for adding this plugin's data sources to the API """ from .routes import create_routes create_routes(flask_app) GHTorrentPlugin.augur_plugin_meta = {'name': 'ghtorrent', 'datasource': True} Application.register_plugin(GHTorrentPlugin) __all__ = ['GHTorrentPlugin']
# SPDX-License-Identifier: MIT from augur.augurplugin import AugurPlugin from augur.application import Application class ExamplePlugin(AugurPlugin): """ This plugin serves as an example as to how to load plugins into Augur """ def __init__(self, augur_app): super().__init__(augur_app) def __call__(self): from .example_datasource import ExampleDatasource return ExampleDatasource() def add_routes(self, flask_app): """ Responsible for adding this plugin's data sources to the API """ pass ExamplePlugin.augur_plugin_meta = { 'name': 'example_plugin', 'datasource': True } Application.register_plugin(ExamplePlugin) __all__ = ['ExamplePlugin']
from augur import logger class DownloadsPlugin(AugurPlugin): """ This plugin serves as an example as to how to load plugins into Augur """ def __init__(self, augur): self.__downloads = None # _augur will be set by the super init super().__init__(augur) def __call__(self): from .downloads import Downloads if self.__downloads is None: logger.debug('Initializing Downloads') self.__downloads = Downloads(self._augur['githubapi']()) return self.__downloads def create_routes(self, flask_app): """ Responsible for adding this plugin's data sources to the API """ from .routes import create_routes create_routes(flask_app) DownloadsPlugin.augur_plugin_meta = {'name': 'downloads', 'datasource': True} Application.register_plugin(DownloadsPlugin) __all__ = ['DownloadsPlugin']
logger.debug('Initializing Facade') self.__facade = Facade( user=self._augur.read_config('Facade', 'user', 'AUGUR_FACADE_DB_USER', 'root'), password=self._augur.read_config('Facade', 'pass', 'AUGUR_FACADE_DB_PASS', ''), host=self._augur.read_config('Facade', 'host', 'AUGUR_FACADE_DB_HOST', '127.0.0.1'), port=self._augur.read_config('Facade', 'port', 'AUGUR_FACADE_DB_PORT', '3306'), dbname=self._augur.read_config('Facade', 'name', 'AUGUR_FACADE_DB_NAME', 'facade'), projects=self._augur.read_config('Facade', 'projects', None, [])) return self.__facade def create_routes(self, flask_app): """ Responsible for adding this plugin's data sources to the API """ from .routes import create_routes create_routes(flask_app) FacadePlugin.augur_plugin_meta = {'name': 'facade', 'datasource': True} Application.register_plugin(FacadePlugin) __all__ = ['FacadePlugin']
def __init__(self, augur): self.__metrics_status = None self.__githubapi = None # _augur will be set by the super init super().__init__(augur) def __call__(self): from .metrics_status import MetricsStatus from augur.datasources.githubapi.githubapi import GitHubAPI if self.__metrics_status is None: logger.debug('Initializing MetricsStatus') api_key = self._augur.read_config('GitHub', 'apikey', 'AUGUR_GITHUB_API_KEY', 'None') self.__githubapi = GitHubAPI(api_key=api_key) self.__metrics_status = MetricsStatus(self.__githubapi) return self.__metrics_status def create_routes(self, flask_app): """ Responsible for adding this plugin's data sources to the API """ from .routes import create_routes create_routes(flask_app) MetricsStatusPlugin.augur_plugin_meta = { 'name': 'metrics_status', 'datasource': True } Application.register_plugin(MetricsStatusPlugin) __all__ = ['MetricsStatusPlugin']
def new_func(ctx, *args, **kwargs): ctx.obj = Application(offline_mode=True).config return ctx.invoke(f, ctx.obj, *args, **kwargs)
def new_func(ctx, *args, **kwargs): ctx.obj = Application() return ctx.invoke(f, ctx.obj, *args, **kwargs)
from augur import logger class LocalCSVPlugin(AugurPlugin): """ Plugin that can read local CSV files """ def __init__(self, augur): self.__localCSV = None # _augur will be set by the super init super().__init__(augur) def __call__(self): from augur.localcsv import LocalCSV if self.__localCSV is None: logger.debug('Initializing LocalCSV') self.__localCSV = LocalCSV() return self.__localCSV def create_routes(self, flask_app): """ Responsible for adding this plugin's data sources to the API """ from .routes import create_routes create_routes(flask_app) LocalCSVPlugin.augur_plugin_meta = {'name': 'localcsv', 'datasource': True} Application.register_plugin(LocalCSVPlugin) __all__ = ['LocalCSVPlugin']
'AUGUR_LIBRARIESIO_DB_USER', 'root'), password=self._augur.read_config('Database', 'pass', 'AUGUR_LIBRARIESIO_DB_PASS', 'password'), host=self._augur.read_config('Database', 'host', 'AUGUR_LIBRARIESIO_DB_HOST', '127.0.0.1'), port=self._augur.read_config('Database', 'port', 'AUGUR_LIBRARIESIO_DB_PORT', '3306'), dbname=self._augur.read_config('Database', 'name', 'AUGUR_LIBRARIESIO_DB_NAME', 'librariesio')) return self.__librariesio def create_routes(self, flask_app): """ Responsible for adding this plugin's data sources to the API """ from .routes import create_routes create_routes(flask_app) LibrariesIOPlugin.augur_plugin_meta = { 'datasource': True, 'name': 'librariesio' } Application.register_plugin(LibrariesIOPlugin) __all__ = ['LibrariesIOPlugin']