Пример #1
0
 def get_output(cls, command, silent=False):
     """
     Wraps a subprocess.check_output call. Checks for process errors and command not found errors.
     :param silent: If silent is true the command will not be logged
     :param command: array of strings - same as check_output
     :return: string of output, error, or None if the command is not found
     """
     try:
         if not silent:
             Logger.extra("Attempting to execute command %s", command)
         output = subprocess.check_output(command,
                                          stderr=subprocess.STDOUT,
                                          universal_newlines=True)
     except OSError as e:
         output = ""
         if e.errno == errno.ENOENT:
             Logger.warn("\"%s\" may not be installed", command[0])
         else:
             Logger.exception(e)
         cls.log_failed_command(command)
     except subprocess.CalledProcessError as e:
         output = e.output
         cls.log_failed_command(command, output.strip())
     Logger.verbose("Command \"%s\" output %s", command, output)
     return output
Пример #2
0
 def is_interface_wiiu_compatible(cls, interface):
     if not OsUtil.is_linux():
         Logger.extra("Ignoring interface compatibility check for %s",
                      interface)
         return False
     frequency_info = ProcessUtil.get_output(
         ["iwlist", interface, "frequency"])
     return "5." in frequency_info
Пример #3
0
 def __init__(self, in_path):
     pre = "resources/"
     Logger.debug("Loading resource \"%s\"", join(pre, in_path))
     current_dir = os.path.dirname(__file__).split(os.sep)
     # Check local files first
     file_path = "/"
     if len(current_dir) >= 3:
         for path in range(0, len(current_dir) - 3):
             file_path = join(file_path, current_dir[path])
         file_path = join(file_path, pre, in_path)
         if os.path.exists(file_path):
             try:
                 with open(file_path) as f:
                     self.resource = f.read()
             except UnicodeDecodeError:
                 Logger.debug("Opening resource as binary.")
                 with open(file_path, "rb") as f:
                     self.resource = f.read()
             Logger.extra("Found resource in local resource directory.")
             return
     # Check /usr/local - pip installs to here
     file_path = "/usr/local/resources/" + in_path
     if os.path.exists(file_path):
         try:
             with open(file_path) as f:
                 self.resource = f.read()
         except UnicodeDecodeError:
             Logger.debug("Opening resource as binary.")
             with open(file_path, "rb") as f:
                 self.resource = f.read()
             Logger.extra(
                 "Found resource in /usr/local/ resource directory.")
             return
     # Attempt to get from package - setup.py installs here
     try:
         self.resource = pkg_resources.resource_string(
             pkg_resources.Requirement.parse("drcsim"), join(pre, in_path))
         Logger.extra("Found resource in package.")
     except FileNotFoundError:
         Logger.throw("Could not find resource: %s" % join(pre, in_path))
         sys.exit()
Пример #4
0
 def log_failed_command(cls, command, output=None):
     Logger.extra("Failed to execute command \"%s\" and got output \"%s\"",
                  command, output)