예제 #1
0
 def command(self, command, *restring):
     '''command [command]
     Sends the specified command to the server console and will optionally
     wait for a given regex to return a match from the server.log before
     returning.
     '''
     
     if len(restring) > 0:
         # If a regex was specified for interactivity, then we will need
         # to open the server.log file and seek to the end of the file
         # before we actually do anything.  Once we send the command that
         # was specified we will use the end of the file as a starting
         # point for the parsing.
         logfile = open(os.path.join(self.env, 'env/logs', 'latest.log'), 'r')
         size = os.stat(os.path.join(self.env, 'env/logs', 'latest.log'))[6]
         logfile.seek(size)
     
     # Sending the command to the screen session
     screen.send('mc_%s' % self.name, command)
     
     if len(restring) > 0:
         # Now we will start parsing through all of the log data that the
         # server is returning, using the now old EOF as a starting point.
         # We will run the regex that we had compiled to the relog variable
         # on every line until we get a match, then return those matches.
         found = 0
         relog = re.compile(restring[found])
         while found < len(restring):
             where = logfile.tell()
             line = logfile.readline()
             if not line:
                 time.sleep(0.1)
                 logfile.seek(where)
             else:
                 data = re.compile(restring[found]).findall(line)
                 if len(data) > 0:
                     found += 1
         logfile.close()
         return data
     
     # If there was no regex specified, then there is nothing to return.
     return None
예제 #2
0
 def command(self, command, *restring):
     '''command [command]
     Sends the specified command to the server console and will optionally
     wait for a given regex to return a match from the server.log before
     returning.
     '''
     
     if len(restring) > 0:
         # If a regex was specified for interactivity, then we will need
         # to open the server.log file and seek to the end of the file
         # before we actually do anything.  Once we send the command that
         # was specified we will use the end of the file as a starting
         # point for the parsing.
         logfile = open(os.path.join(self.env, 'env', 'server.log'), 'r')
         size = os.stat(os.path.join(self.env, 'env', 'server.log'))[6]
         logfile.seek(size)
     
     # Sending the command to the screen session
     screen.send('mc_%s' % self.name, command)
     
     if len(restring) > 0:
         # Now we will start parsing through all of the log data that the
         # server is returning, using the now old EOF as a starting point.
         # We will run the regex that we had compiled to the relog variable
         # on every line until we get a match, then return those matches.
         found = 0
         relog = re.compile(restring[found])
         while found < len(restring):
             where = logfile.tell()
             line = logfile.readline()
             if not line:
                 time.sleep(0.1)
                 logfile.seek(where)
             else:
                 data = re.compile(restring[found]).findall(line)
                 if len(data) > 0:
                     found += 1
         logfile.close()
         return data
     
     # If there was no regex specified, then there is nothing to return.
     return None