Пример #1
0
    def link(self, src_in, tgt_in, flags, _from_task=None):

        # link will *only* work if src and tgt are on the same resource (and
        # even then may fail)
        self._is_valid()

        cwdurl = saga.Url(self.url)  # deep copy
        src = saga.Url(src_in)  # deep copy
        tgt = saga.Url(tgt_in)  # deep copy

        rec_flag = ""
        if flags & saga.filesystem.RECURSIVE:
            raise saga.BadParameter(
                "'RECURSIVE' flag not  supported for link()")

        if flags & saga.filesystem.CREATE_PARENTS:
            self._create_parent(cwdurl, tgt)

        # if src and tgt point to the same host, we just run a shell link
        # on that host
        if  sumisc.url_is_compatible (cwdurl, src) and \
            sumisc.url_is_compatible (cwdurl, tgt) :

            # print "shell ln"
            ret, out, err = self._command(" ln -s '%s' '%s'\n" %
                                          (src.path, tgt.path))
            if ret != 0:
                raise saga.NoSuccess ("link (%s -> %s) failed (%s): (out: %s) (err: %s)" \
                                   % (src, tgt, ret, out, err))

        # src and tgt are on different hosts, this is not supported
        else:
            raise saga.BadParameter(
                "link is only supported on same file system as cwd")
Пример #2
0
    def link (self, src_in, tgt_in, flags, _from_task=None):

        # link will *only* work if src and tgt are on the same resource (and
        # even then may fail)
        self._is_valid ()

        cwdurl = saga.Url (self.url) # deep copy
        src    = saga.Url (src_in)   # deep copy
        tgt    = saga.Url (tgt_in)   # deep copy

        rec_flag = ""
        if  flags & saga.filesystem.RECURSIVE : 
            raise saga.BadParameter ("'RECURSIVE' flag not  supported for link()")

        if  flags & saga.filesystem.CREATE_PARENTS : 
            self._create_parent (cwdurl, tgt)

        # if src and tgt point to the same host, we just run a shell link
        # on that host
        if  sumisc.url_is_compatible (cwdurl, src) and \
            sumisc.url_is_compatible (cwdurl, tgt) :

            # print "shell ln"
            ret, out, err = self._command (" ln -s '%s' '%s'\n" % (src.path, tgt.path))
            if  ret != 0 :
                raise saga.NoSuccess ("link (%s -> %s) failed (%s): (out: %s) (err: %s)" \
                                   % (src, tgt, ret, out, err))


        # src and tgt are on different hosts, this is not supported
        else :
            raise saga.BadParameter ("link is only supported on same file system as cwd")
Пример #3
0
    def remove(self, tgt_in, flags):

        self._is_valid()

        # FIXME: eval flags
        # FIXME: check if tgt remove happens to affect cwd... :-P

        cwdurl = saga.Url(self.url)  # deep copy
        tgt = saga.Url(tgt_in)  # deep copy

        rec_flag = ""
        if flags & saga.filesystem.RECURSIVE:
            rec_flag += "-r "

        if sumisc.url_is_compatible(cwdurl, tgt):

            ret, out, err = self._command(" rm -f %s '%s'\n" %
                                          (rec_flag, tgt.path))
            if ret != 0:
                raise saga.NoSuccess ("remove (%s) failed (%s): (out: %s) (err: %s)" \
                                   % (tgt, ret, out, err))

        # we cannot support the URL
        else:
            raise saga.BadParameter("remove of %s is not supported" % tgt)
Пример #4
0
    def change_dir(self, tgt, flags):

        cwdurl = saga.Url(self.url)
        tgturl = saga.Url(tgt)

        if not sumisc.url_is_compatible(cwdurl, tgturl):
            raise saga.BadParameter ("target dir outside of namespace '%s': %s" \
                                  % (cwdurl, tgturl))

        cmd = None

        if  tgturl.path == '.' or \
            tgturl.path == cwdurl.path :
            self._logger.debug("change directory optimized away (%s) == (%s)" %
                               (cwdurl, tgturl))

        if flags & saga.filesystem.CREATE_PARENTS:
            cmd = " mkdir -p '%s' ;  cd '%s'" % (tgturl.path, tgturl.path)
        elif flags & saga.filesystem.CREATE:
            cmd = " mkdir    '%s' ;  cd '%s'" % (tgturl.path, tgturl.path)
        else:
            cmd = " test -d  '%s' && cd '%s'" % (tgturl.path, tgturl.path)

        ret, out, _ = self._command(cmd)

        if ret != 0:
            raise saga.BadParameter("invalid dir '%s': %s" % (cwdurl, tgturl))

        self._logger.debug("changed directory (%s)(%s)" % (ret, out))

        self.valid = True
Пример #5
0
    def _create_parent(self, cwdurl, tgt):

        dirname = sumisc.url_get_dirname(tgt)
        ret = None
        out = None

        if sumisc.url_is_compatible(cwdurl, tgt):

            ret, out, _ = self._command(" mkdir -p '%s'\n" % (dirname),
                                        make_location=True)
            if ret != 0:
                raise saga.NoSuccess ("failed at mkdir '%s': (%s) (%s)" \
                                   % (dirname, ret, out))

        elif sumisc.url_is_local(tgt):

            if tgt.scheme and not tgt.scheme.lower() in _ADAPTOR_SCHEMAS:
                raise saga.BadParameter ("schema of mkdir target is not supported (%s)" \
                                      % (tgt))
            _mkdir_p(dirname)

        else:
            lease_tgt = self._adaptor.get_lease_target(tgt)
            with self.lm.lease(lease_tgt, self.shell_creator,
                               tgt) as tmp_shell:
                tmp_shell.run_sync('mkdir -p %s' % dirname)
Пример #6
0
    def remove (self, tgt_in, flags):

        self._is_valid ()

        # FIXME: eval flags
        # FIXME: check if tgt remove happens to affect cwd... :-P

        cwdurl = saga.Url (self.url) # deep copy
        tgt    = saga.Url (tgt_in)   # deep copy

        if sumisc.url_is_relative (tgt) : tgt = sumisc.url_make_absolute (cwdurl, tgt)

        rec_flag = ""
        if flags & saga.filesystem.RECURSIVE : 
            rec_flag  += "-r "

        if  sumisc.url_is_compatible (cwdurl, tgt) :

            ret, out, _ = self.shell.run_sync ("rm -f %s %s\n" % (rec_flag, tgt.path))
            if  ret != 0 :
                raise saga.NoSuccess ("remove (%s) failed (%s): (%s)" \
                                   % (tgt, ret, out))


        # we cannot support the URL
        else :
            raise saga.BadParameter ("remove of %s is not supported" % tgt)
Пример #7
0
    def _create_parent (self, cwdurl, tgt) :

        dirname = sumisc.url_get_dirname (tgt)

        if sumisc.url_is_compatible (cwdurl, tgt) :

            ret, out, _ = self.shell.run_sync ("mkdir -p %s\n" % (dirname))
            if  ret != 0 :
                raise saga.NoSuccess ("failed at mkdir '%s': (%s) (%s)" \
                                   % (dirname, ret, out))

        elif sumisc.url_is_local (tgt) :

            if tgt.scheme and not tgt.scheme.lower () in _ADAPTOR_SCHEMAS :
                raise saga.BadParameter ("schema of mkdir target is not supported (%s)" \
                                      % (tgt))

            ret, out, _ = self.local.run_sync ("mkdir -p %s\n" % (dirname))
            if  ret != 0 :
                raise saga.NoSuccess ("failed at mkdir '%s': (%s) (%s)" \
                                   % (dirname, ret, out))

        else :
            raise saga.BadParameter ("failed: cannot create target dir for '%s': (%s) (%s)" \
                                  % (tgt, ret, out))
Пример #8
0
    def remove (self, tgt_in, flags):

        self._is_valid ()

        # FIXME: eval flags
        # FIXME: check if tgt remove happens to affect cwd... :-P

        cwdurl = saga.Url (self.url) # deep copy
        tgt    = saga.Url (tgt_in)   # deep copy

        rec_flag = ""
        if  flags & saga.filesystem.RECURSIVE : 
            rec_flag  += "-r "

        if  sumisc.url_is_compatible (cwdurl, tgt) :

            ret, out, err = self._command (" rm -f %s '%s'\n" % (rec_flag, tgt.path))
            if  ret != 0 :
                raise saga.NoSuccess ("remove (%s) failed (%s): (out: %s) (err: %s)" \
                                   % (tgt, ret, out, err))


        # we cannot support the URL
        else :
            raise saga.BadParameter ("remove of %s is not supported" % tgt)
Пример #9
0
    def _create_parent (self, cwdurl, tgt) :

        dirname = sumisc.url_get_dirname (tgt)

        if  sumisc.url_is_compatible (cwdurl, tgt) :

            ret, out, _ = self.shell.obj.run_sync (" mkdir -p '%s'\n" % (dirname))
            if  ret != 0 :
                raise saga.NoSuccess ("failed at mkdir '%s': (%s) (%s)" \
                                   % (dirname, ret, out))

        elif sumisc.url_is_local (tgt) :

            if  tgt.scheme and not tgt.scheme.lower () in _ADAPTOR_SCHEMAS :
                raise saga.BadParameter ("schema of mkdir target is not supported (%s)" \
                                      % (tgt))

            ret, out, _ = self.local.obj.run_sync (" mkdir -p '%s'\n" % (dirname))
            if  ret != 0 :
                raise saga.NoSuccess ("failed at mkdir '%s': (%s) (%s)" \
                                   % (dirname, ret, out))

        else :

            lease_tgt = self._adaptor.get_lease_target (tgt)
            with self.lm.lease (lease_tgt, self.shell_creator, tgt) as tmp_shell :
                tmp_shell.run_sync ('mkdir -p %s' % dirname)
Пример #10
0
    def _create_parent (self, cwdurl, tgt) :

        dirname = sumisc.url_get_dirname (tgt)

        if  sumisc.url_is_compatible (cwdurl, tgt) :

            ret, out, _ = self.shell.obj.run_sync (" mkdir -p '%s'\n" % (dirname))
            if  ret != 0 :
                raise saga.NoSuccess ("failed at mkdir '%s': (%s) (%s)" \
                                   % (dirname, ret, out))

        elif sumisc.url_is_local (tgt) :

            if  tgt.scheme and not tgt.scheme.lower () in _ADAPTOR_SCHEMAS :
                raise saga.BadParameter ("schema of mkdir target is not supported (%s)" \
                                      % (tgt))

            ret, out, _ = self.local.obj.run_sync (" mkdir -p '%s'\n" % (dirname))
            if  ret != 0 :
                raise saga.NoSuccess ("failed at mkdir '%s': (%s) (%s)" \
                                   % (dirname, ret, out))

        else :

            raise saga.BadParameter ("failed: cannot create target dir '%s': not local to pwd (%s)" \
                                  % (tgt, cwdurl))
Пример #11
0
    def change_dir (self, tgt, flags) :

        cwdurl = saga.Url (self.url)
        tgturl = saga.Url (tgt)

        if  not sumisc.url_is_compatible (cwdurl, tgturl) :
            raise saga.BadParameter ("target dir outside of namespace '%s': %s" \
                                  % (cwdurl, tgturl))

        cmd = None

        if  tgturl.path == '.' or \
            tgturl.path == cwdurl.path :
            self._logger.debug ("change directory optimized away (%s) == (%s)" % (cwdurl, tgturl))


        if  flags & saga.filesystem.CREATE_PARENTS :
            cmd = " mkdir -p '%s' ;  cd '%s'" % (tgturl.path, tgturl.path)
        elif flags & saga.filesystem.CREATE :
            cmd = " mkdir    '%s' ;  cd '%s'" % (tgturl.path, tgturl.path)
        else :
            cmd = " test -d  '%s' && cd '%s'" % (tgturl.path, tgturl.path)

        ret, out, _ = self._command (cmd)

        if  ret != 0 :
            raise saga.BadParameter ("invalid dir '%s': %s" % (cwdurl, tgturl))

        self._logger.debug ("changed directory (%s)(%s)" % (ret, out))

        self.valid = True
Пример #12
0
    def get_path_spec(self,
                      session,
                      url,
                      path=None,
                      cwd_url=None,
                      cwd_path=None):

        # we assume that, whenever we request a path spec, we also want to use
        # it, and we thus register and activate the endpoint, if needed.

        sid = session._id

        if not sid in self.shells:
            raise saga.IncorrectState("GO shell disconnected")

        shell = self.shells[sid]['shell']
        url = saga.Url(url)

        if not path:
            path = url.path

        if not cwd_url:
            cwd_url = saga.Url(url)

            if not cwd_path:
                cwd_path = '.'
        else:
            if not cwd_path:
                cwd_path = cwd_url.path

        if not url.host:
            url.host = cwd_url.host
        if not url.schema:
            url.schema = cwd_url.schema

        if not url.host:
            raise saga.BadParameter('need host for GO ops')
        if not url.schema:
            raise saga.BadParameter('need schema for GO ops')

        ep_name, ep_url = self.get_go_endpoint_ids(session, url)

        # if both URLs point into the same namespace, and if the given path is
        # not absolute, then expand it relative to the cwd_path (if it exists).
        # Otherwise it is left to the unmodified path.
        ps_path = path
        # TODO: should the check be on cwd_url / url or on ep_url?
        if sumisc.url_is_compatible(cwd_url, url) and not path.startswith('/'):
            if cwd_path and path:
                ps_path = os.path.join(cwd_path, path)
            elif cwd_path:
                ps_path = cwd_path

        # the pathspec is the concatenation of ps_host and ps_path by a colon
        ps = "%s:%s" % (ep_name, ps_path)

        # check if we know the endpoint in XXX, and create/activate as needed
        ep = self.get_go_endpoint(session, shell, ep_url)

        return ps
Пример #13
0
    def get_path_spec(self, session, url, path=None, cwd_url=None, cwd_path=None):

        # we assume that, whenever we request a path spec, we also want to use
        # it, and we thus register and activate the endpoint, if needed.

        sid = session._id

        if not sid in self.shells:
            raise saga.IncorrectState("GO shell disconnected")

        shell = self.shells[sid]['shell']
        url   = saga.Url(url)

        if not path:
            path = url.path

        if not cwd_url:
            cwd_url = saga.Url(url)

            if not cwd_path:
                cwd_path = '.'
        else:
            if not cwd_path:
                cwd_path = cwd_url.path

        if not url.host:
            url.host = cwd_url.host
        if not url.schema:
            url.schema = cwd_url.schema

        if not url.host:
            raise saga.BadParameter('need host for GO ops')
        if not url.schema:
            raise saga.BadParameter('need schema for GO ops')

        ep_name, ep_url = self.get_go_endpoint_ids(session, url)

        # if both URLs point into the same namespace, and if the given path is
        # not absolute, then expand it relative to the cwd_path (if it exists).
        # Otherwise it is left to the unmodified path.
        ps_path = path
        # TODO: should the check be on cwd_url / url or on ep_url?
        if sumisc.url_is_compatible(cwd_url, url) and not path.startswith('/'):
            if cwd_path and path:
                ps_path = os.path.join(cwd_path, path)
            elif cwd_path:
                ps_path = cwd_path

        # the pathspec is the concatenation of ps_host and ps_path
        ps = "%s%s" % (ep_name, ps_path)

        # check if we know the endpoint in XXX, and create/activate as needed
        ep = self.get_go_endpoint(session, shell, ep_url)

        return ps
Пример #14
0
    def change_dir(self, tgt):

        # backup state
        orig_url = self._url

        try:
            if not sumisc.url_is_compatible(tgt, self._url):
                raise se.BadParameter("cannot chdir to %s, leaves namespace" %
                                      tgt)

            self._url = sumisc.url_make_absolute(tgt, self._url)
            self._init_check()

        finally:
            # restore state on error
            self._url = orig_url
Пример #15
0
    def change_dir (self, tgt) :

        # backup state
        orig_url = self._url

        try :
            if  not sumisc.url_is_compatible (tgt, self._url) :
                raise se.BadParameter ("cannot chdir to %s, leaves namespace" % tgt)

            self._url = sumisc.url_make_absolute (tgt, self_url)
            self._init_check ()


        finally :
            # restore state on error
            self._url = orig_url
Пример #16
0
    def _create_parent(self, cwdurl, tgt):

        dirname = sumisc.url_get_dirname(tgt)

        if sumisc.url_is_compatible(cwdurl, tgt):

            ret, out, _ = self._run_sync(" mkdir -p '%s'\n" % (dirname))
            if ret:
                raise saga.NoSuccess("failed at mkdir '%s': (%s) (%s)" %
                                     (dirname, ret, out))

        elif sumisc.url_is_local(tgt):

            if tgt.scheme and tgt.scheme.lower() not in _ADAPTOR_SCHEMAS:
                raise saga.BadParameter("unsupported mkdir schema (%s)" % tgt)
            _mkdir_p(dirname)

        else:

            lease_tgt = self._adaptor.get_lease_target(tgt)
            with self.lm.lease(lease_tgt, self.shell_creator,
                               tgt) as tmp_shell:
                tmp_shell.run_sync('mkdir -p %s' % dirname)
Пример #17
0
    def change_dir(self, tgt, flags):

        tgt_url = saga.Url(tgt)

        # TODO: attempt to get new EP
        if not sumisc.url_is_compatible(self.url, tgt_url):
            raise saga.BadParameter("Target dir outside of namespace '%s': %s" \
                                  % (self.url, tgt_url))

        if sumisc.url_is_relative(tgt_url):

            self.path      = tgt_url.path
            self.orig.path = self.path

        else:
            self.orig      = saga.Url(tgt_url)
            self.url       = tgt_url
            self.path      = self.url.path
            self.url.path  = None

        self.initialize()

        self._logger.debug("changed directory (%s)" % (tgt))
Пример #18
0
    def change_dir (self, tgt, flags) :

        tgt_url = saga.Url (tgt)

        # FIXME: attempt to get new EP
        if  not sumisc.url_is_compatible (self.url, tgt_url) :
            raise saga.BadParameter ("target dir outside of namespace '%s': %s" \
                                  % (self.url, tgt_url))

        if sumisc.url_is_relative (tgt_url) :

            self.path      = tgt_url.path
            self.orig.path = self.path

        else :
            self.orig      = saga.Url (tgt_url)
            self.url       = tgt_url
            self.path      = self.url.path
            self.url.path  = None

        self.initialize ()

        self._logger.debug ("changed directory (%s)" % (tgt))
Пример #19
0
    def copy(self, src_in, tgt_in, flags, _from_task=None):

        self._is_valid()

        # FIXME: eval flags

        cwdurl = saga.Url(self.url)  # deep copy
        src = saga.Url(src_in)  # deep copy
        tgt = saga.Url(tgt_in)  # deep copy

        if sumisc.url_is_relative(src):
            src = sumisc.url_make_absolute(cwdurl, src)
        if sumisc.url_is_relative(tgt):
            tgt = sumisc.url_make_absolute(cwdurl, tgt)

        rec_flag = ""
        if flags & saga.filesystem.RECURSIVE:
            rec_flag += "-r "

        files_copied = list()

        # if cwd, src and tgt point to the same host, we just run a shell cp
        # command on that host
        if  sumisc.url_is_compatible (cwdurl, src) and \
            sumisc.url_is_compatible (cwdurl, tgt) :

            if flags & saga.filesystem.CREATE_PARENTS:
                self._create_parent(cwdurl, tgt)

            # print "shell cp"
            ret, out, err = self._command(" cp %s '%s' '%s'\n" %
                                          (rec_flag, src.path, tgt.path))
            if ret != 0:
                raise saga.NoSuccess ("copy (%s -> %s) failed (%s): (out: %s) (err: %s)" \
                                   % (src, tgt, ret, out, err))

        # src and tgt are on different hosts, we need to find out which of them
        # is local (stage_from vs. stage_to).
        else:
            # print "! shell cp"

            # for a remote target, we need to manually create the target dir (if
            # needed)
            if flags & saga.filesystem.CREATE_PARENTS:
                self._create_parent(cwdurl, tgt)

            # if cwd is remote, we use stage from/to
            if not sumisc.url_is_local(cwdurl):

                # print "cwd remote"
                if  sumisc.url_is_local (src)          and \
                    sumisc.url_is_compatible (cwdurl, tgt) :

                    # print "from local to remote: %s -> %s" % (src.path, tgt.path)
                    lease_tgt = self._adaptor.get_lease_target(self.url)
                    with self.lm.lease (lease_tgt, self.shell_creator, self.url) \
                        as copy_shell :
                        files_copied = copy_shell.stage_to_remote(
                            src.path, tgt.path, rec_flag)

                elif sumisc.url_is_local (tgt)          and \
                     sumisc.url_is_compatible (cwdurl, src) :

                    # print "from remote to local: %s -> %s" % (src.path, tgt.path)
                    lease_tgt = self._adaptor.get_lease_target(self.url)
                    with self.lm.lease (lease_tgt, self.shell_creator, self.url) \
                        as copy_shell :
                        files_copied = copy_shell.stage_from_remote(
                            src.path, tgt.path, rec_flag)

                else:
                    # print "from remote to other remote -- fail"
                    # we cannot support the combination of URLs
                    raise saga.BadParameter ("copy from %s to %s is not supported" \
                                          % (src, tgt))

            # if cwd is local, and src or tgt are remote, we need to actually
            # create a new pipe to the target host.  note that we may not have
            # a useful session for that!
            else:  # sumisc.url_is_local (cwdurl) :

                # print "cwd local"

                if sumisc.url_is_local(src):

                    # need a compatible target scheme
                    if tgt.scheme and not tgt.scheme.lower(
                    ) in _ADAPTOR_SCHEMAS:
                        raise saga.BadParameter ("schema of copy target is not supported (%s)" \
                                              % (tgt))

                    # print "from local to remote"
                    lease_tgt = self._adaptor.get_lease_target(tgt)
                    with self.lm.lease (lease_tgt, self.shell_creator, tgt) \
                        as copy_shell :
                        files_copied = copy_shell.stage_to_remote(
                            src.path, tgt.path, rec_flag)

                elif sumisc.url_is_local(tgt):

                    # need a compatible source scheme
                    if src.scheme and not src.scheme.lower(
                    ) in _ADAPTOR_SCHEMAS:
                        raise saga.BadParameter ("schema of copy source is not supported (%s)" \
                                              % (src))

                    # print "from remote to local"
                    lease_tgt = self._adaptor.get_lease_target(tgt)
                    with self.lm.lease (lease_tgt, self.shell_creator, tgt) \
                        as copy_shell :
                        files_copied = copy_shell.stage_from_remote(
                            src.path, tgt.path, rec_flag)

                else:

                    # print "from remote to other remote -- fail"
                    # we cannot support the combination of URLs
                    raise saga.BadParameter ("copy from %s to %s is not supported" \
                                          % (src, tgt))

        if _from_task:
            _from_task._set_metric('files_copied', files_copied)
Пример #20
0
    def copy_self (self, tgt_in, flags):

        self._is_valid ()

        # FIXME: eval flags

        # print "copy self %s -> %s" % (self.url, tgt_in)

        cwdurl = saga.Url (self.cwdurl) # deep copy
        src    = saga.Url (self.url)    # deep copy
        tgt    = saga.Url (tgt_in)      # deep copy

        if sumisc.url_is_relative (src) : src = sumisc.url_make_absolute (cwdurl, src)
        if sumisc.url_is_relative (tgt) : tgt = sumisc.url_make_absolute (cwdurl, tgt)

        rec_flag = ""
        if flags & saga.filesystem.RECURSIVE : 
            rec_flag  += "-r "

        if flags & saga.filesystem.CREATE_PARENTS : 
            self._create_parent (cwdurl, tgt)

        # print cwdurl
        # print src
        # print tgt

        # if cwd, src and tgt point to the same host, we just run a shell cp
        # command on that host
        if  sumisc.url_is_compatible (cwdurl, src) and \
            sumisc.url_is_compatible (cwdurl, tgt) :

            # print "shell cp"
            ret, out, _ = self.shell.run_sync ("cp %s %s %s\n" % (rec_flag, src.path, tgt.path))
            if  ret != 0 :
                raise saga.NoSuccess ("copy (%s -> %s) failed (%s): (%s)" \
                                   % (src, tgt, ret, out))


        # src and tgt are on different hosts, we need to find out which of them
        # is local (stage_from vs. stage_to).
        else :
            # print "! shell cp"

            # if cwd is remote, we use stage from/to on the existing pipe
            if not sumisc.url_is_local (cwdurl) :

                # print "cwd remote"

                if sumisc.url_is_local (src)          and \
                   sumisc.url_is_compatible (cwdurl, tgt) :

                    # print "from local to remote"
                    self.shell.stage_to_remote (src.path, tgt.path, rec_flag)

                elif sumisc.url_is_local (tgt)          and \
                     sumisc.url_is_compatible (cwdurl, src) :

                    # print "from remote to loca"
                    self.shell.stage_from_remote (src.path, tgt.path, rec_flag)

                else :
                    # print "from remote to other remote -- fail"
                    # we cannot support the combination of URLs
                    raise saga.BadParameter ("copy from %s to %s is not supported" \
                                          % (src, tgt))
   

            # if cwd is local, and src or tgt are remote, we need to actually
            # create a new pipe to the target host.  note that we may not have
            # a useful session for that!
            else : # sumisc.url_is_local (cwdurl) :

                # print "cwd local"

                if sumisc.url_is_local (src) :

                    # need a compatible target scheme
                    if tgt.scheme and not tgt.scheme.lower () in _ADAPTOR_SCHEMAS :
                        raise saga.BadParameter ("schema of copy target is not supported (%s)" \
                                              % (tgt))

                    # print "from local to remote"
                    tmp_shell = sups.PTYShell (tgt, self.session, self._logger)
                    tmp_shell.stage_to_remote (src.path, tgt.path, rec_flag)

                elif sumisc.url_is_local (tgt) :

                    # need a compatible source scheme
                    if src.scheme and not src.scheme.lower () in _ADAPTOR_SCHEMAS :
                        raise saga.BadParameter ("schema of copy source is not supported (%s)" \
                                              % (src))

                    # print "from remote to local"
                    tmp_shell = sups.PTYShell (src, self.session, self._logger)
                    tmp_shell.stage_from_remote (src.path, tgt.path, rec_flag)

                else :

                    # print "from remote to other remote -- fail"
                    # we cannot support the combination of URLs
                    raise saga.BadParameter ("copy from %s to %s is not supported" \
                                          % (src, tgt))
Пример #21
0
    def copy (self, src_in, tgt_in, flags, _from_task=None):

        self._is_valid ()

        # FIXME: eval flags

        cwdurl = saga.Url (self.url) # deep copy
        src    = saga.Url (src_in)   # deep copy
        tgt    = saga.Url (tgt_in)   # deep copy

        if  sumisc.url_is_relative (src) : src = sumisc.url_make_absolute (cwdurl, src)
        if  sumisc.url_is_relative (tgt) : tgt = sumisc.url_make_absolute (cwdurl, tgt)
    
        rec_flag = ""
        if  flags & saga.filesystem.RECURSIVE : 
            rec_flag  += "-r "

        files_copied = list()

        # if cwd, src and tgt point to the same host, we just run a shell cp
        # command on that host
        if  sumisc.url_is_compatible (cwdurl, src) and \
            sumisc.url_is_compatible (cwdurl, tgt) :

            if  flags & saga.filesystem.CREATE_PARENTS : 
                self._create_parent (cwdurl, tgt)

            # print "shell cp"
            ret, out, err = self._command (" cp %s '%s' '%s'\n" % (rec_flag, src.path, tgt.path))
            if  ret != 0 :
                raise saga.NoSuccess ("copy (%s -> %s) failed (%s): (out: %s) (err: %s)" \
                                   % (src, tgt, ret, out, err))


        # src and tgt are on different hosts, we need to find out which of them
        # is local (stage_from vs. stage_to).
        else :
            # print "! shell cp"

            # for a remote target, we need to manually create the target dir (if
            # needed)
            if  flags & saga.filesystem.CREATE_PARENTS : 
                self._create_parent (cwdurl, tgt)


            # if cwd is remote, we use stage from/to
            if  not sumisc.url_is_local (cwdurl) :

                # print "cwd remote"
                if  sumisc.url_is_local (src)          and \
                    sumisc.url_is_compatible (cwdurl, tgt) :

                  # print "from local to remote: %s -> %s" % (src.path, tgt.path)
                    lease_tgt = self._adaptor.get_lease_target (self.url)
                    with self.lm.lease (lease_tgt, self.shell_creator, self.url) \
                        as copy_shell :
                        files_copied = copy_shell.stage_to_remote (src.path, tgt.path, rec_flag)

                elif sumisc.url_is_local (tgt)          and \
                     sumisc.url_is_compatible (cwdurl, src) :

                  # print "from remote to local: %s -> %s" % (src.path, tgt.path)
                    lease_tgt = self._adaptor.get_lease_target (self.url)
                    with self.lm.lease (lease_tgt, self.shell_creator, self.url) \
                        as copy_shell :
                        files_copied = copy_shell.stage_from_remote (src.path, tgt.path, rec_flag)

                else :
                    # print "from remote to other remote -- fail"
                    # we cannot support the combination of URLs
                    raise saga.BadParameter ("copy from %s to %s is not supported" \
                                          % (src, tgt))
   

            # if cwd is local, and src or tgt are remote, we need to actually
            # create a new pipe to the target host.  note that we may not have
            # a useful session for that!
            else : # sumisc.url_is_local (cwdurl) :

                # print "cwd local"

                if  sumisc.url_is_local (src) :

                    # need a compatible target scheme
                    if  tgt.scheme and not tgt.scheme.lower () in _ADAPTOR_SCHEMAS :
                        raise saga.BadParameter ("schema of copy target is not supported (%s)" \
                                              % (tgt))

                    # print "from local to remote"
                    lease_tgt = self._adaptor.get_lease_target (tgt)
                    with self.lm.lease (lease_tgt, self.shell_creator, tgt) \
                        as copy_shell :
                        files_copied = copy_shell.stage_to_remote (src.path, tgt.path, rec_flag)

                elif sumisc.url_is_local (tgt) :

                    # need a compatible source scheme
                    if  src.scheme and not src.scheme.lower () in _ADAPTOR_SCHEMAS :
                        raise saga.BadParameter ("schema of copy source is not supported (%s)" \
                                              % (src))

                    # print "from remote to local"
                    lease_tgt = self._adaptor.get_lease_target (tgt)
                    with self.lm.lease (lease_tgt, self.shell_creator, tgt) \
                        as copy_shell :
                        files_copied = copy_shell.stage_from_remote (src.path, tgt.path, rec_flag)

                else :

                    # print "from remote to other remote -- fail"
                    # we cannot support the combination of URLs
                    raise saga.BadParameter ("copy from %s to %s is not supported" \
                                          % (src, tgt))

   
        if  _from_task :
            _from_task._set_metric ('files_copied', files_copied)