fix: [import_dir] remove dir whitespaces #475

pull/486/head
Terrtia 2020-02-25 11:34:55 +01:00
parent 1f8c858c77
commit 72fe8a2461
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
1 changed files with 8 additions and 5 deletions

View File

@ -9,7 +9,7 @@ import gzip
import argparse
import os
import time, datetime
import mimetypes
import magic
'''
'
@ -75,11 +75,10 @@ if __name__ == "__main__":
messagedata = f.read()
#verify that the data is gzipEncoded. if not compress it
if 'text' in str(mimetypes.guess_type(complete_path)[0]):
if 'text/plain' in str(magic.from_buffer(messagedata, mime=True)):
messagedata = gzip.compress(messagedata)
complete_path += '.gz'
if complete_path[-4:] != '.gz':
#if paste do not have a 'date hierarchy', create it
@ -94,10 +93,14 @@ if __name__ == "__main__":
wanted_path = wanted_path.split('/')
wanted_path = '/'.join(wanted_path[-(4+args.hierarchy):])
path_to_send = 'import_dir/' + args.name + '>>' + wanted_path
# remove whitespace
wanted_path = wanted_path.replace(' ', '')
feeder_name = args.name.replace(' ', '')
path_to_send = 'import_dir/' + feeder_name + '>>' + wanted_path
s = b' '.join( [ args.channel.encode(), path_to_send.encode(), base64.b64encode(messagedata) ] )
socket.send(s)
print('import_dir/' + args.name+'>>'+wanted_path)
print('import_dir/' + feeder_name+'>>'+wanted_path)
time.sleep(args.seconds)
else: