Browse Source

Allows to get a file absolute path from a revision id

Adrien Panay 7 years ago
parent
commit
07a10000f1
1 changed files with 33 additions and 0 deletions
  1. 33 0
      tracim/tracim/lib/content.py

+ 33 - 0
tracim/tracim/lib/content.py View File

@@ -15,6 +15,8 @@ import re
15 15
 import tg
16 16
 from tg.i18n import ugettext as _
17 17
 
18
+from depot.manager import DepotManager
19
+
18 20
 import sqlalchemy
19 21
 from sqlalchemy.orm import aliased
20 22
 from sqlalchemy.orm import joinedload
@@ -450,6 +452,37 @@ class ContentApi(object):
450 452
 
451 453
         return revision
452 454
 
455
+    # def get_one_revision_file(self, revision_id: int = None):
456
+    #     """
457
+    #     This function allows us to directly get a Python file object from its
458
+    #     revision identifier.
459
+    #     :param revision_id: The revision id of the file we want to return
460
+    #     :return: The corresponding Python file object
461
+    #     """
462
+    #     revision = self.get_one_revision(revision_id)
463
+    #     return DepotManager.get().get(revision.depot_file_uid)
464
+
465
+    def get_one_revision_filepath(self, revision_id: int = None) -> str:
466
+        """
467
+        This method allows us to directly get a file path from its revision
468
+        identifier.
469
+        :param revision_id: The revision id of the filepath we want to return
470
+        :return: The corresponding filepath
471
+        """
472
+        revision = self.get_one_revision(revision_id)
473
+
474
+        dpt = DepotManager.get()
475
+        # python 3.6 PEP 526 -- Syntax for Variable Annotations
476
+        # https://www.python.org/dev/peps/pep-0526/
477
+        # dpt_path: str = dpt.storage_path
478
+        # dpt_file_dir: str = item.revision.depot_file_uid.file_id
479
+        # dpt_file_path: str = dpt_path + dpt_file_dir + dpt_file_name
480
+        dpt_path = dpt.storage_path
481
+        dpt_file_dir = revision.depot_file_uid.file_id
482
+        dpt_file_path = '{0}{1}/file'.format(dpt_path, dpt_file_dir)
483
+
484
+        return file_from_depot.name
485
+
453 486
     def get_one_by_label_and_parent(
454 487
             self,
455 488
             content_label: str,