Exemplo n.º 1
0
  def open(self, ami_path, f_mode):
    try:
      # special names
      uname = ami_path.upper()
      if uname == 'NIL:':
        sys_name = "/dev/null"
        fobj = open(sys_name, f_mode)
        fh = FileHandle(fobj, ami_path, sys_name)
      elif uname in ('*','CONSOLE:'):
        sys_name = ''
        fh = FileHandle(sys.stdout,'*','',need_close=False)
      else:
        # map to system path
        sys_path = self.path_mgr.ami_to_sys_path(ami_path)
        if sys_path == None:
          log_file.info("file not found: '%s' -> '%s'" % (ami_path, sys_path))
          return None

        # make some checks on existing file
        if os.path.exists(sys_path):
          # if not writeable -> no append mode
          if not os.access(sys_path, os.W_OK):
            if f_mode[-1] == '+':
              f_mode = f_mode[:-1]

        log_file.debug("opening file: '%s' -> '%s' f_mode=%s" % (ami_path, sys_path, f_mode))
        fobj = open(sys_path, f_mode)
        fh = FileHandle(fobj, ami_path, sys_path)

      self._register_file(fh)
      return fh
    except IOError as e:
      log_file.info("error opening: '%s' -> '%s' f_mode=%s -> %s" % (ami_path, sys_path, f_mode, e))
      return None
Exemplo n.º 2
0
    def open(self, lock, ami_path, f_mode):
        try:
            # special names
            uname = ami_path.upper()
            # thor: NIL: and CONSOLE: also work as device names
            # and the file names behind are ignored.
            if uname.startswith('NIL:'):
                sys_name = "/dev/null"
                if f_mode == "rwb+":
                    f_mode = "rb+"
                fobj = open(sys_name, f_mode)
                fh = FileHandle(fobj, ami_path, sys_name, is_nil=True)
            elif uname == '*' or uname.startswith('CONSOLE:'):
                sys_name = ''
                fh = FileHandle(sys.stdout, '*', '', need_close=False)
            else:
                # map to system path
                sys_path = self.path_mgr.ami_to_sys_path(lock,
                                                         ami_path,
                                                         searchMulti=True)
                if sys_path == None:
                    log_file.info("file not found: '%s' -> '%s'" %
                                  (ami_path, sys_path))
                    return None

                # make some checks on existing file
                if os.path.exists(sys_path):
                    # if not writeable -> no append mode
                    if f_mode == "rwb+":
                        f_mode = "rb+"
                    if not os.access(sys_path, os.W_OK):
                        if f_mode[-1] == '+':
                            f_mode = f_mode[:-1]
                else:
                    # if the file does not exist, but the mode is MODE_READWRITE, create it.
                    if f_mode == "rwb+":
                        f_mode = "wb+"

                log_file.debug("opening file: '%s' -> '%s' f_mode=%s" %
                               (ami_path, sys_path, f_mode))
                fobj = open(sys_path, f_mode)
                fh = FileHandle(fobj, ami_path, sys_path)

            self._register_file(fh)
            return fh
        except IOError as e:
            log_file.info("error opening: '%s' -> '%s' f_mode=%s -> %s" %
                          (ami_path, sys_path, f_mode, e))
            return None
Exemplo n.º 3
0
  def open(self, lock, ami_path, f_mode):
    try:
      # special names
      uname = ami_path.upper()
      # thor: NIL: and CONSOLE: also work as device names
      # and the file names behind are ignored.
      if uname.startswith('NIL:'):
        sys_name = "/dev/null"
        if f_mode == "rwb+":
          f_mode = "rb+"
        fobj = open(sys_name, f_mode)
        fh   = FileHandle(fobj, ami_path, sys_name, is_nil = True)
      elif uname == '*' or uname.startswith('CONSOLE:'):
        sys_name = ''
        fh = FileHandle(sys.stdout,'*','',need_close=False)
      else:
        # map to system path
        sys_path = self.path_mgr.ami_to_sys_path(lock,ami_path,searchMulti=True)
        if sys_path == None:
          log_file.info("file not found: '%s' -> '%s'" % (ami_path, sys_path))
          return None

        # make some checks on existing file
        if os.path.exists(sys_path):
          # if not writeable -> no append mode
          if f_mode == "rwb+":
            f_mode = "rb+"
          if not os.access(sys_path, os.W_OK):
            if f_mode[-1] == '+':
              f_mode = f_mode[:-1]
        else:
          # if the file does not exist, but the mode is MODE_READWRITE, create it.
          if f_mode == "rwb+":
            f_mode = "wb+"

        log_file.debug("opening file: '%s' -> '%s' f_mode=%s" % (ami_path, sys_path, f_mode))
        fobj = open(sys_path, f_mode)
        fh = FileHandle(fobj, ami_path, sys_path)

      self._register_file(fh)
      return fh
    except IOError as e:
      log_file.info("error opening: '%s' -> '%s' f_mode=%s -> %s" % (ami_path, sys_path, f_mode, e))
      return None
Exemplo n.º 4
0
    def open(self, ami_path, f_mode):
        try:
            # special names
            uname = ami_path.upper()
            if uname == 'NIL:':
                sys_name = "/dev/null"
                fobj = open(sys_name, f_mode)
                fh = FileHandle(fobj, ami_path, sys_name)
            elif uname in ('*', 'CONSOLE:'):
                sys_name = ''
                fh = FileHandle(sys.stdout, '*', '', need_close=False)
            else:
                # map to system path
                sys_path = self.path_mgr.ami_to_sys_path(ami_path)
                if sys_path == None:
                    log_file.info("file not found: '%s' -> '%s'" %
                                  (ami_path, sys_path))
                    return None

                # make some checks on existing file
                if os.path.exists(sys_path):
                    # if not writeable -> no append mode
                    if not os.access(sys_path, os.W_OK):
                        if f_mode[-1] == '+':
                            f_mode = f_mode[:-1]

                log_file.debug("opening file: '%s' -> '%s' f_mode=%s" %
                               (ami_path, sys_path, f_mode))
                fobj = open(sys_path, f_mode)
                fh = FileHandle(fobj, ami_path, sys_path)

            self._register_file(fh)
            return fh
        except IOError as e:
            log_file.info("error opening: '%s' -> '%s' f_mode=%s -> %s" %
                          (ami_path, sys_path, f_mode, e))
            return None