Guest User

Untitled

a guest
Oct 17th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. from subprocess import call
  4. import os, sys, ftplib, string, traceback, datetime
  5.  
  6. logtime = datetime.datetime.now()
  7. logtimeString = logtime.strftime("%Y-%m-%d_%H:%M:%S")
  8.  
  9. successLogs = "successLogs." + logtimeString + ".txt"
  10. failureLogs = "failureLogs" + logtimeString + ".txt"
  11. successLogFile = open(successLogs, 'a')
  12. failureLogFile = open(failureLogs, 'a')
  13.  
  14. #successLogFile.write("success, error is: " + e + ", continuing\n")
  15. #failureLogFile.write("failed, error is: " + e + "\n")
  16.  
  17. def printFileError(fileError):
  18. print("something went bad with file", fileError, file=failureLogFile)
  19.  
  20. def processVMX(vmxPath):
  21. vmxTmpPath = vmxPath + ".bak"
  22. os.rename(vmxPath, vmxTmpPath)
  23. #print("before open vmx")
  24. vmxFile = open(vmxPath, 'w')
  25. vmxOldFile = open(vmxTmpPath, 'r')
  26. #print("opened..")
  27. for line in vmxOldFile.readlines():
  28. # print("for line")
  29. # if "virtualHW.version = \"8\"" in line:
  30. # print("in if statement")
  31. vmxFile.write(line.replace('virtualHW.version = "8"', 'virtualHW.version = "7"'))
  32. # vmxFile.write(line)
  33. # print("wrote to file")
  34. #o.write(line + "\n")
  35. vmxFile.close()
  36. vmxOldFile.close()
  37. os.remove(vmxTmpPath)
  38.  
  39. def uploadToFTP(path,user,pwd):
  40. #print "before ftplib.."
  41. ftp = ftplib.FTP()
  42. host = "ftp.cloud.skytap.com"
  43. port = 21
  44.  
  45. #print "before connecting.."
  46. ftp.connect(host,port)
  47. #print "connected, before getwelcome"
  48. #print(ftp.getwelcome())
  49. #print "got welcome"
  50. #print("connecting....")
  51.  
  52. try:
  53. try:
  54. ftp.login(user,pwd)
  55. ftp.cwd("/upload")
  56. #print "Currently in:", ftp.pwd() # double check make sure this says /upload
  57. #print "finished logging in..."
  58.  
  59. for root, dirs, files in os.walk(path, onerror=printFileError):
  60. #for root, dirs, files in os.walk(path):
  61. checker = os.system('md5sum -c md5sum.txt') #might need to modify
  62. if(0 == checker):
  63. for f in files:
  64. fullPath = os.path.abspath(root + '/' + f)
  65. #os.system('md5 ' + fullPath + ' > ' + fullPath + '.md5') #might need to modify
  66. if(fullPath.endswith(".vmx")):
  67. processVMX(fullPath)
  68. #print "Uploading:", fullPath
  69. fileToUpload = open(fullPath, "rb")
  70. ftp.storbinary('STOR ' + f, fileToUpload)
  71. fileToUpload.close()
  72. #MD5checker fileToUpload = open(fullPath + '.md5', "rb")
  73. #MD5checker ftp.storbinary('STOR <ftp://ftp.storbinary('STOR> ' + f + '.md5', fileToUpload)
  74. #MD5checker fileToUpload.close()
  75. print("Uploaded file", fullPath, file=successLogFile)
  76. finally:
  77. ftp.quit()
  78. except e:
  79. print("something went wrong:", e, fileName=errorLogFile)
  80.  
  81. #raw_input("Press enter...")
  82.  
  83. configFile = open(sys.argv[1], 'r')
  84.  
  85.  
  86. for line in configFile:
  87. info = string.split(line, ':')
  88. uploadToFTP(info[0], info[1], info[2])
  89.  
  90. configFile.close()
  91. successLogFile.close()
  92. failureLogFile.close()
Add Comment
Please, Sign In to add comment