taers232c / GAM-Scripts3

Scripts for use with GAM - Python 3.6+
239 stars 52 forks source link

GetSharedWithUserDriveACLs.py - Titles with Null #10

Closed ArchchancellorMustrumRidcully closed 2 years ago

ArchchancellorMustrumRidcully commented 2 years ago

Good afternoon,

I've found an item that while it is not the fault of the script itself, I am curious if it can be handled within the script or if a subsequent "cleansing" step might be required.

Performing the following steps:

  1. gam config auto_batch_min 1 redirect csv ./filelistperms-UserWithNullInTitleOfDoc.csv multiprocess user "UserWithNullInTitleOfDoc@domain.edu" print filelist fields id,title,permissions,owners.emailaddress
  2. GetSharedWithUserDriveACLs.py filelistperms-UserWithNullInTitleOfDoc.csv delete-review-UserWithNullInTitleOfDoc.csv

Results in:

C:\GAM\GoogleSharedWithSomeone>GetSharedWithUserDriveACLs.py filelistperms-UserWithNullInTitleOfDoc.csv delete-review-UserWithNullInTitleOfDoc.csv
Traceback (most recent call last):
  File "C:\GAM\GoogleSharedWithSomeone\GetSharedWithUserDriveACLs.py", line 62, in <module>
    for row in csv.DictReader(inputFile, quotechar=QUOTE_CHAR):
  File "C:\Users\ArchchancellorMustrumRidcully\AppData\Local\Programs\Python\Python39\lib\csv.py", line 111, in __next__
    row = next(self.reader)
_csv.Error: line contains NUL

I was able to look at the input file and see a "TitleofFileNUL" in the title field. For testing, I believe it can be recreated with any input file and inserting a NUL value in the Title (or perhaps anywhere).

Is there anyway to pre-cleanse the file, either within the script by searching for the appearance of a NUL (not merely whether or not the item is entirely null)?

I found this while processing an 8.4Gb csv file, it took a bit to find the needle in the haystack. I was able replicate the NUL in the export from both an OU level export and then by a named user export.

Thank you!

taers232c commented 2 years ago

Add this to the end of the print filelist command: stripcrsfromname It strips CRs, LFs and NULs from the filenames.

Let me know if this solves the problem.

ArchchancellorMustrumRidcully commented 2 years ago

Updated w/command + I also came current with 6.24.x (and I now see the 6.22 update notes for 'stripcrsfromname').

Output is looking good now.

Thank you and I hope your weekend is well!