Skip to content

Instantly share code, notes, and snippets.

@Hanaasagi
Created December 18, 2016 02:55
Embed
What would you like to do?
import sys
import os
import time
py = sys.version_info
if py < (3, 0, 0):
input = raw_input
_version = 1.0
def check_update():
if _version == 1.0:
return True
return False
def update():
"""
your update code
"""
with open(os.path.abspath(os.path.basename(__file__)), 'r+') as f:
buffer = f.read()
buffer = buffer.replace('_version = 1.0', '_version = 2.0')
f.seek(0, 0)
f.write(buffer)
if __name__ == '__main__':
print('version: ' + str(_version))
print('now it is running')
time.sleep(2)
if check_update():
choice = input(
'Now there is a new version, Do you want to update ?')
if choice in ('y', 'Y'):
update()
os.execvp(sys.executable, [sys.executable] + sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment