@@ -649,6 +649,33 @@ def str_to_id(x):
649
649
chain .from_iterable (qdb .sql_connection .TRN .execute ()[idx :])))
650
650
651
651
652
+ def _path_builder (db_dir , filepath , mountpoint , subdirectory , obj_id ):
653
+ """Builds the path of a DB stored file
654
+
655
+ Parameters
656
+ ----------
657
+ db_dir : str
658
+ The DB base dir
659
+ filepath : str
660
+ The path stored in the DB
661
+ mountpoint : str
662
+ The mountpoint of the given file
663
+ subdirectory : bool
664
+ Whether the file is stored in a subdirectory in the mountpoint or not
665
+ obj_id : int
666
+ The id of the object to which the file is attached
667
+
668
+ Returns
669
+ -------
670
+ str
671
+ The full path of the given file
672
+ """
673
+ if subdirectory :
674
+ return join (db_dir , mountpoint , str (obj_id ), filepath )
675
+ else :
676
+ return join (db_dir , mountpoint , filepath )
677
+
678
+
652
679
def retrieve_filepaths (obj_fp_table , obj_id_column , obj_id , sort = None ,
653
680
fp_type = None ):
654
681
"""Retrieves the filepaths for the given object id
@@ -674,12 +701,6 @@ def retrieve_filepaths(obj_fp_table, obj_id_column, obj_id, sort=None,
674
701
object id
675
702
"""
676
703
677
- def path_builder (db_dir , filepath , mountpoint , subdirectory , obj_id ):
678
- if subdirectory :
679
- return join (db_dir , mountpoint , str (obj_id ), filepath )
680
- else :
681
- return join (db_dir , mountpoint , filepath )
682
-
683
704
sql_sort = ""
684
705
if sort == 'ascending' :
685
706
sql_sort = " ORDER BY filepath_id"
@@ -710,7 +731,7 @@ def path_builder(db_dir, filepath, mountpoint, subdirectory, obj_id):
710
731
results = qdb .sql_connection .TRN .execute_fetchindex ()
711
732
db_dir = get_db_files_base_dir ()
712
733
713
- return [(fpid , path_builder (db_dir , fp , m , s , obj_id ), fp_type_ )
734
+ return [(fpid , _path_builder (db_dir , fp , m , s , obj_id ), fp_type_ )
714
735
for fpid , fp , fp_type_ , m , s in results ]
715
736
716
737
@@ -845,6 +866,38 @@ def move_filepaths_to_upload_folder(study_id, filepaths):
845
866
qdb .sql_connection .TRN .execute ()
846
867
847
868
869
+ def get_filepath_information (filepath_id ):
870
+ """Gets the filepath information of filepath_id
871
+
872
+ Parameters
873
+ ----------
874
+ filepath_id : int
875
+ The filepath id
876
+
877
+ Returns
878
+ -------
879
+ dict
880
+ The filepath information
881
+ """
882
+ with qdb .sql_connection .TRN :
883
+ sql = """SELECT filepath_id, filepath, filepath_type, checksum,
884
+ data_type, mountpoint, subdirectory, active,
885
+ artifact_id
886
+ FROM qiita.filepath
887
+ JOIN qiita.filepath_type USING (filepath_type_id)
888
+ JOIN qiita.data_directory USING (data_directory_id)
889
+ LEFT JOIN qiita.artifact_filepath USING (filepath_id)
890
+ WHERE filepath_id = %s"""
891
+ qdb .sql_connection .TRN .add (sql , [filepath_id ])
892
+ res = dict (qdb .sql_connection .TRN .execute_fetchindex ()[0 ])
893
+
894
+ obj_id = res .pop ('artifact_id' )
895
+ res ['fullpath' ] = _path_builder (get_db_files_base_dir (),
896
+ res ['filepath' ], res ['mountpoint' ],
897
+ res ['subdirectory' ], obj_id )
898
+ return res
899
+
900
+
848
901
def filepath_id_to_rel_path (filepath_id ):
849
902
"""Gets the relative to the base directory of filepath_id
850
903
0 commit comments