Merge remote-tracking branch 'jay0lee/master'

This commit is contained in:
Ross Scroggs
2015-12-23 06:42:45 -08:00
2 changed files with 27 additions and 19 deletions

View File

@@ -809,7 +809,7 @@ def buildGAPIObject(api):
if api in [u'directory', u'reports', u'datatransfer']: if api in [u'directory', u'reports', u'datatransfer']:
api = u'admin' api = u'admin'
try: try:
service = googleapiclient.discovery.build(api, version, http=http) service = googleapiclient.discovery.build(api, version, http=http, cache_discovery=False)
except googleapiclient.errors.UnknownApiNameOrVersion: except googleapiclient.errors.UnknownApiNameOrVersion:
service = getServiceFromDiscoveryDocument(api, version, http) service = getServiceFromDiscoveryDocument(api, version, http)
except httplib2.ServerNotFoundError as e: except httplib2.ServerNotFoundError as e:
@@ -870,7 +870,7 @@ def buildGAPIServiceObject(api, act_as, soft_errors=False):
cache=GC_Values[GC_CACHE_DIR])) cache=GC_Values[GC_CACHE_DIR]))
version = getAPIVer(api) version = getAPIVer(api)
try: try:
return googleapiclient.discovery.build(api, version, http=http) return googleapiclient.discovery.build(api, version, http=http, cache_discovery=False)
except googleapiclient.errors.UnknownApiNameOrVersion: except googleapiclient.errors.UnknownApiNameOrVersion:
return getServiceFromDiscoveryDocument(api, version, http) return getServiceFromDiscoveryDocument(api, version, http)
except httplib2.ServerNotFoundError as e: except httplib2.ServerNotFoundError as e:
@@ -1608,6 +1608,7 @@ def doPrintAdmins():
cd = buildGAPIObject(u'directory') cd = buildGAPIObject(u'directory')
roleId = None roleId = None
userKey = None userKey = None
todrive = False
i = 3 i = 3
while i < len(sys.argv): while i < len(sys.argv):
if sys.argv[i].lower() == u'user': if sys.argv[i].lower() == u'user':
@@ -1623,6 +1624,9 @@ def doPrintAdmins():
print u'ERROR: %s is not a valid role' % role print u'ERROR: %s is not a valid role' % role
sys.exit(5) sys.exit(5)
i += 2 i += 2
elif sys.argv[i].lower() == u'todrive':
todrive = True
i += 1
else: else:
print u'ERROR: %s is not a valid argument for "gam print admins".' % sys.argv[i] print u'ERROR: %s is not a valid argument for "gam print admins".' % sys.argv[i]
sys.exit(2) sys.exit(2)
@@ -1653,7 +1657,7 @@ def doPrintAdmins():
admins_attrib[0][u'orgUnit'] = u'orgUnit' admins_attrib[0][u'orgUnit'] = u'orgUnit'
admin_attrib[u'orgUnit'] = orgUnit admin_attrib[u'orgUnit'] = orgUnit
admins_attrib.append(admin_attrib) admins_attrib.append(admin_attrib)
output_csv(admins_attrib, admins_attrib[0], u'Admins', False) output_csv(admins_attrib, admins_attrib[0], u'Admins', todrive)
def buildOrgUnitIdToNameMap(): def buildOrgUnitIdToNameMap():
cd = buildGAPIObject(u'directory') cd = buildGAPIObject(u'directory')
@@ -1704,7 +1708,7 @@ def buildUserIdToNameMap():
def user_from_userid(userid): def user_from_userid(userid):
if not GM_Globals[GM_MAP_USER_ID_TO_NAME]: if not GM_Globals[GM_MAP_USER_ID_TO_NAME]:
buildUserIdToNameMap() buildUserIdToNameMap()
return GM_Globals[GM_MAP_USER_ID_TO_NAME][userid] return GM_Globals[GM_MAP_USER_ID_TO_NAME].get(userid, '')
SERVICE_NAME_TO_ID_MAP = { SERVICE_NAME_TO_ID_MAP = {
u'Drive': u'55656082996', u'Drive': u'55656082996',
@@ -4530,7 +4534,8 @@ def showLabels(users):
sys.exit(2) sys.exit(2)
for user in users: for user in users:
gmail = buildGAPIServiceObject(u'gmail', user) gmail = buildGAPIServiceObject(u'gmail', user)
labels = callGAPI(service=gmail.users().labels(), function=u'list', userId=user) labels = callGAPI(service=gmail.users().labels(), function=u'list', userId=user, soft_errors=True)
if labels:
for label in labels[u'labels']: for label in labels[u'labels']:
if label[u'type'] == u'system' and not show_system: if label[u'type'] == u'system' and not show_system:
continue continue
@@ -4558,6 +4563,7 @@ def showGmailProfile(users):
if not gmail: if not gmail:
continue continue
results = callGAPI(service=gmail.users(), function=u'getProfile', userId=u'me', soft_errors=True) results = callGAPI(service=gmail.users(), function=u'getProfile', userId=u'me', soft_errors=True)
if results:
for item in results: for item in results:
if item not in profiles[0]: if item not in profiles[0]:
profiles[0][item] = item profiles[0][item] = item
@@ -8995,6 +9001,8 @@ try:
items = list() items = list()
for line in f: for line in f:
argv = shlex.split(line) argv = shlex.split(line)
if not argv:
continue
if (argv[0] in [u'#', u' ', u''] or len(argv) < 2) and argv != [u'commit-batch']: if (argv[0] in [u'#', u' ', u''] or len(argv) < 2) and argv != [u'commit-batch']:
continue continue
elif argv[0] not in [u'gam', u'commit-batch']: elif argv[0] not in [u'gam', u'commit-batch']:

View File

@@ -255,8 +255,8 @@ def safename(filename):
filename = re_slash.sub(",", filename) filename = re_slash.sub(",", filename)
# limit length of filename # limit length of filename
if len(filename)>200: if len(filename)>64:
filename=filename[:200] filename=filename[:64]
return ",".join((filename, filemd5)) return ",".join((filename, filemd5))
NORMALIZE_SPACE = re.compile(r'(?:\r\n)?[ \t]+') NORMALIZE_SPACE = re.compile(r'(?:\r\n)?[ \t]+')