Created
December 18, 2016 02:55
-
-
Save Hanaasagi/76f24a5a49575e3ecb95803be2210953 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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