From ee35a41d03618e26866cbc024def05610ef1aadd Mon Sep 17 00:00:00 2001 From: Jay Lee Date: Wed, 18 Mar 2015 14:13:44 -0400 Subject: [PATCH] Revert "look for extra-args.txt file to read additional GAPI arguments from." This reverts commit 6b2aa1c532fb4d5777c1443f823c2c9cca41300c. --- gam.py | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/gam.py b/gam.py index 7343721f..926d6156 100755 --- a/gam.py +++ b/gam.py @@ -40,7 +40,7 @@ import oauth2client.file import oauth2client.tools import uritemplate -global true_values, false_values, extra_args, customerId, domain, usergroup_types +global true_values, false_values, prettyPrint, customerId, domain, usergroup_types true_values = [u'on', u'yes', u'enabled', u'true', u'1'] false_values = [u'off', u'no', u'disabled', u'false', u'0'] usergroup_types = [u'user', u'users', u'group', u'ou', u'org', @@ -369,10 +369,9 @@ def callGData(service, function, soft_errors=False, throw_errors=[], **kwargs): def callGAPI(service, function, silent_errors=False, soft_errors=False, throw_reasons=[], retry_reasons=[], **kwargs): method = getattr(service, function) retries = 10 - parameters = dict(kwargs.items() + extra_args.items()) for n in range(1, retries+1): try: - return method(**parameters).execute() + return method(prettyPrint=prettyPrint, **kwargs).execute() except googleapiclient.errors.HttpError, e: try: error = json.loads(e.content) @@ -505,7 +504,7 @@ def getAPIScope(api): u'https://www.googleapis.com/auth/drive'] def buildGAPIObject(api): - global domain, customerId, extra_args + global domain, customerId, prettyPrint oauth2file = getGamPath()+u'oauth2.txt' try: oauth2file = getGamPath()+os.environ[u'OAUTHFILE'] @@ -528,15 +527,9 @@ def buildGAPIObject(api): http = httplib2.Http(ca_certs=getGamPath()+u'cacert.pem', disable_ssl_certificate_validation=disable_ssl_certificate_validation, cache=cache) if os.path.isfile(getGamPath()+u'debug.gam'): httplib2.debuglevel = 4 - extra_args = {u'prettyPrint': True} + prettyPrint = True else: - extra_args = {u'prettyPrint': False} - if os.path.isfile(getGamPath()+u'extra-args.txt'): - import ConfigParser - config = ConfigParser.ConfigParser() - config.optionxform = str - config.read(getGamPath()+u'extra-args.txt') - extra_args.update(dict(config.items(u'extra-args'))) + prettyPrint = False http = credentials.authorize(http) version = getAPIVer(api) if api in [u'directory', u'reports']: @@ -569,7 +562,7 @@ def buildGAPIObject(api): return service def buildGAPIServiceObject(api, act_as=None, soft_errors=False): - global extra_args + global prettyPrint oauth2servicefile = getGamPath()+u'oauth2service' try: oauth2servicefile = getGamPath()+os.environ[u'OAUTHSERVICEFILE'] @@ -613,15 +606,9 @@ def buildGAPIServiceObject(api, act_as=None, soft_errors=False): http = httplib2.Http(ca_certs=getGamPath()+u'cacert.pem', disable_ssl_certificate_validation=disable_ssl_certificate_validation, cache=cache) if os.path.isfile(getGamPath()+u'debug.gam'): httplib2.debuglevel = 4 - extra_args = {u'prettyPrint': True} + prettyPrint = True else: - extra_args = {u'prettyPrint': False} - if os.path.isfile(getGamPath()+u'extra-args.txt'): - import ConfigParser - config = ConfigParser.ConfigParser() - config.optionxform = str - config.read(getGamPath()+u'extra-args.txt') - extra_args.update(dict(config.items(u'extra-args'))) + prettyPrint = False http = credentials.authorize(http) version = getAPIVer(api) try: @@ -1714,7 +1701,11 @@ def delDriveFileACL(users): permissionId = unicode(sys.argv[6]) for user in users: drive = buildGAPIServiceObject(u'drive', user) - if not permissionId.isnumeric() and permissionId.lower() not in [u'anyone',]: + if permissionId[:3].lower() == u'id:': + permissionId = permissionId[3:] + elif permissionId.lower() in [u'anyone']: + pass + else: permissionId = callGAPI(service=drive.permissions(), function=u'getIdForEmail', email=permissionId, fields=u'id')[u'id'] print u'Removing permission for %s from %s' % (permissionId, fileId) callGAPI(service=drive.permissions(), function=u'delete', fileId=fileId, permissionId=permissionId) @@ -1765,7 +1756,7 @@ def updateDriveFileACL(users): fileId = sys.argv[5] permissionId = unicode(sys.argv[6]) transferOwnership = None - body = {u'type': perm_type} + body = {} i = 7 while i < len(sys.argv): if sys.argv[i].lower().replace(u'_', u'') == u'withlink': @@ -1793,7 +1784,9 @@ def updateDriveFileACL(users): sys.exit(9) for user in users: drive = buildGAPIServiceObject(u'drive', user) - if not permissionId.isnumeric(): + if permissionId[:3].lower() == u'id:': + permissionId = permissionId[3:] + else: permissionId = callGAPI(service=drive.permissions(), function=u'getIdForEmail', email=permissionId, fields=u'id')[u'id'] print u'updating permissions for %s to file %s' % (permissionId, fileId) result = callGAPI(service=drive.permissions(), function=u'patch', fileId=fileId, permissionId=permissionId, transferOwnership=transferOwnership, body=body) @@ -4278,7 +4271,7 @@ def doUpdateUser(users): body[u'emails'] = [{u'type': u'custom', u'customType': u'former_employee', u'primary': False, u'address': user_primary}] sys.stderr.write(u'updating user %s...\n' % user) if do_update_user: - result = callGAPI(service=cd.users(), function=u'patch', soft_errors=True, userKey=user, body=body, fields='primaryEmail') + result = callGAPI(service=cd.users(), function=u'patch', soft_errors=True, userKey=user, body=body) if do_admin_user: result2 = callGAPI(service=cd.users(), function=u'makeAdmin', soft_errors=True, userKey=user, body={u'status': is_admin}) @@ -7273,9 +7266,9 @@ access or an 'a' to grant action-only access. http = httplib2.Http(ca_certs=certFile, disable_ssl_certificate_validation=disable_ssl_certificate_validation) if os.path.isfile(getGamPath()+u'debug.gam'): httplib2.debuglevel = 4 - extra_args = {u'prettyPrint': True} + prettyPrint = True else: - extra_args = {u'prettyPrint': False} + prettyPrint = False try: credentials = oauth2client.tools.run_flow(flow=FLOW, storage=storage, flags=flags, http=http) except httplib2.CertificateValidationUnsupported: