Skip to content

Instantly share code, notes, and snippets.

@Hanaasagi
Created December 18, 2016 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hanaasagi/76f24a5a49575e3ecb95803be2210953 to your computer and use it in GitHub Desktop.
Save Hanaasagi/76f24a5a49575e3ecb95803be2210953 to your computer and use it in GitHub Desktop.
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