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)
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()
def init_instance (self, adaptor_state, url, flags, session) : """ Directory instance constructor """ self.url = saga.Url (url) # deep copy self.flags = flags self.session = session self.valid = False # will be set by initialize # cwd is where this directory is in, so the path w/o the last element path = self.url.path.rstrip ('/') self.cwd = sumisc.url_get_dirname (path) self.cwdurl = saga.Url (url) # deep copy self.cwdurl.path = self.cwd 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 ()
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))
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)
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))
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 ()
def init_instance (self, adaptor_state, url, flags, session) : """ Directory instance constructor """ if flags == None : flags = 0 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 # cwd is where this directory is in, so the path w/o the last element path = self.url.path.rstrip ('/') self.cwd = sumisc.url_get_dirname (path) 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 not leased, as we use it for almost every operation. # Even more important, that shell has state (it has a pwd). If # performance or scalability becomes a problem, we can also lease-manage # it, but then need to keep state separate. 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 is not leased -- local shells are always fast and eat # little resourcess self.local = sups.PTYShell ('fork://localhost/', saga.Session(default=True), self._logger) return self.get_api ()
def initialize(self): # shell got started, found its prompt. Now, change # to the initial (or later current) working directory. cmd = "" dirname = sumisc.url_get_dirname(self.url) if self.flags & saga.filesystem.CREATE_PARENTS: cmd = " mkdir -p '%s'; touch '%s'" % (dirname, self.url.path) self._logger.info("mkdir '%s'; touch '%s'" % (dirname, self.url.path)) elif self.flags & saga.filesystem.CREATE: cmd = " touch '%s'" % (self.url.path) self._logger.info("touch %s" % self.url.path) else: cmd = " true" if self.flags & saga.filesystem.READ: cmd += "; test -r '%s'" % (self.url.path) if self.flags & saga.filesystem.WRITE: cmd += "; test -w '%s'" % (self.url.path) ret, out, _ = self._run_sync(cmd) if ret != 0: if self.flags & saga.filesystem.CREATE_PARENTS: raise saga.BadParameter("cannot open/create: '%s' - %s" % (self.url.path, out)) elif self.flags & saga.filesystem.CREATE: raise saga.BadParameter("cannot open/create: '%s' - %s" % (self.url.path, out)) else: raise saga.DoesNotExist("File does not exist: '%s' - %s" % (self.url.path, out)) self._logger.info("file initialized (%s)(%s)" % (ret, out)) self.valid = True
def init_instance (self, adaptor_state, url, flags, session): """ File instance constructor """ # FIXME: eval flags! if flags == None : flags = 0 self.orig = saga.Url (url) # deep copy self.url = saga.Url (url) # deep copy self.path = url.path # keep path separate self.cwd = sumisc.url_get_dirname (self.url) self.url.path = None self.flags = flags self.session = session self.valid = False # will be set by initialize self.initialize () return self.get_api ()
def init_instance(self, adaptor_state, url, flags, session): """ File instance constructor """ # TODO: eval flags! if flags == None: flags = 0 self.orig = saga.Url(url) # deep copy self.url = saga.Url(url) # deep copy self.path = url.path # keep path separate self.cwd = sumisc.url_get_dirname(self.url) self.url.path = None self.flags = flags self.session = session self.valid = False # will be set by initialize self.initialize() return self.get_api()
def init_instance(self, adaptor_state, url, flags, session): """ Directory instance constructor """ if flags == None: flags = 0 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 # cwd is where this directory is in, so the path w/o the last element path = self.url.path.rstrip('/') self.cwd = sumisc.url_get_dirname(path) 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 # The dir command shell is leased, as the dir seems to be used # extensively in some cases. Note that before each command, we need to # perform a 'cd' to the target location, to make sure we operate in the # right location (see self._command()) 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 is not leased -- local shells are always fast and eat # little resourcess self.local = sups.PTYShell('fork://localhost/', saga.Session(default=True), self._logger) return self.get_api()
def init_instance (self, adaptor_state, url, flags, session) : """ Directory instance constructor """ if flags == None : flags = 0 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 # cwd is where this directory is in, so the path w/o the last element path = self.url.path.rstrip ('/') self.cwd = sumisc.url_get_dirname (path) 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 # The dir command shell is leased, as the dir seems to be used # extensively in some cases. Note that before each command, we need to # perform a 'cd' to the target location, to make sure we operate in the # right location (see self._command()) 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 is not leased -- local shells are always fast and eat # little resourcess self.local = sups.PTYShell ('fork://localhost/', saga.Session(default=True), self._logger) return self.get_api ()
def initialize (self) : # shell got started, found its prompt. Now, change # to the initial (or later current) working directory. cmd = "" dirname = sumisc.url_get_dirname (self.url) if self.flags & saga.filesystem.CREATE_PARENTS : cmd = " mkdir -p '%s'; touch '%s'" % (dirname, self.url.path) self._logger.info ("mkdir '%s'; touch '%s'" % (dirname, self.url.path)) elif self.flags & saga.filesystem.CREATE : cmd = " touch '%s'" % (self.url.path) self._logger.info ("touch %s" % self.url.path) else : cmd = " true" if self.flags & saga.filesystem.READ : cmd += "; test -r '%s'" % (self.url.path) if self.flags & saga.filesystem.WRITE : cmd += "; test -w '%s'" % (self.url.path) ret, out, _ = self._run_sync(cmd) if ret != 0 : if self.flags & saga.filesystem.CREATE_PARENTS : raise saga.BadParameter ("cannot open/create: '%s' - %s" % (self.url.path, out)) elif self.flags & saga.filesystem.CREATE : raise saga.BadParameter ("cannot open/create: '%s' - %s" % (self.url.path, out)) else : raise saga.DoesNotExist("File does not exist: '%s' - %s" % (self.url.path, out)) self._logger.info ("file initialized (%s)(%s)" % (ret, out)) self.valid = True
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)
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 ()
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()
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 ()
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()