mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-03 20:31:35 +00:00
Make sync license consistent with other license commands (#1252)
This commit is contained in:
@@ -1368,6 +1368,7 @@ gam <UserTypeEntity> delete|del group|groups
|
|||||||
gam <UserTypeEntity> create|add license <SKUID> [product|productid <ProductID>]
|
gam <UserTypeEntity> create|add license <SKUID> [product|productid <ProductID>]
|
||||||
gam <UserTypeEntity> update license <SKUID> [product|productid <ProductID>] [from] <SKUID>
|
gam <UserTypeEntity> update license <SKUID> [product|productid <ProductID>] [from] <SKUID>
|
||||||
gam <UserTypeEntity> delete|del license <SKUID> [product|productid <ProductID>]
|
gam <UserTypeEntity> delete|del license <SKUID> [product|productid <ProductID>]
|
||||||
|
gam <UserTypeEntity> sync license <SKUID> [product|productid <ProductID>]
|
||||||
|
|
||||||
gam <UserTypeEntity> update photo <FileNamePattern>
|
gam <UserTypeEntity> update photo <FileNamePattern>
|
||||||
gam <UserTypeEntity> delete|del photo
|
gam <UserTypeEntity> delete|del photo
|
||||||
|
|||||||
@@ -11262,7 +11262,7 @@ def ProcessGAMCommand(args):
|
|||||||
elif argument in ['guardian', 'guardians']:
|
elif argument in ['guardian', 'guardians']:
|
||||||
doPrintShowGuardians(False)
|
doPrintShowGuardians(False)
|
||||||
elif argument in ['license', 'licenses', 'licence', 'licences']:
|
elif argument in ['license', 'licenses', 'licence', 'licences']:
|
||||||
gapi_licensing.show_()
|
gapi_licensing.show()
|
||||||
elif argument in ['project', 'projects']:
|
elif argument in ['project', 'projects']:
|
||||||
doPrintShowProjects(False)
|
doPrintShowProjects(False)
|
||||||
elif argument in ['sakey', 'sakeys']:
|
elif argument in ['sakey', 'sakeys']:
|
||||||
@@ -11352,13 +11352,6 @@ def ProcessGAMCommand(args):
|
|||||||
else:
|
else:
|
||||||
controlflow.invalid_argument_exit(argument, 'gam rotate')
|
controlflow.invalid_argument_exit(argument, 'gam rotate')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
elif command == 'sync':
|
|
||||||
argument = sys.argv[2].lower()
|
|
||||||
if argument in ['sku', 'skus', 'license', 'licenses']:
|
|
||||||
gapi_licensing.sync()
|
|
||||||
else:
|
|
||||||
controlflow.invalid_argument_exit(argument, 'gam sync')
|
|
||||||
sys.exit(0)
|
|
||||||
elif command in ['cancelwipe', 'wipe', 'approve', 'block', 'sync']:
|
elif command in ['cancelwipe', 'wipe', 'approve', 'block', 'sync']:
|
||||||
target = sys.argv[2].lower().replace('_', '')
|
target = sys.argv[2].lower().replace('_', '')
|
||||||
if target in ['device', 'devices']:
|
if target in ['device', 'devices']:
|
||||||
@@ -11599,6 +11592,13 @@ def ProcessGAMCommand(args):
|
|||||||
else:
|
else:
|
||||||
controlflow.invalid_argument_exit(addWhat,
|
controlflow.invalid_argument_exit(addWhat,
|
||||||
f'gam <users> {command}')
|
f'gam <users> {command}')
|
||||||
|
elif command == 'sync':
|
||||||
|
syncWhat = sys.argv[4].lower()
|
||||||
|
if syncWhat in ['license', 'licence']:
|
||||||
|
gapi_licensing.sync(users)
|
||||||
|
else:
|
||||||
|
controlflow.invalid_argument_exit(syncWhat,
|
||||||
|
f'gam <users> {command}')
|
||||||
elif command == 'update':
|
elif command == 'update':
|
||||||
updateWhat = sys.argv[4].lower()
|
updateWhat = sys.argv[4].lower()
|
||||||
if updateWhat == 'calendar':
|
if updateWhat == 'calendar':
|
||||||
|
|||||||
@@ -1,19 +1,12 @@
|
|||||||
import base64
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import googleapiclient
|
|
||||||
|
|
||||||
import gam
|
import gam
|
||||||
from gam.var import *
|
from gam.var import *
|
||||||
|
from gam import controlflow
|
||||||
from gam import display
|
from gam import display
|
||||||
from gam import gapi
|
from gam import gapi
|
||||||
from gam import fileutils
|
|
||||||
from gam.gapi import errors as gapi_errors
|
from gam.gapi import errors as gapi_errors
|
||||||
from gam.gapi.directory import groups as gapi_directory_groups
|
|
||||||
from gam import utils
|
|
||||||
|
|
||||||
|
|
||||||
def build():
|
def build():
|
||||||
@@ -85,16 +78,12 @@ def delete(users, sku=None):
|
|||||||
if len(lbatch._order) > 0:
|
if len(lbatch._order) > 0:
|
||||||
lbatch.execute()
|
lbatch.execute()
|
||||||
|
|
||||||
def sync():
|
def sync(users):
|
||||||
lic = build()
|
sku = sys.argv[5]
|
||||||
sku = sys.argv[3]
|
|
||||||
entity_type = sys.argv[4].lower()
|
|
||||||
entity = sys.argv[5].lower()
|
|
||||||
current_users = gam.getUsersToModify(entity_type, entity)
|
|
||||||
current_licenses = gam.getUsersToModify(entity_type='license',
|
current_licenses = gam.getUsersToModify(entity_type='license',
|
||||||
entity=sku)
|
entity=sku)
|
||||||
users_to_license = [user for user in current_users if user not in current_licenses]
|
users_to_license = [user for user in users if user not in current_licenses]
|
||||||
users_to_unlicense = [user for user in current_licenses if user not in current_users]
|
users_to_unlicense = [user for user in current_licenses if user not in users]
|
||||||
print(f'Need to remove license from {len(users_to_unlicense)} and add to ' \
|
print(f'Need to remove license from {len(users_to_unlicense)} and add to ' \
|
||||||
f'{len(users_to_license)} users...')
|
f'{len(users_to_license)} users...')
|
||||||
# do the remove first to free up seats
|
# do the remove first to free up seats
|
||||||
@@ -296,7 +285,7 @@ def print_(returnFields=None,
|
|||||||
|
|
||||||
|
|
||||||
def show():
|
def show():
|
||||||
licenseCounts = doPrintLicenses(countsOnly=True, returnCounts=True)
|
licenseCounts = print_(countsOnly=True, returnCounts=True)
|
||||||
for u_license in licenseCounts:
|
for u_license in licenseCounts:
|
||||||
line = ''
|
line = ''
|
||||||
for i in range(0, len(u_license), 2):
|
for i in range(0, len(u_license), 2):
|
||||||
@@ -313,6 +302,3 @@ def _formatSKUIdDisplayName(skuId):
|
|||||||
if skuId == skuIdDisplay:
|
if skuId == skuIdDisplay:
|
||||||
return skuId
|
return skuId
|
||||||
return f'{skuId} ({skuIdDisplay})'
|
return f'{skuId} ({skuIdDisplay})'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user