コード例 #1
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()
コード例 #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()
コード例 #3
0
ファイル: shell_file.py プロジェクト: hgkim2004/saga-python
    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 ()
コード例 #4
0
ファイル: shell_file.py プロジェクト: agrill/saga-python
    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)
コード例 #5
0
ファイル: shell_file.py プロジェクト: jcohen02/saga-python
    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)
コード例 #6
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)
コード例 #7
0
ファイル: go_file.py プロジェクト: RRCKI/pilot
    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)
コード例 #8
0
ファイル: go_file.py プロジェクト: virthead/COMPASS-ProdSys
    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)
コード例 #9
0
ファイル: shell_file.py プロジェクト: agrill/saga-python
    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)
コード例 #10
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)
コード例 #11
0
ファイル: go_file.py プロジェクト: RRCKI/pilot
    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))
コード例 #12
0
ファイル: go_file.py プロジェクト: virthead/COMPASS-ProdSys
    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))
コード例 #13
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()
コード例 #14
0
ファイル: shell_file.py プロジェクト: agrill/saga-python
    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))
コード例 #15
0
ファイル: shell_file.py プロジェクト: nobias/saga-python
    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()
コード例 #16
0
ファイル: shell_file.py プロジェクト: RRCKI/pilot
    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 ()
コード例 #17
0
ファイル: shell_file.py プロジェクト: jcohen02/saga-python
    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)
コード例 #18
0
ファイル: shell_file.py プロジェクト: jcohen02/saga-python
    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 ()
コード例 #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)