From 28383c13919dd821731ed8a7c0fd99a7afe1227b Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Sun, 1 Mar 2026 19:52:51 -0800 Subject: [PATCH] Added option `returnidonly` to `gam create|update printer` --- .github/workflows/build.yml | 2 +- src/GamCommands.txt | 4 ++-- src/GamUpdate.txt | 7 +++++++ src/gam/__init__.py | 23 ++++++++++++++++------- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4e66aa1d..e86dedac 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1102,7 +1102,7 @@ jobs: echo "printer model count:" run_gam print printermodels | wc -l run_gam print printers - printerid=$($gam create printer displayname "${newbase}" uri ipp://localhost:631 driverless description "made by ${gam_user}" ou "${newou}" nodetails | awk '{print substr($2, 1, length($2)-1)}') + printerid=$($gam create printer displayname "${newbase}" uri ipp://localhost:631 driverless description "made by ${gam_user}" ou "${newou}" returnIdOnly) run_gam info printer "$printerid" run_gam delete printer "$printerid" run_gam delete ou "${newou}" diff --git a/src/GamCommands.txt b/src/GamCommands.txt index 3cafb138..5c912be5 100644 --- a/src/GamCommands.txt +++ b/src/GamCommands.txt @@ -4568,8 +4568,8 @@ gam check ou|org [todrive *] usedriverlessconfig| ::= "(,)*" -gam create printer + -gam update printer + +gam create printer + [nodetails|returnidonly] +gam update printer + [nodetails|returnidonly] gam delete printer | | diff --git a/src/GamUpdate.txt b/src/GamUpdate.txt index 082eeca4..714f7f02 100644 --- a/src/GamUpdate.txt +++ b/src/GamUpdate.txt @@ -1,3 +1,10 @@ +7.34.12 + +Fixed build errors that prevented Windows zip files from being created. + +Added option `returnidonly` to `gam create|update printer` that causes GAM to return just the ID +of the printer. + 7.34.11 Updated gam-install.sh script for macOS/Linux to properly config GAM when the answer to the following question is No. diff --git a/src/gam/__init__.py b/src/gam/__init__.py index 5910ca1d..d26524c7 100755 --- a/src/gam/__init__.py +++ b/src/gam/__init__.py @@ -25,7 +25,7 @@ https://github.com/GAM-team/GAM/wiki """ __author__ = 'GAM Team ' -__version__ = '7.34.11' +__version__ = '7.34.12' __license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)' # pylint: disable=wrong-import-position @@ -31656,6 +31656,7 @@ UPDATE_PRINTER_JSON_SKIP_FIELDS = ['id', 'name', 'createTime', 'orgUnitId', 'org def _getPrinterAttributes(cd, jsonDeleteFields): '''get printer attributes for create/update commands''' body = {} + returnIdOnly = False showDetails = True while Cmd.ArgumentsRemaining(): myarg = getArgument() @@ -31674,13 +31675,15 @@ def _getPrinterAttributes(cd, jsonDeleteFields): body['useDriverlessConfig'] = getBoolean() elif myarg == 'nodetails': showDetails = False + elif myarg == 'returnidonly': + returnIdOnly = True elif myarg == 'json': body.update(getJSON(jsonDeleteFields)) else: unknownArgumentExit() if body.get('makeAndModel'): body.pop('useDriverlessConfig', None) - return (body, showDetails) + return (body, showDetails, returnIdOnly) PRINTER_FIELDS_CHOICE_MAP = { 'auxiliarymessages': 'auxiliaryMessages', @@ -31726,33 +31729,39 @@ def _showPrinter(cd, printer, FJQC, orgUnitId=None, showInherited=False, i=0, co showJSON(None, printer, timeObjects=PRINTER_TIME_OBJECTS) Ind.Decrement() -# gam create printer + [nodetails] +# gam create printer + [nodetails|returnidonly] def doCreatePrinter(): cd = buildGAPIObject(API.DIRECTORY) parent = _getCustomersCustomerIdWithC() - body, showDetails = _getPrinterAttributes(cd, CREATE_PRINTER_JSON_SKIP_FIELDS) + body, showDetails, returnIdOnly = _getPrinterAttributes(cd, CREATE_PRINTER_JSON_SKIP_FIELDS) if not body.get('orgUnitId'): missingArgumentExit('orgunit') try: printer = callGAPI(cd.customers().chrome().printers(), 'create', throwReasons=[GAPI.INVALID_ARGUMENT, GAPI.PERMISSION_DENIED], parent=parent, body=body) + if returnIdOnly: + writeStdout(f"{printer['id']}\n") + return entityActionPerformed([Ent.PRINTER, printer['id']]) if showDetails: _showPrinter(cd, printer, None) except (GAPI.invalidArgument, GAPI.permissionDenied) as e: entityActionFailedWarning([Ent.PRINTER, None], str(e)) -# gam update printer + [nodetails] +# gam update printer + [nodetails|returnidonly] def doUpdatePrinter(): name, printerId, cd = _getPrinterID() - body, showDetails = _getPrinterAttributes(cd, UPDATE_PRINTER_JSON_SKIP_FIELDS) + body, showDetails, returnIdOnly = _getPrinterAttributes(cd, UPDATE_PRINTER_JSON_SKIP_FIELDS) updateMask = ','.join(list(body.keys())) # note clearMask seems unnecessary. Updating field to '' clears it. try: printer = callGAPI(cd.customers().chrome().printers(), 'patch', throwReasons=[GAPI.NOT_FOUND, GAPI.INVALID_ARGUMENT, GAPI.PERMISSION_DENIED], name=name, updateMask=updateMask, body=body) + if returnIdOnly: + writeStdout(f"{printer['id']}\n") + return entityActionPerformed([Ent.PRINTER, printerId]) if showDetails: _showPrinter(cd, printer, None) @@ -71340,7 +71349,7 @@ def updatePhoto(users): bailOnInternalError=True, throwReasons=[GAPI.USER_NOT_FOUND, GAPI.FORBIDDEN, GAPI.PHOTO_NOT_FOUND, GAPI.INTERNAL_ERROR], userKey=user) - except (GAPI.photoNotFound, GAPI.internalError) as e: + except (GAPI.photoNotFound, GAPI.internalError): pass callGAPI(cd.users().photos(), 'update', throwReasons=[GAPI.USER_NOT_FOUND, GAPI.FORBIDDEN, GAPI.INVALID_INPUT, GAPI.CONDITION_NOT_MET],