Ejemplo n.º 1
0
    def run(self):
        """
        Keeps the graph database and continously running in the terminal
        and parses the input.
        """
        while True:

            if verbose:
                # Prints out the graph structure for verbose output
                self.gs.display()

            commands = []
            #sys.stdout.write(">>> ")
            command = raw_input(">>> ")
            while True:
                #command = raw_input(">>> ")
                if (len(command) != 0 and command[-1] == ";"):
                    commands.append(command)
                    break
                commands.append(command)
                command = raw_input("... ")
            command_str = " ".join(commands)

            # Start the parser and parse the commands
            if (command_str[-1] == ";"):
                real_command = command_str[:-1] + " ;" # need to add space for parser 
                parser = Parser(real_command)
                parser.run()
            else:
                print "ERROR INVALID QUERY"
            

            # Check if user entered any errors in query.
            # If there are no errors, then create linker
            if (not(self.has_Errors(parser))):
                linker = Linker(parser.get_object_list(), self.gs)
                linker.execute()
            # Else, print the error
            else:
                print "Invalid Query"
Ejemplo n.º 2
0
    def run(self):
        """
        Keeps the graph database and continously running in the terminal
        and parses the input.
        """
        while True:

            if verbose:
                # Prints out the graph structure for verbose output
                self.gs.display()

            commands = []
            #sys.stdout.write(">>> ")
            command = raw_input(">>> ")
            while True:
                #command = raw_input(">>> ")
                if (len(command) != 0 and command[-1] == ";"):
                    commands.append(command)
                    break
                commands.append(command)
                command = raw_input("... ")
            command_str = " ".join(commands)

            # Start the parser and parse the commands
            if (command_str[-1] == ";"):
                real_command = command_str[:-1] + " ;"  # need to add space for parser
                parser = Parser(real_command)
                parser.run()
            else:
                print "ERROR INVALID QUERY"

            # Check if user entered any errors in query.
            # If there are no errors, then create linker
            if (not (self.has_Errors(parser))):
                linker = Linker(parser.get_object_list(), self.gs)
                linker.execute()
            # Else, print the error
            else:
                print "Invalid Query"
Ejemplo n.º 3
0
    def __init__(self, gs, filename):
        """
        Constructor takes a L{GraphStructure} object, a parser object, and  
        a file name as arguments. It will execute all of the commands that are 
        in the file. 
        """
        self.gs = gs

        f = open(filename, 'r')

        # Every line in the file is a command
        for line in f:
            # Skips blank lines and commented lines in text file
            if (len(line.split()) == 0) or (line[0] == '#'):
                continue

            # Assert that line ends with semicolon
            if line.split()[-1][-1] != ';':
                print "Invalid file format! Every line must end with a semicolon."
                break

            # Add a space before semicolon for parser. This ensures that
            # commands can end with a semicolon right after the last word
            # in the command.
            arr = line.split()
            arr[-1] = arr[-1][:-1] + ' ;'
            command = " ".join(arr)

            # Run the parser.
            parser = Parser(command)
            parser.run()

            # Extract the created objects from the parser and execute the linker.
            linker = Linker(parser.get_object_list(), self.gs)
            linker.execute()

        f.close()
Ejemplo n.º 4
0
    def __init__(self, gs, filename):   
        """
        Constructor takes a L{GraphStructure} object, a parser object, and  
        a file name as arguments. It will execute all of the commands that are 
        in the file. 
        """
        self.gs = gs

        f = open(filename, 'r')

        # Every line in the file is a command 
        for line in f:
            # Skips blank lines and commented lines in text file
            if (len(line.split()) == 0) or (line[0] == '#'):
                continue

            # Assert that line ends with semicolon 
            if line.split()[-1][-1] != ';':
                print "Invalid file format! Every line must end with a semicolon."
                break

            # Add a space before semicolon for parser. This ensures that 
            # commands can end with a semicolon right after the last word 
            # in the command.  
            arr = line.split()
            arr[-1] = arr[-1][:-1] + ' ;'
            command = " ".join(arr) 

            # Run the parser. 
            parser = Parser(command)
            parser.run()

            # Extract the created objects from the parser and execute the linker. 
            linker = Linker(parser.get_object_list(), self.gs)
            linker.execute()

        f.close()