Ejemplo n.º 1
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)
Ejemplo n.º 2
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))
Ejemplo n.º 3
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)
Ejemplo n.º 4
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))
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
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))