Example #1
0
    def make_dir (self, tgt_in, flags):

        self._is_valid ()

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

        tgt_abs = sumisc.url_make_absolute (cwdurl, tgturl)

        if  flags & saga.filesystem.EXCLUSIVE : 
            # FIXME: this creates a race condition between testing for exclusive
            # mkdir and creating the dir.
            ret, out, _ = self.shell.run_sync ("test -d %s " % tgt_abs.path)

            if  ret != 0 :
                raise saga.AlreadyExists ("make_dir target (%s) exists (%s)" \
                    % tgt_in, out)


        options = ""

        if  flags & saga.filesystem.CREATE_PARENTS : 
            options += "-p"

        self.shell.run_sync ("mkdir %s %s" % (options, tgt_abs.path))
Example #2
0
    def init_instance(self, adaptor_state, url, flags, session):

        # FIXME: eval flags!

        self._logger.info("init_instance %s" % url)

        if 'from_open' in adaptor_state and adaptor_state['from_open']:
            self.url = saga.Url(url)  # deep copy
            self.flags = flags
            self.session = session
            self.valid = False  # will be set by initialize
            self.cwdurl = saga.Url(adaptor_state["cwd"])
            self.cwd = self.cwdurl.path

            if sumisc.url_is_relative(self.url):
                self.url = sumisc.url_make_absolute(self.cwd, self.url)

        else:
            if sumisc.url_is_relative(url):
                raise saga.BadParameter("cannot interprete relative URL in this context ('%s')" % url)

            self.url = url
            self.flags = flags
            self.session = session
            self.valid = False  # will be set by initialize
            self.cwd = sumisc.url_get_dirname(url)

            self.cwdurl = saga.Url(url)  # deep copy
            self.cwdurl.path = self.cwd

        self.initialize()
        return self.get_api()
Example #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

        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)
Example #4
0
    def init_instance(self, adaptor_state, url, flags, session):

        # FIXME: eval flags!

        self._logger.info("init_instance %s" % url)

        if 'from_open' in adaptor_state and adaptor_state['from_open']:
            self.url = saga.Url(url)  # deep copy
            self.flags = flags
            self.session = session
            self.valid = False  # will be set by initialize
            self.cwdurl = saga.Url(adaptor_state["cwd"])
            self.cwd = self.cwdurl.path

            if sumisc.url_is_relative(self.url):
                self.url = sumisc.url_make_absolute(self.cwd, self.url)

        else:
            if sumisc.url_is_relative(url):
                raise saga.BadParameter("cannot interprete relative URL in this context ('%s')" % url)

            self.url = url
            self.flags = flags
            self.session = session
            self.valid = False  # will be set by initialize
            self.cwd = sumisc.url_get_dirname(url)

            self.cwdurl = saga.Url(url)  # deep copy
            self.cwdurl.path = self.cwd

        self.initialize()
        return self.get_api()
Example #5
0
    def is_dir(self, name):

        try:
            saga.advert.Directory(sumisc.url_make_absolute(self._url, name))
        except Exception as e:
            return False

        return True
Example #6
0
    def is_dir (self, name) :

        try :
            saga.advert.Directory (sumisc.url_make_absolute (self._url, name))
        except Exception as e:
            return False

        return True
Example #7
0
    def open_dir (self, url, flags) :

        self._is_valid ()

        adaptor_state = { "from_open" : True,
                          "cwd"       : saga.Url(self.url) }  # deep copy

        if  sumisc.url_is_relative (url) :
            url = sumisc.url_make_absolute (self.get_url (), url)

        return saga.filesystem.Directory (url=url, flags=flags, session=self.session, 
                                          _adaptor=self._adaptor, _adaptor_state=adaptor_state)
Example #8
0
    def init_instance (self, adaptor_state, url, flags, session):

        # FIXME: eval flags!
        if  flags == None :
            flags = 0

        self._logger.info ("init_instance %s" % url)

        if  'from_open' in adaptor_state and adaptor_state['from_open'] :

            # comes from job.service.create_job()
            self.url         = saga.Url(url) # deep copy
            self.flags       = flags
            self.session     = session
            self.valid       = False  # will be set by initialize
            self.cwdurl      = saga.Url (adaptor_state["cwd"])
            self.cwd         = self.cwdurl.path

            if  sumisc.url_is_relative (self.url) :
                self.url = sumisc.url_make_absolute (self.cwd, self.url)

        else :

            if  sumisc.url_is_relative (url) :
                raise saga.BadParameter ("cannot interprete relative URL in this context ('%s')" % url)

            self.url         = url
            self.flags       = flags
            self.session     = session
            self.valid       = False  # will be set by initialize
            self.cwd         = sumisc.url_get_dirname (url)

            self.cwdurl      = saga.Url (url) # deep copy
            self.cwdurl.path = self.cwd


        # FIXME: get ssh Master connection from _adaptor dict
        self.shell = sups.PTYShell (self.url, self.session, self._logger)

      # self.shell.set_initialize_hook (self.initialize)
      # self.shell.set_finalize_hook   (self.finalize)

        self.initialize ()


        # we create a local shell handle, too, if only to support copy and move
        # to and from local file systems (mkdir for staging target, remove of move
        # source).  Not that we do not perform a cd on the local shell -- all
        # operations are assumed to be performed on absolute paths.
        self.local = sups.PTYShell ('fork://localhost/', saga.Session(default=True), 
                                    self._logger)

        return self.get_api ()
Example #9
0
    def is_link (self, tgt_in):

        self._is_valid ()

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

        tgt_abs = sumisc.url_make_absolute (cwdurl, tgturl)

        ret, out, _ = self.shell.run_sync ("test -h %s" % tgt_abs.path)

        return True if ret == 0 else False
Example #10
0
    def open_dir (self, url, flags) :

        self._is_valid ()

        adaptor_state = { "from_open" : True,
                          "cwd"       : saga.Url(self.url) }  # deep copy

        if  sumisc.url_is_relative (url) :
            url = sumisc.url_make_absolute (self.get_url (), url)

        return saga.filesystem.Directory (url=url, flags=flags, session=self.session, 
                                          _adaptor=self._adaptor, _adaptor_state=adaptor_state)
Example #11
0
    def open (self, url, flags) :

        self._is_valid ()

        adaptor_state = { "from_open" : True,
                          "url"       : saga.Url (self.url),   # deep copy
                          "path"      : self.path}

        if  sumisc.url_is_relative (url) :
            url = sumisc.url_make_absolute (self.get_url (), url)

        return saga.filesystem.File (url=url, flags=flags, session=self.session, 
                                     _adaptor=self._adaptor, _adaptor_state=adaptor_state)
Example #12
0
    def open(self, url, flags):

        self._is_valid()

        adaptor_state = { "from_open" : True,
                          "url"       : saga.Url(self.url),   # deep copy
                          "path"      : self.path}

        if sumisc.url_is_relative(url):
            url = sumisc.url_make_absolute(self.get_url(), url)

        return saga.filesystem.File(url=url, flags=flags, session=self.session,
                                     _adaptor=self._adaptor, _adaptor_state=adaptor_state)
Example #13
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
Example #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
Example #15
0
    def get_size (self, tgt_in) :

        self._is_valid ()

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

        tgt_abs = sumisc.url_make_absolute (cwdurl, tgt)

        ret, out, _ = self.shell.run_sync ("du -ks %s  | xargs | cut -f 1 -d ' '\n" % tgt.path)
        if  ret != 0 :
            raise saga.NoSuccess ("get size for (%s) failed (%s): (%s)" \
                               % (tgt, ret, out))

        size = None
        try :
            size = int (out) * 1024 # see '-k' option to 'du'
        except Exception as e :
            raise saga.NoSuccess ("could not get file size: %s" % out)

        return size
Example #16
0
    def open (self, url, flags) :

        self._is_valid ()

        # NOTE:
        # In principle, we could also pass the self.shell here, to re-use
        # existing connections.  However, that would imply:
        #   - strictly keeping cwd on adaptor side, and always compute complete
        #     paths here
        #   - ensure thread safety accross API objects
        #   - ensure shell lifetime management
        # This seems not worth the tradeoff until we hit connection and session
        # limit too frequently...

        adaptor_state = { "from_open" : True,
                          "cwd"       : saga.Url(self.url) }  # deep copy

        if  sumisc.url_is_relative (url) :
            url = sumisc.url_make_absolute (self.get_url (), url)

        return saga.filesystem.File (url=url, flags=flags, session=self.session, 
                                     _adaptor=self._adaptor, _adaptor_state=adaptor_state)
Example #17
0
    def open (self, url, flags) :

        self._is_valid ()

        # NOTE:
        # In principle, we could also pass the self.shell here, to re-use
        # existing connections.  However, that would imply:
        #   - strictly keeping cwd on adaptor side, and always compute complete
        #     paths here
        #   - ensure thread safety accross API objects
        #   - ensure shell lifetime management
        # This seems not worth the tradeoff until we hit connection and session
        # limit too frequently...

        adaptor_state = { "from_open" : True,
                          "cwd"       : saga.Url(self.url) }  # deep copy

        if sumisc.url_is_relative (url) :
            url = sumisc.url_make_absolute (self.get_url (), url)

        return saga.filesystem.File (url=url, flags=flags, session=self.session, 
                                     _adaptor=self._adaptor, _adaptor_state=adaptor_state)
Example #18
0
    def init_instance (self, adaptor_state, url, flags, session):

        # FIXME: eval flags!
        if  flags == None :
            flags = 0

        self._logger.info ("init_instance %s" % url)

        if  'from_open' in adaptor_state and adaptor_state['from_open'] :

            # comes from job.service.create_job()
            self.url         = saga.Url(url) # deep copy
            self.flags       = flags
            self.session     = session
            self.valid       = False  # will be set by initialize
            self.lm          = session._lease_manager

            self.cwdurl      = saga.Url (adaptor_state["cwd"])
            self.cwd         = self.cwdurl.path

            if  sumisc.url_is_relative (self.url) :
                self.url = sumisc.url_make_absolute (self.cwd, self.url)

        else :

            if  sumisc.url_is_relative (url) :
                raise saga.BadParameter ("cannot interprete relative URL in this context ('%s')" % url)

            self.url         = url
            self.flags       = flags
            self.session     = session
            self.valid       = False  # will be set by initialize
            self.lm          = session._lease_manager

            self.cwd         = sumisc.url_get_dirname (url)
            self.cwdurl      = saga.Url (url) # deep copy
            self.cwdurl.path = self.cwd

            if  not self.flags :
                self.flags = 0

        # Use `_set_session` method of the base class to set the session object
        # `_set_session` and `get_session` methods are provided by `CPIBase`.
        self._set_session(session)

        def _shell_creator (url) :
            return sups.PTYShell (url, self.get_session(), self._logger)
        self.shell_creator = _shell_creator

     #  # self.shell is also a leased shell -- for File, it does not have any
     #  # state, really.
     #  # FIXME: get ssh Master connection from _adaptor dict
     #  lease_tgt  = self._adaptor.get_lease_target (self.url)
     #  self.shell = self.lm.lease (lease_tgt, self.shell_creator, self.url) 
     #  # TODO : release shell
     #
     ## self.shell.set_initialize_hook (self.initialize)
     ## self.shell.set_finalize_hook   (self.finalize)

        self.initialize ()

        return self.get_api ()
Example #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)
Example #20
0
    def init_instance(self, adaptor_state, url, flags, session):

        # FIXME: eval flags!
        if flags == None:
            flags = 0

        self._logger.info("init_instance %s" % url)

        if 'from_open' in adaptor_state and adaptor_state['from_open']:

            # comes from job.service.create_job()
            self.url = saga.Url(url)  # deep copy
            self.flags = flags
            self.session = session
            self.valid = False  # will be set by initialize
            self.lm = session._lease_manager

            self.cwdurl = saga.Url(adaptor_state["cwd"])
            self.cwd = self.cwdurl.path

            if sumisc.url_is_relative(self.url):
                self.url = sumisc.url_make_absolute(self.cwd, self.url)

        else:

            if sumisc.url_is_relative(url):
                raise saga.BadParameter(
                    "cannot interprete relative URL in this context ('%s')" %
                    url)

            self.url = url
            self.flags = flags
            self.session = session
            self.valid = False  # will be set by initialize
            self.lm = session._lease_manager

            self.cwd = sumisc.url_get_dirname(url)
            self.cwdurl = saga.Url(url)  # deep copy
            self.cwdurl.path = self.cwd

            if not self.flags:
                self.flags = 0

        # Use `_set_session` method of the base class to set the session object
        # `_set_session` and `get_session` methods are provided by `CPIBase`.
        self._set_session(session)

        def _shell_creator(url):
            return sups.PTYShell(url, self.get_session(), self._logger)

        self.shell_creator = _shell_creator

        #  # self.shell is also a leased shell -- for File, it does not have any
        #  # state, really.
        #  # FIXME: get ssh Master connection from _adaptor dict
        #  lease_tgt  = self._adaptor.get_lease_target (self.url)
        #  self.shell = self.lm.lease (lease_tgt, self.shell_creator, self.url)
        #  # TODO : release shell
        #
        ## self.shell.set_initialize_hook (self.initialize)
        ## self.shell.set_finalize_hook   (self.finalize)

        self.initialize()

        return self.get_api()
Example #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)
Example #22
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))
Example #23
0
    def init_instance (self, adaptor_state, url, flags, session):

        # FIXME: eval flags!
        if  flags == None :
            flags = 0

        self._logger.info ("init_instance %s" % url)

        if  'from_open' in adaptor_state and adaptor_state['from_open'] :

            # comes from job.service.create_job()
            self.url         = saga.Url(url) # deep copy
            self.flags       = flags
            self.session     = session
            self.valid       = False  # will be set by initialize
            self.lm          = session._lease_manager

            self.cwdurl      = saga.Url (adaptor_state["cwd"])
            self.cwd         = self.cwdurl.path

            if  sumisc.url_is_relative (self.url) :
                self.url = sumisc.url_make_absolute (self.cwd, self.url)

        else :

            if  sumisc.url_is_relative (url) :
                raise saga.BadParameter ("cannot interprete relative URL in this context ('%s')" % url)

            self.url         = url
            self.flags       = flags
            self.session     = session
            self.valid       = False  # will be set by initialize
            self.lm          = session._lease_manager

            self.cwd         = sumisc.url_get_dirname (url)
            self.cwdurl      = saga.Url (url) # deep copy
            self.cwdurl.path = self.cwd


        def _shell_creator (url) :
            return sups.PTYShell (url, self.session, self._logger)
        self.shell_creator = _shell_creator

        # self.shell is also a leased shell -- for File, it does not have any
        # state, really.
        # FIXME: get ssh Master connection from _adaptor dict
        lease_tgt  = self._adaptor.get_lease_target (self.url)
        self.shell = self.lm.lease (lease_tgt, self.shell_creator, self.url) 
        # TODO : release shell

      # self.shell.obj.set_initialize_hook (self.initialize)
      # self.shell.obj.set_finalize_hook   (self.finalize)

        self.initialize ()


        # we lease a local shell handle, too, if only to support copy and move
        # to and from local file systems (mkdir for staging target, remove of move
        # source).  Note that we do not perform a cd on the local shell -- all
        # operations are assumed to be performed on absolute paths.
        lease_tgt  = self._adaptor.get_lease_target ("fork://localhost")
        self.local = self.lm.lease (lease_tgt, self.shell_creator, lease_tgt) 

        return self.get_api ()
Example #24
0
    def init_instance(self, adaptor_state, url, flags, session):

        # FIXME: eval flags!
        if flags == None:
            flags = 0

        self._logger.info("init_instance %s" % url)

        if 'from_open' in adaptor_state and adaptor_state['from_open']:

            # comes from job.service.create_job()
            self.url = saga.Url(url)  # deep copy
            self.flags = flags
            self.session = session
            self.valid = False  # will be set by initialize
            self.lm = session._lease_manager

            self.cwdurl = saga.Url(adaptor_state["cwd"])
            self.cwd = self.cwdurl.path

            if sumisc.url_is_relative(self.url):
                self.url = sumisc.url_make_absolute(self.cwd, self.url)

        else:

            if sumisc.url_is_relative(url):
                raise saga.BadParameter(
                    "cannot interprete relative URL in this context ('%s')" %
                    url)

            self.url = url
            self.flags = flags
            self.session = session
            self.valid = False  # will be set by initialize
            self.lm = session._lease_manager

            self.cwd = sumisc.url_get_dirname(url)
            self.cwdurl = saga.Url(url)  # deep copy
            self.cwdurl.path = self.cwd

            if not self.flags:
                self.flags = 0

        def _shell_creator(url):
            return sups.PTYShell(url, self.session, self._logger)

        self.shell_creator = _shell_creator

        # self.shell is also a leased shell -- for File, it does not have any
        # state, really.
        # FIXME: get ssh Master connection from _adaptor dict
        lease_tgt = self._adaptor.get_lease_target(self.url)
        self.shell = self.lm.lease(lease_tgt, self.shell_creator, self.url)
        # TODO : release shell

        # self.shell.obj.set_initialize_hook (self.initialize)
        # self.shell.obj.set_finalize_hook   (self.finalize)

        self.initialize()

        # we lease a local shell handle, too, if only to support copy and move
        # to and from local file systems (mkdir for staging target, remove of move
        # source).  Note that we do not perform a cd on the local shell -- all
        # operations are assumed to be performed on absolute paths.
        lease_tgt = self._adaptor.get_lease_target("fork://localhost")
        self.local = self.lm.lease(lease_tgt, self.shell_creator, lease_tgt)

        return self.get_api()