Commit 8ca8c829 authored by Richard Robert Sawoscinski's avatar Richard Robert Sawoscinski
Browse files

Merge branch 'newbranch' into 'main'

added a new line character to the file opens in sift drive and added an error...

See merge request !6
parents 58e56737 2f738a4d
This diff is collapsed.
......@@ -196,7 +196,7 @@ class Sifter:
def write_logfiles(self):
if len(self.transfer_files) > 0:
target = '{}/transfer_files.csv'.format(self.log_path)
with open(target, 'w+') as csvfile:
with open(target, 'w+', newline='') as csvfile:
fieldnames = ['owner', 'name', 'id', 'link', 'parent', 'created'] # NOQA 501
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
......@@ -206,7 +206,7 @@ class Sifter:
if len(self.private_files) > 0:
target = '{}/private_files.csv'.format(self.log_path)
with open(target, 'w+') as csvfile:
with open(target, 'w+', newline='') as csvfile:
fieldnames = ['owner', 'name', 'id', 'link', 'parent', 'created'] # NOQA 501
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
......@@ -216,7 +216,7 @@ class Sifter:
if len(self.unknown_files) > 0:
target = '{}/unknown_files.csv'.format(self.log_path)
with open(target, 'w+') as csvfile:
with open(target, 'w+', newline='') as csvfile:
fieldnames = ['owner', 'name', 'id', 'link', 'parent', 'created'] # NOQA 501
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
......
......@@ -9,8 +9,11 @@ import yaml
from cak_core import arg_prompt
from subprocess import check_output as cmd
from subprocess import CalledProcessError
from datetime import datetime
devnull = open(os.devnull, 'w+')
file_errors = [{"id": "eraeraeraer", "payload": "adsrasr"}]
class Mover:
......@@ -90,19 +93,24 @@ class Mover:
),
extra={'entity': item['owner']}
)
transfer_error = True
pass
#continue on error
if transfer_error == True:
self.logger.info('{} can not be transferred moving on to next file'.format(item['id']), extra={'entity': item['owner']})
file_errors.append({'id': item['id'],'payload': item})
else:
self.logger.info(
'{} transferred successfully'.format(item['id']),
extra={'entity': item['owner']}
)
if hasattr(self, 'strip_access'):
if self.strip_access:
self.strip_permissions(item)
self.upload_file_errors(item['owner'])
def strip_permissions(self, item):
try:
cmd([
......@@ -117,7 +125,48 @@ class Mover:
except CalledProcessError as e:
self.logger.warning(e.output, extra={'entity': item['owner']})
def upload_file_errors(self, owner):
timestamp = datetime.now()
timestamp = timestamp.strftime("%m-%d-%Y %H:%M")
target = ""
if len(file_errors) > 0:
target = '{}/{}_Drive_Transfer_file_errors {}.csv'.format(os.getcwd(),owner,timestamp)
print ("Creating Target CSV")
with open(target, 'w+') as csvfile:
fieldnames = ['id', 'payload'] # NOQA 501
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for item in file_errors:
writer.writerow(item)
csvfile.close()
print ("Uploading Errors Sheet to Google")
#timestamp = datetime.now()
#timestamp = timestamp.strftime("%m/%d/%Y %H:%M")
#file_error_filename = "/{} file errors {}.csv".format(owner, timestamp)
#open ('test.csv', 'x')
#with open('test.csv', 'w', encoding='utf8', newline='') as output_file:
# fc = csv.DictWriter(output_file, fieldnames=keys,)
# fc.writeheader()
# fc.writerows(file_errors)
a = cmd([
self.config['google']['gam_command'],
'user',
'rsauosci@collab.its.umich.edu',
'add',
'drivefile',
'localfile',
target
])
print (a.decode('utf-8', 'ignore'))
def main():
helptext = '''examples:
......@@ -208,6 +257,6 @@ def main():
mover = Mover(vars(args), config)
mover.transfer_files()
if __name__ == '__main__':
main()
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