From 58335025c4fa6b5ce8007819ca945f8c0634db2d Mon Sep 17 00:00:00 2001 From: Jay Lee Date: Wed, 30 Sep 2015 09:42:08 -0400 Subject: [PATCH] Make cloudprint. and admin-settings JSON files part of Windows binary --- src/build.bat | 4 ---- src/gam.py | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/build.bat b/src/build.bat index 6a4b4c83..a839d03c 100644 --- a/src/build.bat +++ b/src/build.bat @@ -8,14 +8,10 @@ del /q /f gam-%1-windows-x64.zip c:\python27-32\scripts\pyinstaller -F --distpath=gam gam.spec xcopy LICENSE gam\ xcopy whatsnew.txt gam\ -xcopy admin-settings-v1.json gam\ -xcopy cloudprint-v2.json gam\ del gam\w9xpopen.exe "%ProgramFiles(x86)%\7-Zip\7z.exe" a -tzip gam-%1-windows.zip gam\ -xr!.svn c:\python27\scripts\pyinstaller -F --distpath=gam-64 gam.spec xcopy LICENSE gam-64\ xcopy whatsnew.txt gam-64\ -xcopy admin-settings-v1.json gam-64\ -xcopy cloudprint-v2.json gam-64\ "%ProgramFiles(x86)%\7-Zip\7z.exe" a -tzip gam-%1-windows-x64.zip gam-64\ -xr!.svn diff --git a/src/gam.py b/src/gam.py index d1230a7a..86f827ce 100644 --- a/src/gam.py +++ b/src/gam.py @@ -588,15 +588,23 @@ def buildGAPIObject(api): try: service = googleapiclient.discovery.build(api, version, http=http) except googleapiclient.errors.UnknownApiNameOrVersion: - disc_file = os.path.join(gamSiteConfigDir, u'%s-%s.json' % (api, version)) + disc_filename = u'%s-%s.json' % (api, version) + disc_file = os.path.join(gamSiteConfigDir, disc_filename) + pyinstaller_disc_file = None + try: + pyinstaller_disc_file = os.path.join(sys._MEIPASS, disc_filename) + except NameError: + pass if os.path.isfile(disc_file): f = file(disc_file, 'rb') - discovery = f.read() - f.close() - service = googleapiclient.discovery.build_from_document(discovery, base=u'https://www.googleapis.com', http=http) + elif pyinstaller_disc_file: + f = file(pyinstaller_disc_file, 'rb') else: print 'No online discovery doc and %s does not exist locally' % disc_file raise + discovery = f.read() + f.close() + service = googleapiclient.discovery.build_from_document(discovery, base=u'https://www.googleapis.com', http=http) except httplib2.CertificateValidationUnsupported: print u'Error: You don\'t have the Python ssl module installed so we can\'t verify SSL Certificates. You can fix this by installing the Python SSL module or you can live on the edge and turn SSL validation off by creating a file called noverifyssl.txt in the same location as gam.exe / gam.py' sys.exit(8) @@ -673,6 +681,24 @@ def buildGAPIServiceObject(api, act_as=None, soft_errors=False): if soft_errors: return False sys.exit(4) + except googleapiclient.errors.UnknownApiNameOrVersion: + disc_filename = u'%s-%s.json' % (api, version) + disc_file = os.path.join(gamSiteConfigDir, disc_filename) + pyinstaller_disc_file = None + try: + pyinstaller_disc_file = os.path.join(sys._MEIPASS, disc_filename) + except NameError: + pass + if os.path.isfile(disc_file): + f = file(disc_file, 'rb') + elif pyinstaller_disc_file: + f = file(pyinstaller_disc_file, 'rb') + else: + print 'No online discovery doc and %s does not exist locally' % disc_file + raise + discovery = f.read() + f.close() + return googleapiclient.discovery.build_from_document(discovery, base=u'https://www.googleapis.com', http=http) def buildDiscoveryObject(api): import uritemplate