mirror of
https://github.com/GAM-team/GAM.git
synced 2026-06-29 10:21:35 +00:00
gam csv FileName:FieldName changed to gam csvfile FileName:FieldName
Added error checking
This commit is contained in:
31
src/gam.py
31
src/gam.py
@@ -1607,14 +1607,14 @@ def doCreateAdmin():
|
|||||||
def doPrintAdminRoles():
|
def doPrintAdminRoles():
|
||||||
cd = buildGAPIObject(u'directory')
|
cd = buildGAPIObject(u'directory')
|
||||||
roles = callGAPIpages(service=cd.roles(), function=u'list', items=u'items',
|
roles = callGAPIpages(service=cd.roles(), function=u'list', items=u'items',
|
||||||
customer=GC_Values[GC_CUSTOMER_ID])
|
customer=GC_Values[GC_CUSTOMER_ID])
|
||||||
roles_attrib = [{}]
|
roles_attrib = [{}]
|
||||||
for role in roles:
|
for role in roles:
|
||||||
role_attrib = {}
|
role_attrib = {}
|
||||||
for key, value in role.items():
|
for key, value in role.items():
|
||||||
if key in [u'kind', u'etag', u'etags']:
|
if key in [u'kind', u'etag', u'etags']:
|
||||||
continue
|
continue
|
||||||
if not isinstance( value, (str, unicode, bool)):
|
if not isinstance(value, (str, unicode, bool)):
|
||||||
continue
|
continue
|
||||||
if key not in roles_attrib[0]:
|
if key not in roles_attrib[0]:
|
||||||
roles_attrib[0][key] = key
|
roles_attrib[0][key] = key
|
||||||
@@ -6900,14 +6900,14 @@ def doGetBackupCodes(users):
|
|||||||
codes = callGAPI(service=cd.verificationCodes(), function=u'list', throw_reasons=[u'invalidArgument', u'invalid'], userKey=user)
|
codes = callGAPI(service=cd.verificationCodes(), function=u'list', throw_reasons=[u'invalidArgument', u'invalid'], userKey=user)
|
||||||
except googleapiclient.errors.HttpError:
|
except googleapiclient.errors.HttpError:
|
||||||
codes = None
|
codes = None
|
||||||
printBackupCodes(user, codes)
|
printBackupCodes(user, codes)
|
||||||
|
|
||||||
def doGenBackupCodes(users):
|
def doGenBackupCodes(users):
|
||||||
cd = buildGAPIObject(u'directory')
|
cd = buildGAPIObject(u'directory')
|
||||||
for user in users:
|
for user in users:
|
||||||
callGAPI(service=cd.verificationCodes(), function=u'generate', userKey=user)
|
callGAPI(service=cd.verificationCodes(), function=u'generate', userKey=user)
|
||||||
codes = callGAPI(service=cd.verificationCodes(), function=u'list', userKey=user)
|
codes = callGAPI(service=cd.verificationCodes(), function=u'list', userKey=user)
|
||||||
printBackupCodes(user, codes)
|
printBackupCodes(user, codes)
|
||||||
|
|
||||||
def doDelBackupCodes(users):
|
def doDelBackupCodes(users):
|
||||||
cd = buildGAPIObject(u'directory')
|
cd = buildGAPIObject(u'directory')
|
||||||
@@ -8666,17 +8666,22 @@ def getUsersToModify(entity_type=None, entity=None, silent=False, return_uids=Fa
|
|||||||
users = []
|
users = []
|
||||||
filename = entity
|
filename = entity
|
||||||
users = readFile(filename, u'rb').splitlines()
|
users = readFile(filename, u'rb').splitlines()
|
||||||
elif entity_type == u'csv':
|
elif entity_type == u'csvfile':
|
||||||
(filename, column) = entity.split(u':')
|
try:
|
||||||
file_contents = readFile(filename)
|
(filename, column) = entity.split(u':')
|
||||||
f = StringIO.StringIO(file_contents)
|
except ValueError:
|
||||||
|
filename = column = None
|
||||||
|
if (not filename) or (not column):
|
||||||
|
systemErrorExit(2, u'Expected gam csvfile FileName:FieldName')
|
||||||
|
f = openFile(filename)
|
||||||
input_file = csv.DictReader(f)
|
input_file = csv.DictReader(f)
|
||||||
|
if column not in input_file.fieldnames:
|
||||||
|
systemErrorExit(2, MESSAGE_HEADER_NOT_FOUND_IN_CSV_HEADERS.format(column, ','.join(input_file.fieldnames)))
|
||||||
users = []
|
users = []
|
||||||
for row in input_file:
|
for row in input_file:
|
||||||
if column not in row:
|
if column in row:
|
||||||
print u'ERROR: %s does not seem to be a header in CSV file %s' % (column, filename)
|
users.append(row[column])
|
||||||
sys.exit(3)
|
closeFile(f)
|
||||||
users.append(row[column])
|
|
||||||
elif entity_type in [u'courseparticipants', u'teachers', u'students']:
|
elif entity_type in [u'courseparticipants', u'teachers', u'students']:
|
||||||
croom = buildGAPIObject(u'classroom')
|
croom = buildGAPIObject(u'classroom')
|
||||||
users = []
|
users = []
|
||||||
@@ -9376,7 +9381,7 @@ try:
|
|||||||
if command == u'print':
|
if command == u'print':
|
||||||
for user in users:
|
for user in users:
|
||||||
print user
|
print user
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
try:
|
try:
|
||||||
if (GC_Values[GC_AUTO_BATCH_MIN] > 0) and (len(users) > GC_Values[GC_AUTO_BATCH_MIN]):
|
if (GC_Values[GC_AUTO_BATCH_MIN] > 0) and (len(users) > GC_Values[GC_AUTO_BATCH_MIN]):
|
||||||
items = []
|
items = []
|
||||||
|
|||||||
Reference in New Issue
Block a user