Commit 2df71b69 authored by mail-related applications's avatar mail-related applications
Browse files

added logging and helfpul printouts to drive sifter

parent 77e0bbd4
......@@ -141,7 +141,7 @@ class Sifter:
], stderr=devnull
).decode('utf-8').split('\n')[:-1]
allFiles = csv.DictReader(results, delimiter=',', quotechar='"', dialect=csv.QUOTE_ALL)
allFiles = csv.DictReader(results, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
for item in allFiles:
if item['id'] not in self.transfer_files.keys():
if item['id'] not in self.private_files.keys():
......@@ -175,7 +175,7 @@ class Sifter:
], stderr=devnull
).decode('UTF-8').split('\n')[:-1]
shared = csv.DictReader(results, delimiter=',', quotechar='"')
shared = csv.DictReader(results, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
for item in shared:
if item['owners.0.emailAddress'] != self.account:
self.shared_files[item['id']] = {
......@@ -235,6 +235,10 @@ class Sifter:
csvfile.close()
def upload_logfiles(self):
timestamp = datetime.now()
timestamp = timestamp.strftime("%m-%d-%Y %H:%M")
goflder_info = ""
try:
if self.destination_account:
upload_user = self.destination_account
......@@ -259,9 +263,10 @@ class Sifter:
)
return None
gFolderName = self.account + ' Drive Report'
gFolderName = self.account + ' Drive Report {}'.format(timestamp)
try:
cmd([
gfolder_info = cmd([
self.config['google']['gam_command'],
'user',
upload_user,
......@@ -273,6 +278,12 @@ class Sifter:
'gdirectory'
], stderr=devnull
)
gfolder_info = str(gfolder_info)
gfolder_info = (gfolder_info[gfolder_info.find('(')+1:gfolder_info.find(')')])
gfolder_info = ("https://drive.google.com/drive/folders/{}").format(gfolder_info)
print ("Results for sifter available here: {}".format(gfolder_info))
except CalledProcessError:
self.logger.error(
'Unable to create report directory',
......@@ -281,7 +292,7 @@ class Sifter:
for log_file in available_files:
try:
cmd([
file_id = cmd([
self.config['google']['gam_command'],
'user',
upload_user,
......@@ -294,6 +305,11 @@ class Sifter:
'convert'
], stderr=devnull
)
file_id = str(file_id)
file_id = (file_id[file_id.find('(')+1:file_id.find(')')])
print ("\nGAM command to download {} file:".format(log_file))
print ("gam user {} get drivefile id {}".format(upload_user, file_id))
except CalledProcessError:
self.logger.error(
'Error uploading {}'.format(log_file),
......@@ -306,7 +322,7 @@ class Sifter:
def main():
helptext = '''examples:
google-sift-drive -a alexham -f 'burr_beef' 'duel notes'
google-sift-drive -a alexham -o 'burr_beef' 'duel notes'
google-sift-drive --account alexham --omit_folders 'burr_beef'
'''
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment