diff --git a/src/GamCommands.txt b/src/GamCommands.txt index 7063a40c..7f78cf86 100644 --- a/src/GamCommands.txt +++ b/src/GamCommands.txt @@ -102,7 +102,7 @@ If an item contains spaces, it should be surrounded by ". banana|basil|blueberry|flamingo|graphite|grape| lavender|peacock|sage|tangerine|tomato ::= - csv|doc|dot|docx|dotx|epub|html|jpeg|jpg|mht|odp|ods|odt| + csv|doc|dot|docx|dotx|epub|html|jpeg|jpg|json|mht|odp|ods|odt| pdf|png|ppt|pot|potx|pptx|rtf|svg|tsv|txt|xls|xlt|xlsx|xltx|zip| ms|microsoft|openoffice| ::= @@ -1276,8 +1276,8 @@ If the pattern {{Section}} appears in , it will be replaced with the n For redirect csv, the optional arguments must appear in the order shown. ::= redirect csv [multiprocess] [append] [noheader] [charset ] - [columndelimiter ] [noescapechar ] [quotechar ] - [sortheaders ] [timestampcolumn ] + [columndelimiter ] [noescapechar []] [quotechar ] + [sortheaders ] [timestampcolumn ] [transpose []] [todrive *] | redirect stdout [multiprocess] [append] | redirect stdout null [multiprocess] | diff --git a/src/GamUpdate.txt b/src/GamUpdate.txt index 88f8d6e9..47385b2e 100644 --- a/src/GamUpdate.txt +++ b/src/GamUpdate.txt @@ -1,7 +1,13 @@ +7.05.16 + +Added option `transpose []` to `redirect csv` that causes +GAM to transpose CSV output rows and columns. This will most useful +when a `countsonly` option is used in a `print` or `report` command. + 7.05.15 Updated `gam get drivefile` and `gam create drivefile` -to allow downloading and uploading of Google App Scripts. +to allow downloading and uploading of Google Apps Scripts. ``` $ gam user user1@domain.com get drivefile 1ZY-YkS3E0OKipALra_XzfIh9cvxoILSbb8TRdHBFCpyB_mXI_J8FmjHv format json User: user1@domain.com, Download 1 Drive File diff --git a/src/gam/__init__.py b/src/gam/__init__.py index 3dcef155..4ea1053c 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.05.15' +__version__ = '7.05.16' __license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)' #pylint: disable=wrong-import-position @@ -4113,8 +4113,8 @@ def SetGlobalVariables(): if checkArgumentPresent(Cmd.MULTIPROCESSEXIT_CMD): _setMultiprocessExit() # redirect csv [multiprocess] [append] [noheader] [charset ] -# [columndelimiter ] [noescapechar ] [quotechar ]] -# [sortheaders ] [timestampcolumn ] +# [columndelimiter ] [noescapechar []] [quotechar ]] +# [sortheaders ] [timestampcolumn ] [transpose []] # [todrive *] # redirect stdout [multiprocess] [append] # redirect stdout null @@ -4139,6 +4139,8 @@ def SetGlobalVariables(): GM.Globals[GM.CSV_OUTPUT_SORT_HEADERS] = GC.Values[GC.CSV_OUTPUT_SORT_HEADERS] = getString(Cmd.OB_STRING_LIST, minLen=0).replace(',', ' ').split() if checkArgumentPresent('timestampcolumn'): GM.Globals[GM.CSV_OUTPUT_TIMESTAMP_COLUMN] = GC.Values[GC.CSV_OUTPUT_TIMESTAMP_COLUMN] = getString(Cmd.OB_STRING, minLen=0) + if checkArgumentPresent('transpose'): + GM.Globals[GM.CSV_OUTPUT_TRANSPOSE] = getBoolean() _setCSVFile(filename, mode, encoding, writeHeader, multi) GM.Globals[GM.CSVFILE][GM.REDIRECT_QUEUE_CSVPF] = CSVPrintFile() if checkArgumentPresent('todrive'): @@ -7794,6 +7796,7 @@ class CSVPrintFile(): def __init__(self, titles=None, sortTitles=None, indexedTitles=None): self.rows = [] self.rowCount = 0 + self.outputTranspose = GM.Globals[GM.CSV_OUTPUT_TRANSPOSE] self.todrive = GM.Globals[GM.CSV_TODRIVE] self.titlesSet = set() self.titlesList = [] @@ -8993,6 +8996,22 @@ class CSVPrintFile(): self.JSONtitlesList = self.orderHeaders(self.JSONtitlesList) titlesList = self.JSONtitlesList normalizeSortHeaders() + if self.outputTranspose: + newRows = [] + pivotKey = titlesList[0] + newTitlesList = [pivotKey] + newTitlesSet = set(newTitlesList) + for title in titlesList[1:]: + newRow = {pivotKey: title} + for row in self.rows: + pivotValue = row[pivotKey] + if pivotValue not in newTitlesSet: + newTitlesSet.add(pivotValue) + newTitlesList.append(pivotValue) + newRow[pivotValue] = row.get(title) + newRows.append(newRow) + titlesList = newTitlesList + self.rows = newRows if (not self.todrive) or self.todrive['localcopy']: if GM.Globals[GM.CSVFILE][GM.REDIRECT_NAME] == '-': if GM.Globals[GM.STDOUT][GM.REDIRECT_MULTI_FD]: diff --git a/src/gam/gamlib/glglobals.py b/src/gam/gamlib/glglobals.py index 5285fd46..51eec1e8 100644 --- a/src/gam/gamlib/glglobals.py +++ b/src/gam/gamlib/glglobals.py @@ -85,6 +85,8 @@ CSV_OUTPUT_ROW_FILTER_MODE = 'corm' CSV_OUTPUT_ROW_LIMIT = 'corl' # Add timestamp column to CSV output file CSV_OUTPUT_TIMESTAMP_COLUMN = 'cotc' +# Transpose output rows/columns +CSV_OUTPUT_TRANSPOSE = 'cotr' # Output sort headers CSV_OUTPUT_SORT_HEADERS = 'cosh' # CSV todrive options @@ -250,6 +252,7 @@ Globals = { CSV_OUTPUT_ROW_LIMIT: 0, CSV_OUTPUT_SORT_HEADERS: [], CSV_OUTPUT_TIMESTAMP_COLUMN: None, + CSV_OUTPUT_TRANSPOSE: False, CSV_TODRIVE: {}, CURRENT_API_SERVICES: {}, CURRENT_CLIENT_API: None,