本文整理汇总了Python中saga.utils.misc.url_is_compatible函数的典型用法代码示例。如果您正苦于以下问题:Python url_is_compatible函数的具体用法?Python url_is_compatible怎么用?Python url_is_compatible使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了url_is_compatible函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: link
def link (self, src_in, tgt_in, flags, _from_task=None):
# link will *only* work if src and tgt are on the same resource (and
# even then may fail)
self._is_valid ()
cwdurl = saga.Url (self.url) # deep copy
src = saga.Url (src_in) # deep copy
tgt = saga.Url (tgt_in) # deep copy
rec_flag = ""
if flags & saga.filesystem.RECURSIVE :
raise saga.BadParameter ("'RECURSIVE' flag not supported for link()")
if flags & saga.filesystem.CREATE_PARENTS :
self._create_parent (cwdurl, tgt)
# if src and tgt point to the same host, we just run a shell link
# on that host
if sumisc.url_is_compatible (cwdurl, src) and \
sumisc.url_is_compatible (cwdurl, tgt) :
# print "shell ln"
ret, out, err = self._command (" ln -s '%s' '%s'\n" % (src.path, tgt.path))
if ret != 0 :
raise saga.NoSuccess ("link (%s -> %s) failed (%s): (out: %s) (err: %s)" \
% (src, tgt, ret, out, err))
# src and tgt are on different hosts, this is not supported
else :
raise saga.BadParameter ("link is only supported on same file system as cwd")
示例2: remove
def remove (self, tgt_in, flags):
self._is_valid ()
# FIXME: eval flags
# FIXME: check if tgt remove happens to affect cwd... :-P
cwdurl = saga.Url (self.url) # deep copy
tgt = saga.Url (tgt_in) # deep copy
rec_flag = ""
if flags & saga.filesystem.RECURSIVE :
rec_flag += "-r "
if sumisc.url_is_compatible (cwdurl, tgt) :
ret, out, err = self._command (" rm -f %s '%s'\n" % (rec_flag, tgt.path))
if ret != 0 :
raise saga.NoSuccess ("remove (%s) failed (%s): (out: %s) (err: %s)" \
% (tgt, ret, out, err))
# we cannot support the URL
else :
raise saga.BadParameter ("remove of %s is not supported" % tgt)
示例3: _create_parent
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))
示例4: change_dir
def change_dir (self, tgt, flags) :
cwdurl = saga.Url (self.url)
tgturl = saga.Url (tgt)
if not sumisc.url_is_compatible (cwdurl, tgturl) :
raise saga.BadParameter ("target dir outside of namespace '%s': %s" \
% (cwdurl, tgturl))
cmd = None
if tgturl.path == '.' or \
tgturl.path == cwdurl.path :
self._logger.debug ("change directory optimized away (%s) == (%s)" % (cwdurl, tgturl))
if flags & saga.filesystem.CREATE_PARENTS :
cmd = " mkdir -p '%s' ; cd '%s'" % (tgturl.path, tgturl.path)
elif flags & saga.filesystem.CREATE :
cmd = " mkdir '%s' ; cd '%s'" % (tgturl.path, tgturl.path)
else :
cmd = " test -d '%s' && cd '%s'" % (tgturl.path, tgturl.path)
ret, out, _ = self._command (cmd)
if ret != 0 :
raise saga.BadParameter ("invalid dir '%s': %s" % (cwdurl, tgturl))
self._logger.debug ("changed directory (%s)(%s)" % (ret, out))
self.valid = True
示例5: remove
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)
示例6: _create_parent
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)
示例7: get_path_spec
def get_path_spec(self, session, url, path=None, cwd_url=None, cwd_path=None):
# we assume that, whenever we request a path spec, we also want to use
# it, and we thus register and activate the endpoint, if needed.
sid = session._id
if not sid in self.shells:
raise saga.IncorrectState("GO shell disconnected")
shell = self.shells[sid]['shell']
url = saga.Url(url)
if not path:
path = url.path
if not cwd_url:
cwd_url = saga.Url(url)
if not cwd_path:
cwd_path = '.'
else:
if not cwd_path:
cwd_path = cwd_url.path
if not url.host:
url.host = cwd_url.host
if not url.schema:
url.schema = cwd_url.schema
if not url.host:
raise saga.BadParameter('need host for GO ops')
if not url.schema:
raise saga.BadParameter('need schema for GO ops')
ep_name, ep_url = self.get_go_endpoint_ids(session, url)
# if both URLs point into the same namespace, and if the given path is
# not absolute, then expand it relative to the cwd_path (if it exists).
# Otherwise it is left to the unmodified path.
ps_path = path
# TODO: should the check be on cwd_url / url or on ep_url?
if sumisc.url_is_compatible(cwd_url, url) and not path.startswith('/'):
if cwd_path and path:
ps_path = os.path.join(cwd_path, path)
elif cwd_path:
ps_path = cwd_path
# the pathspec is the concatenation of ps_host and ps_path
ps = "%s%s" % (ep_name, ps_path)
# check if we know the endpoint in XXX, and create/activate as needed
ep = self.get_go_endpoint(session, shell, ep_url)
return ps
示例8: change_dir
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
示例9: change_dir
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))
示例10: copy
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))
#.........这里部分代码省略.........
示例11: copy_self
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
#.........这里部分代码省略.........