womesiete

testCode

Sep 24th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. import os, inspect, urllib2
  2.  
  3. runningVersion = "1.00.0v"
  4. versionUrl = "http://pastebin.com/raw.php?i=3JqJtUiX"
  5. codeUrl = "http://pastebin.com/download.php?i=GWqAQ0Xj"
  6. scriptFilePath = (os.path.abspath(inspect.getfile(inspect.currentframe()))).replace("\\", "/")
  7.  
  8. def checkUpdate(silent=1):
  9. # silently attempt to update the script file by default, post messages if silent==0
  10. # never update if "No_Update.txt" exists in the same folder
  11. if os.path.exists(os.path.dirname(scriptFilePath)+"/No_Update.txt"):
  12. return
  13. try:
  14. versionData = urllib2.urlopen(versionUrl)
  15. except urllib2.URLError:
  16. if silent==0:
  17. print "Connection failed"
  18. return
  19. currentVersion = versionData.read()
  20. if runningVersion!=currentVersion:
  21. if silent==0:
  22. print "There has been an update.\nWould you like to download it?"
  23. try:
  24. codeData = urllib2.urlopen(codeUrl)
  25. except urllib2.URLError:
  26. if silent==0:
  27. print "Connection failed"
  28. return
  29. currentCode = codeData.read()
  30. #with open(scriptFilePath.replace(".py","_UPDATED.py"), mode="w") as scriptFile:
  31. # scriptFile.write(currentCode)
  32. for line in currentCode.splitlines(True) :
  33. print line
  34. if silent==0:
  35. print "Your program has been updated.\nChanges will take effect after you restart"
  36. elif silent==0:
  37. print "Your program is up to date"
  38.  
  39. checkUpdate()
Advertisement
Add Comment
Please, Sign In to add comment