Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, inspect, urllib2
- runningVersion = "1.00.0v"
- versionUrl = "http://pastebin.com/raw.php?i=3JqJtUiX"
- codeUrl = "http://pastebin.com/download.php?i=GWqAQ0Xj"
- scriptFilePath = (os.path.abspath(inspect.getfile(inspect.currentframe()))).replace("\\", "/")
- def checkUpdate(silent=1):
- # silently attempt to update the script file by default, post messages if silent==0
- # never update if "No_Update.txt" exists in the same folder
- if os.path.exists(os.path.dirname(scriptFilePath)+"/No_Update.txt"):
- return
- try:
- versionData = urllib2.urlopen(versionUrl)
- except urllib2.URLError:
- if silent==0:
- print "Connection failed"
- return
- currentVersion = versionData.read()
- if runningVersion!=currentVersion:
- if silent==0:
- print "There has been an update.\nWould you like to download it?"
- try:
- codeData = urllib2.urlopen(codeUrl)
- except urllib2.URLError:
- if silent==0:
- print "Connection failed"
- return
- currentCode = codeData.read()
- #with open(scriptFilePath.replace(".py","_UPDATED.py"), mode="w") as scriptFile:
- # scriptFile.write(currentCode)
- for line in currentCode.splitlines(True) :
- print line
- if silent==0:
- print "Your program has been updated.\nChanges will take effect after you restart"
- elif silent==0:
- print "Your program is up to date"
- checkUpdate()
Advertisement
Add Comment
Please, Sign In to add comment