@@ -75,33 +75,31 @@ def zip_up(file_list,zip_name,output_folder=None):
7575 content = [content ]
7676 for copyfile in content :
7777 zf .write (copyfile ,os .path .basename (copyfile ))
78+ os .remove (copyfile )
7879
79- # If it's a list, write to new file, and save
80- elif isinstance (content ,list ):
81- filey = write_file ("%s/%s" % (tmpdir ,filename ),"\n " .join (content ))
82- zf .write (filey ,filename )
83- os .remove (filey )
84-
85- # If it's a dict, save to json
86- elif isinstance (content ,dict ):
87- filey = write_json (content ,"%s/%s" % (tmpdir ,filename ))
88- zf .write (filey ,filename )
89- os .remove (filey )
90-
91- # If it's a string, do the same
92- elif isinstance (content ,str ) or filename .endswith ('json' ):
93- filey = write_file ("%s/%s" % (tmpdir ,filename ),content )
94- zf .write (filey ,filename )
95- os .remove (filey )
96-
97- # Otherwise, just write the content into a new archive
98- elif isinstance (content ,bytes ):
99- filey = write_file ("%s/%s" % (tmpdir ,filename ),content .decode ('utf-8' ))
100- zf .write (filey ,filename )
101- os .remove (filey )
102-
103- else :
104- zf .write (content ,filename )
80+ else :
81+
82+ output_file = "%s/%s" % (tmpdir , filename )
83+
84+ # If it's a list, write to new file, and save
85+ if isinstance (content ,list ):
86+ write_file (output_file ,"\n " .join (content ))
87+
88+ # If it's a dict, save to json
89+ elif isinstance (content ,dict ):
90+ write_json (content ,output_file )
91+
92+ # If bytes, need to decode
93+ elif isinstance (content ,bytes ):
94+ write_file (output_file ,content .decode ('utf-8' ))
95+
96+ # String or other
97+ else :
98+ output_file = write_file (output_file ,content )
99+
100+ if os .path .exists (output_file ):
101+ zf .write (output_file ,filename )
102+ os .remove (output_file )
105103
106104 # Close the zip file
107105 zf .close ()
0 commit comments