def connectToDatabase(self, databaseName='octopusDB'): self.j = PythonShellInterface() self.j.setDatabaseName(databaseName) self.j.connectToDatabase() if self.jsonEnabled: self.j.runGremlinQuery('toggle_json')
def __init__(self, project_name, code_base_location, patch_filepath): self.project_name = project_name self.patch_filepath = patch_filepath self.code_base_location = code_base_location self.print_queue = [] self.buffer_output = True self.j = PythonShellInterface() self.j.setDatabaseName(self.project_name) self.temporary_directory_object = tempfile.TemporaryDirectory() self.temporary_directory = self.temporary_directory_object.name
def __init__(self, DESCRIPTION): AccTool.__init__(self, DESCRIPTION) self.argParser.add_argument( '-d', type=str, help='The directory which will contain embeddings.') self.argParser.add_argument('--force', action='store_true', default=False, help='overwrite existing directories') self.argParser.add_argument( '--verbose', action='store_true', default=False, help='Verbose mode: show messages regarding the extrapolation.') # Setup #self.dbInterface.addStepsDir("steps") # Parse command line already here to initialize further class variables. self._parseCommandLine() if not self.args.d: self.args.d = DEFAULT_EBMDDINGS_CACHE_DIRECTORY self.embeddings_directory = self.args.d self.embeddings_data_directory = os.path.join( self.embeddings_directory, 'data') self.embeddings_toc_path = os.path.join(self.embeddings_directory, 'TOC') if os.path.exists(self.embeddings_directory): if self.args.force: self._print("[!] Removing existing directory.") shutil.rmtree(self.embeddings_directory) else: sys.stderr.write( "[-] Please remove the embeddings directory first or supply --force.\n" ) sys.exit() # TODO: REMOVE ALL FOLLOWING LINES... shell_interface = PythonShellInterface() shell_interface.setDatabaseName(self.args.project) shell_interface.connectToDatabase()
def __init__(self, databaseName='octopusDB'): self.argParser = ArgumentParser(description=DESCRIPTION) self.argParser.add_argument('project') # TODO: For now we are ignoring the databaseName in the init parameter. This should be adjusted. self.argParser.add_argument( "directory", help="""The directory containing *.patch files.""") self.args = self.argParser.parse_args() self.project_name = self.args.project self.j = PythonShellInterface() self.j.setDatabaseName(self.project_name) self.j.connectToDatabase() # TODO: replace this ugly code once a nicer way to load steps is available. old_stdout = sys.stdout sys.stdout = open(os.devnull, "w") dir_path = os.path.dirname(os.path.realpath(__file__)) reload_dir(self.j.shell_connection, dir_path + "/steps") sys.stdout.close() sys.stdout = old_stdout # ------------------------------------------------------------------------ # Get the current code base location. # TODO: Is there no cleaner way to get the root element of a graph? #self.code_base_location = self._query("queryNodeIndex('key:1').filepath")[0] self.code_base_location = self._query( "execSQLQuery('SELECT FROM #9:1').filepath")[0] if not self.code_base_location: raise Exception("[!] Couldn't retrieve the code base location.") self._print_indented("[~] Using code base location: " + self.code_base_location) # An array storing all running importer threads. self.import_threads = [] # Ensure that the patch index was built. self._query("createPatchIndex()")
from argparse import ArgumentParser from octopus.server.python_shell_interface import PythonShellInterface from octopus.shell.octopus_shell_utils import reload_dir import sys import os DESCRIPTION = """Retrieve all security patches from the database.""" if __name__ == '__main__': argParser = ArgumentParser(description=DESCRIPTION) argParser.add_argument('project') args = argParser.parse_args() projectName = args.project # Setup dbConnection = PythonShellInterface() dbConnection.setDatabaseName(projectName) dbConnection.connectToDatabase() # Load additional groovy files (mute any output in the meantime). old_stdout = sys.stdout sys.stdout = open(os.devnull, "w") dir_path = os.path.dirname(os.path.realpath(__file__)) + "/steps" reload_dir(dbConnection.shell_connection, dir_path) sys.stdout.close() sys.stdout = old_stdout print("[~] Imported patch statistics for project: {}".format(projectName)) imported_patches = int( dbConnection.runGremlinQuery( 'queryPatchIndex("/.*patch/").toList().size')[0])
def _isolated_query(self, query): shell_interface = PythonShellInterface() shell_interface.setDatabaseName(self.args.project) shell_interface.connectToDatabase() return shell_interface.runGremlinQuery(query)
def _configureShellInterface(self): self.shell_interface = PythonShellInterface() self.shell_interface.setHost(self.hostname) self.shell_interface.setPort(self.port) self.shell_interface.setDatabaseName(self.databaseName)
def close(self): PythonShellInterface().close()
def connectToDatabase(self, databaseName='octopusDB'): self.j = PythonShellInterface() self.j.setDatabaseName(databaseName) self.j.connectToDatabase()