From f1e599d535a465518d5bb2bde023b37b7e403f78 Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Thu, 18 Jul 2024 13:19:41 -0700 Subject: [PATCH] Added option `showitemcountonly` to `gam print domains` --- docs/Domains.md | 10 +++++++++- docs/GamUpdates.md | 5 +++++ docs/How-to-Update-Advanced-Gam.md | 2 +- docs/How-to-Upgrade-from-Standard-GAM.md | 4 ++-- docs/Version-and-Help.md | 12 ++++++------ src/GamCommands.txt | 8 ++++++-- src/GamUpdate.txt | 5 +++++ src/gam/__init__.py | 21 ++++++++++++++++++--- 8 files changed, 52 insertions(+), 15 deletions(-) diff --git a/docs/Domains.md b/docs/Domains.md index 446a60d5..b4f7b159 100644 --- a/docs/Domains.md +++ b/docs/Domains.md @@ -38,7 +38,9 @@ For `info`, if `` is omitted, information about the primary domain w By default, Gam displays the information as an indented list of keys and values. * `formatjson` - Display the fields in JSON format. ``` -gam print domains [todrive *] [formatjson [quotechar ]] +gam print domains + [todrive *] [formatjson [quotechar ]] + [showitemcountonly] ``` By default, Gam displays the information as columns of fields. * `formatjson` - Display the fields in JSON format. @@ -49,6 +51,12 @@ When using the `formatjson` option, double quotes are used extensively in the da The `quotechar ` option allows you to choose an alternate quote character, single quote for instance, that makes for readable/processable output. `quotechar` defaults to `gam.cfg/csv_output_quote_char`. When uploading CSV files to Google, double quote `"` should be used. +## Display domain counts +Display the number of domains. +``` +gam print domains + showitemcountonly +``` ## Create and delete domain aliases ``` gam create domainalias|aliasdomain diff --git a/docs/GamUpdates.md b/docs/GamUpdates.md index a969bf81..8966502a 100644 --- a/docs/GamUpdates.md +++ b/docs/GamUpdates.md @@ -10,6 +10,11 @@ Add the `-s` option to the end of the above commands to suppress creating the `g See [Downloads](https://github.com/taers232c/GAMADV-XTD3/wiki/Downloads) for Windows or other options, including manual installation +### 6.77.17 + +Added option `showitemcountonly` to `gam print domains` that causes GAM to display the +number of domains on stdout; no CSV file is written. + ### 6.77.16 Fixed bug in `gam print filelist` that caused a trap. diff --git a/docs/How-to-Update-Advanced-Gam.md b/docs/How-to-Update-Advanced-Gam.md index f14343ad..b728cc7c 100644 --- a/docs/How-to-Update-Advanced-Gam.md +++ b/docs/How-to-Update-Advanced-Gam.md @@ -1,7 +1,7 @@ # Updating GAMADV-XTD3 Use these steps to update your version of GAMADV-XTD3. -- [Downloads](Downloads) +- [Downloads-Installs](Downloads-Installs) - [Linux and MacOS and Google Cloud Shell](#linux-and-mac-os-and-google-cloud-shell) - [Windows](#windows) - [GAM Configuration](gam.cfg) diff --git a/docs/How-to-Upgrade-from-Standard-GAM.md b/docs/How-to-Upgrade-from-Standard-GAM.md index 77af68b3..13def11e 100644 --- a/docs/How-to-Upgrade-from-Standard-GAM.md +++ b/docs/How-to-Upgrade-from-Standard-GAM.md @@ -346,7 +346,7 @@ writes the credentials into the file oauth2.txt. admin@server:/Users/admin$ rm -f /Users/admin/GAMConfig/oauth2.txt admin@server:/Users/admin$ gam version WARNING: Config File: /Users/admin/GAMConfig/gam.cfg, Section: DEFAULT, Item: oauth2_txt, Value: /Users/admin/GAMConfig/oauth2.txt, Not Found -GAMADV-XTD3 6.77.16 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource +GAMADV-XTD3 6.77.17 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource Ross Scroggs Python 3.12.4 64-bit final MacOS Sonoma 14.5 x86_64 @@ -1018,7 +1018,7 @@ writes the credentials into the file oauth2.txt. C:\>del C:\GAMConfig\oauth2.txt C:\>gam version WARNING: Config File: C:\GAMConfig\gam.cfg, Section: DEFAULT, Item: oauth2_txt, Value: C:\GAMConfig\oauth2.txt, Not Found -GAMADV-XTD3 6.77.16 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource +GAMADV-XTD3 6.77.17 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource Ross Scroggs Python 3.12.4 64-bit final Windows-10-10.0.17134 AMD64 diff --git a/docs/Version-and-Help.md b/docs/Version-and-Help.md index a65592f8..c14eefa0 100644 --- a/docs/Version-and-Help.md +++ b/docs/Version-and-Help.md @@ -3,7 +3,7 @@ Print the current version of Gam with details ``` gam version -GAMADV-XTD3 6.77.16 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource +GAMADV-XTD3 6.77.17 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource Ross Scroggs Python 3.12.4 64-bit final MacOS Sonoma 14.5 x86_64 @@ -15,7 +15,7 @@ Time: 2023-06-02T21:10:00-07:00 Print the current version of Gam with details and time offset information ``` gam version timeoffset -GAMADV-XTD3 6.77.16 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource +GAMADV-XTD3 6.77.17 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource Ross Scroggs Python 3.12.4 64-bit final MacOS Sonoma 14.5 x86_64 @@ -27,7 +27,7 @@ Your system time differs from www.googleapis.com by less than 1 second Print the current version of Gam with extended details and SSL information ``` gam version extended -GAMADV-XTD3 6.77.16 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource +GAMADV-XTD3 6.77.17 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource Ross Scroggs Python 3.12.4 64-bit final MacOS Sonoma 14.5 x86_64 @@ -64,7 +64,7 @@ MacOS High Sierra 10.13.6 x86_64 Path: /Users/Admin/bin/gamadv-xtd3 Version Check: Current: 5.35.08 - Latest: 6.77.16 + Latest: 6.77.17 echo $? 1 ``` @@ -72,7 +72,7 @@ echo $? Print the current version number without details ``` gam version simple -6.77.16 +6.77.17 ``` In Linux/MacOS you can do: ``` @@ -82,7 +82,7 @@ echo $VER Print the current version of Gam and address of this Wiki ``` gam help -GAM 6.77.16 - https://github.com/taers232c/GAMADV-XTD3 +GAM 6.77.17 - https://github.com/taers232c/GAMADV-XTD3 Ross Scroggs Python 3.12.4 64-bit final MacOS Sonoma 14.5 x86_64 diff --git a/src/GamCommands.txt b/src/GamCommands.txt index 074e6e2b..0f3c84eb 100644 --- a/src/GamCommands.txt +++ b/src/GamCommands.txt @@ -3275,9 +3275,13 @@ gam delete domain gam info domain [] [formatjson] -gam print domains [todrive *] +gam print domains + [todrive *] [formatjson [quotechar ]] -gam show domains [formatjson] + [showitemcountonly] +gam show domains + [formatjson] + [showitemcountonly] gam create|add domainalias|aliasdomain gam delete domainalias|aliasdomain diff --git a/src/GamUpdate.txt b/src/GamUpdate.txt index 1ae9f7e4..7da47481 100644 --- a/src/GamUpdate.txt +++ b/src/GamUpdate.txt @@ -2,6 +2,11 @@ Merged GAM-Team version +6.77.17 + +Added option `showitemcountonly` to `gam print domains` that causes GAM to display the +number of domains on stdout; no CSV file is written. + 6.77.16 Fixed bug in `gam print filelist` that caused a trap. diff --git a/src/gam/__init__.py b/src/gam/__init__.py index f78ee26b..60085a1e 100755 --- a/src/gam/__init__.py +++ b/src/gam/__init__.py @@ -16090,18 +16090,33 @@ def doInfoDomain(): DOMAIN_SORT_TITLES = ['domainName', 'parentDomainName', 'creationTime', 'type', 'verified'] -# gam print domains [todrive *] [formatjson [quotechar ]] -# gam show domains [formatjson] +# gam print domains [todrive *] +# [formatjson [quotechar ]] +# [showitemcountonly] +# gam show domains +# [formatjson] +# [showitemcountonly] def doPrintShowDomains(): cd = buildGAPIObject(API.DIRECTORY) csvPF = CSVPrintFile(['domainName'], DOMAIN_SORT_TITLES) if Act.csvFormat() else None FJQC = FormatJSONQuoteChar(csvPF) - getTodriveFJQCOnly(csvPF, FJQC, True) + showItemCountOnly = False + while Cmd.ArgumentsRemaining(): + myarg = getArgument() + if csvPF and myarg == 'todrive': + csvPF.GetTodriveParameters() + elif myarg == 'showitemcountonly': + showItemCountOnly = True + else: + FJQC.GetFormatJSONQuoteChar(myarg, True) try: domains = callGAPIitems(cd.domains(), 'list', 'domains', throwReasons=[GAPI.BAD_REQUEST, GAPI.NOT_FOUND, GAPI.FORBIDDEN], customer=GC.Values[GC.CUSTOMER_ID]) count = len(domains) + if showItemCountOnly: + writeStdout(f'{count}\n') + return i = 0 for domain in domains: i += 1