Properly handle file extensions for BED/BIM/FAM files
authorDimitri Papadopoulos <dimitri.papadopoulos@cea.fr>
Wed, 17 Jul 2013 13:22:22 +0200
changeset 296 cf995b067f04
parent 295 6a88c772d7cd
child 297 d3ef87d7151b
Properly handle file extensions for BED/BIM/FAM files Additionally use high-level os.path functions with descriptive names instead of rewriting them and having to guess the purpose of the code.
views/download.py
--- a/views/download.py	Fri Jul 12 17:02:26 2013 +0200
+++ b/views/download.py	Wed Jul 17 13:22:22 2013 +0200
@@ -99,11 +99,11 @@
         for entity in self.cw_rset.entities():
             if entity.__regid__ == 'GenomicMeasure':
                 for ext in ('.bim', '.bed', '.fam'):
-                    filepaths.add((osp.basename(entity.filepath)+ext,
-                                   entity.concerns[0].identifier,
-                                   entity.full_filepath+ext))
+                    filepath = osp.splitext(osp.basename(entity.filepath))[0] + ext
+                    full_filepath = osp.splitext(entity.full_filepath)[0] + ext
+                    filepaths.add((filepath, entity.concerns[0].identifier, full_filepath))
             else:
-                filename = entity.type+'_'+entity.filepath.split('/')[-1]
+                filename = entity.type + '_' + osp.basename(entity.filepath)
                 filename = filename.replace(' ', '_')
                 filepaths.add((filename, entity.concerns[0].identifier, entity.full_filepath))
             for external_resource in entity.external_resources: