@@ -151,19 +151,21 @@ def generate_native_viewable_and_light_viewable(geode_object, data, original_fil
151151 name = data .name ()
152152 object_type = geode_functions .get_object_type (geode_object )
153153
154- os .makedirs (data_path , exist_ok = True )
154+ if not os .path .isdir (data_path ):
155+ os .makedirs (data_path )
155156
156157 additional_files_copied = []
157158 if original_filename :
158159 original_file_path = geode_functions .upload_file_path (original_filename )
159160 additional = geode_functions .additional_files (geode_object , original_file_path )
160-
161+
161162 for additional_file in additional .mandatory_files + additional .optional_files :
162- if not additional_file .is_missing and geode_functions . file_exists_in_upload ( additional_file . filename ) :
163+ if not additional_file .is_missing :
163164 source_path = geode_functions .upload_file_path (additional_file .filename )
164- dest_path = os .path .join (data_path , additional_file .filename )
165- shutil .copy2 (source_path , dest_path )
166- additional_files_copied .append (additional_file .filename )
165+ if os .path .exists (source_path ):
166+ dest_path = os .path .join (data_path , additional_file .filename )
167+ shutil .copy2 (source_path , dest_path )
168+ additional_files_copied .append (additional_file .filename )
167169
168170 saved_native_file_path = geode_functions .save (
169171 geode_object ,
@@ -178,21 +180,20 @@ def generate_native_viewable_and_light_viewable(geode_object, data, original_fil
178180 saved_light_viewable_file_path = geode_functions .save_light_viewable (
179181 geode_object , data , data_path , "light_viewable"
180182 )
181- f = open (saved_light_viewable_file_path , "rb" )
182- binary_light_viewable = f .read ()
183- f .close ()
183+ with open (saved_light_viewable_file_path , "rb" ) as f :
184+ binary_light_viewable = f .read ()
184185
185186 result = {
186187 "name" : name ,
187188 "native_file_name" : os .path .basename (saved_native_file_path [0 ]),
188189 "viewable_file_name" : viewable_file_name ,
189190 "id" : generated_id ,
190191 "object_type" : object_type ,
191- "binary_light_viewable" : str ( binary_light_viewable , "utf-8" ),
192+ "binary_light_viewable" : binary_light_viewable . decode ( "utf-8" ),
192193 "geode_object" : geode_object ,
193194 }
194-
195+
195196 if additional_files_copied :
196197 result ["additional_files" ] = additional_files_copied
197-
198+
198199 return result
0 commit comments