* Use string version rather than float; add check to gam version

This lets you have 3.72.0 or 3.72a; current scheme continues to work as
well.

Handle bad data in lastupdatecheck.txt

$ gam version check
GAM 3.72 - http://git.io/gam
Jay Lee <jay0lee@gmail.com>
Python 2.7.12 64-bit final
google-api-python-client 1.5.2
Darwin-15.6.0-x86_64-i386-64bit x86_64
Path: /Users/admin/Documents/GoogleApps/GAM
Version: Check, Current: 3.72, Latest: 3.71
$

Note that latest version at appspot is behind

* Don't allow check argument from showUsage
This commit is contained in:
Ross Scroggs 2016-10-22 08:52:00 -07:00 committed by Jay Lee
parent 34e55a492e
commit ed48e5ecd9

View File

@ -416,7 +416,7 @@ def indentMultiLineText(message, n=0):
return message.replace(u'\n', u'\n{0}'.format(u' '*n)).rstrip() return message.replace(u'\n', u'\n{0}'.format(u' '*n)).rstrip()
def showUsage(): def showUsage():
doGAMVersion() doGAMVersion(checkForCheck=False)
print u''' print u'''
Usage: gam [OPTIONS]... Usage: gam [OPTIONS]...
@ -752,25 +752,18 @@ def SetGlobalVariables():
def doGAMCheckForUpdates(forceCheck=False): def doGAMCheckForUpdates(forceCheck=False):
import urllib2, calendar import urllib2, calendar
try: current_version = __version__
current_version = float(__version__)
except ValueError:
return
now_time = calendar.timegm(time.gmtime()) now_time = calendar.timegm(time.gmtime())
if not forceCheck: if not forceCheck:
last_check_time = readFile(GM_Globals[GM_LAST_UPDATE_CHECK_TXT], continueOnError=True, displayError=forceCheck) last_check_time_str = readFile(GM_Globals[GM_LAST_UPDATE_CHECK_TXT], continueOnError=True, displayError=forceCheck)
if last_check_time == None: last_check_time = int(last_check_time_str) if last_check_time_str and last_check_time_str.isdigit() else 0
last_check_time = 0
if last_check_time > now_time-604800: if last_check_time > now_time-604800:
return return
try: try:
c = urllib2.urlopen(GAM_APPSPOT_LATEST_VERSION) c = urllib2.urlopen(GAM_APPSPOT_LATEST_VERSION)
try: latest_version = c.read().strip()
latest_version = float(c.read())
except ValueError:
return
if forceCheck or (latest_version > current_version): if forceCheck or (latest_version > current_version):
print u'Version: Check, Current: {0:.2f}, Latest: {1:.2f}'.format(current_version, latest_version) print u'Version: Check, Current: {0}, Latest: {1}'.format(current_version, latest_version)
if latest_version <= current_version: if latest_version <= current_version:
writeFile(GM_Globals[GM_LAST_UPDATE_CHECK_TXT], str(now_time), continueOnError=True, displayError=forceCheck) writeFile(GM_Globals[GM_LAST_UPDATE_CHECK_TXT], str(now_time), continueOnError=True, displayError=forceCheck)
return return
@ -790,7 +783,7 @@ def doGAMCheckForUpdates(forceCheck=False):
except (urllib2.HTTPError, urllib2.URLError): except (urllib2.HTTPError, urllib2.URLError):
return return
def doGAMVersion(): def doGAMVersion(checkForCheck=True):
import struct import struct
print u'GAM {0} - {1}\n{2}\nPython {3}.{4}.{5} {6}-bit {7}\ngoogle-api-python-client {8}\n{9} {10}\nPath: {11}'.format(__version__, GAM_URL, print u'GAM {0} - {1}\n{2}\nPython {3}.{4}.{5} {6}-bit {7}\ngoogle-api-python-client {8}\n{9} {10}\nPath: {11}'.format(__version__, GAM_URL,
__author__, __author__,
@ -799,6 +792,16 @@ def doGAMVersion():
googleapiclient.__version__, googleapiclient.__version__,
platform.platform(), platform.machine(), platform.platform(), platform.machine(),
GM_Globals[GM_GAM_PATH]) GM_Globals[GM_GAM_PATH])
if checkForCheck:
i = 2
while i < len(sys.argv):
myarg = sys.argv[i].lower().replace(u'_', u'')
if myarg == u'check':
doGAMCheckForUpdates(forceCheck=True)
i += 1
else:
print u'ERROR: %s is not a valid argument for "gam version"' % sys.argv[i]
sys.exit(2)
def handleOAuthTokenError(e, soft_errors): def handleOAuthTokenError(e, soft_errors):
if e.message in OAUTH2_TOKEN_ERRORS: if e.message in OAUTH2_TOKEN_ERRORS: