标签:程序员 西游记 测试 exception img 编写 apache 本地 总结
1 import os 2 3 def data_backup(folder): 4 print("找到备份目录: %s" %folder) 5 print(‘正在备份......‘) 6 zip_file=‘/tmp/backup20181103.zip‘ 7 print(‘备份成功,备份文件为: %s‘ %zip_file) 8 return zip_file 9 10 def cloud_upload(file): 11 print("\nconnecting cloud storage center...") 12 print("cloud storage connected.") 13 print("upload file...%s...to cloud..." %file) 14 link=‘http://www.xxx.com/bak/%s‘; %os.path.basename(file) 15 print(‘close connection.....‘) 16 return link 17 18 def data_backup_test(link): 19 print("\n下载文件: %s , 验证文件是否无损" %link) 20 21 def main(): 22 #步骤一:本地数据打包 23 zip_file = data_backup("c:\\users\\alex\欧美100G高清无码") 24 25 #步骤二:上传至云服务器 26 link=cloud_upload(zip_file) 27 28 #步骤三:测试备份文件的可用性 29 data_backup_test(link) 30 31 if __name__ == ‘__main__‘: 32 main()
1 import os 2 3 def data_backup(folder): 4 print("找到备份目录: %s" %folder) 5 print(‘正在备份......‘) 6 zip_file=‘/tmp/backup20181103.zip‘ 7 print(‘备份成功,备份文件为: %s‘ %zip_file) 8 return zip_file 9 10 def cloud_upload(file): #加上异常处理,在出现异常的情况下,没有link返回 11 try: 12 print("\nconnecting cloud storage center...") 13 print("cloud storage connected.") 14 print("upload file...%s...to cloud..." % file) 15 link = ‘http://www.xxx.com/bak/%s‘; % os.path.basename(file) 16 return link 17 except Exception: 18 print(‘upload error‘) 19 finally: 20 print(‘close connection.....‘) 21 22 def data_backup_test(link): #加上对参数link的判断 23 if link: 24 print("\n下载文件: %s , 验证文件是否无损" %link) 25 else: 26 print(‘\n链接不存在‘)def main(): 27 28 #步骤一:本地数据打包 29 zip_file = data_backup("c:\\users\\alex\欧美100G高清无码") 30 31 #步骤二:上传至云服务器 32 link=cloud_upload(zip_file) 33 34 #步骤三:测试备份文件的可用性 35 data_backup_test(link) 36 37 if __name__ == ‘__main__‘: 38 main()
标签:程序员 西游记 测试 exception img 编写 apache 本地 总结
原文地址:https://www.cnblogs.com/oceanicstar/p/8846840.html