本文整理汇总了Python中cloudmesh_client.common.Shell.Shell.rsync方法的典型用法代码示例。如果您正苦于以下问题:Python Shell.rsync方法的具体用法?Python Shell.rsync怎么用?Python Shell.rsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudmesh_client.common.Shell.Shell
的用法示例。
在下文中一共展示了Shell.rsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sync
# 需要导入模块: from cloudmesh_client.common.Shell import Shell [as 别名]
# 或者: from cloudmesh_client.common.Shell.Shell import rsync [as 别名]
def sync(cls, cloudname, localdir, remotedir, operation=None):
"""
Syncs a local directory with a remote directory.
Either from local to remote OR vice-versa
:param cloudname:
:param localdir:
:param remotedir:
:param operation: get/put
:return:
"""
# Get the operating system
os_type = cls.operating_system()
# fix the local dir path
localdirpath = Config.path_expand(localdir)
# check if local directory exists
if not os.path.exists(localdirpath):
if operation == "put":
Console.error("The local directory [{}] does not exist."
.format(localdirpath))
return None
elif operation == "get":
# for receiving, create local dir
os.mkdir(localdirpath)
Console.msg("Created local directory [{}] for sync."
.format(localdirpath))
"""
rsync now works on windows machines as well.
we install rsync (v5.4.1.20150827) on windows via chocolatey
$ choco install rsync
"""
host = cls.get_host(cloudname)
if host is None:
Console.error("Cloud [{}] not found in cloudmesh.yaml file."
.format(cloudname))
return None
else:
args = None
if operation == "put":
args = [
"-r",
localdir,
host + ":" + remotedir
]
elif operation == "get":
args = [
"-r",
host + ":" + remotedir,
localdir
]
# call rsync
return Shell.rsync(*args)
示例2: sync
# 需要导入模块: from cloudmesh_client.common.Shell import Shell [as 别名]
# 或者: from cloudmesh_client.common.Shell.Shell import rsync [as 别名]
#.........这里部分代码省略.........
os_type = cls.operating_system()
# fix the local dir path
localdir = Config.path_expand(localdir)
# check if local directory exists
if not os.path.exists(localdir):
if operation == "put":
Console.error("The local directory [{}] does not exist."
.format(localdir))
return None
elif operation == "get":
# for receiving, create local dir
os.mkdir(localdir)
Console.msg("Created local directory [{}] for sync."
.format(localdir))
# sync entire local directory
elif os.path.isdir(localdir):
if operation == "put":
localdir += "/*"
elif operation == "get":
localdir += "/"
# for windows use pscp
# rsync has issues with latest win10
if 'windows' in os_type:
ppk_file = ''
while ppk_file == '':
ppk_file = raw_input("Please enter putty private key(ppk) "
"file path: ")
# expand the path
ppk_file = Config.path_expand(ppk_file)
pass
host = cls.get_host(cloudname)
if host is None:
Console.error("Cloud [{}] not found in cloudmesh.yaml file."
.format(cloudname))
return None
else:
# Get the hostname and user of remote host
hostname = cls.get_hostname(host)
user = cls.get_hostuser(host)
# Console.msg("Syncing local dir [{}] with remote host [{}]"
# .format(localdir, user + "@" + hostname))
args = None
if operation == "put":
# Construct the arguments
# local dir comes first (send)
args = [
"-i",
ppk_file,
localdir,
user + "@" + hostname + ":" + remotedir
]
elif operation == "get":
# Construct the arguments
# remote dir comes first (receive)
args = [
"-i",
ppk_file,
user + "@" + hostname + ":" + remotedir,
localdir
]
try:
# Convert command to string
cmd = " ".join(["pscp"] + args)
result = os.system(cmd)
if result != 0:
Console.error("Something went wrong. Please try again later.")
return None
else:
return "Success."
except Exception as ex:
print(ex, ex.message)
# for linux/mac machines use rsync
else:
host = cls.get_host(cloudname)
if host is None:
Console.error("Cloud [{}] not found in cloudmesh.yaml file."
.format(cloudname))
return None
else:
args = None
if operation == "put":
args = [
localdir,
host + ":" + remotedir
]
elif operation == "get":
args = [
host + ":" + remotedir,
localdir
]
# call rsync
return Shell.rsync(*args)