浏览代码

Allows to get a file absolute path from a revision id

Adrien Panay 8 年前
父节点
当前提交
07a10000f1
共有 1 个文件被更改,包括 33 次插入0 次删除
  1. 33 0
      tracim/tracim/lib/content.py

+ 33 - 0
tracim/tracim/lib/content.py 查看文件

15
 import tg
15
 import tg
16
 from tg.i18n import ugettext as _
16
 from tg.i18n import ugettext as _
17
 
17
 
18
+from depot.manager import DepotManager
19
+
18
 import sqlalchemy
20
 import sqlalchemy
19
 from sqlalchemy.orm import aliased
21
 from sqlalchemy.orm import aliased
20
 from sqlalchemy.orm import joinedload
22
 from sqlalchemy.orm import joinedload
450
 
452
 
451
         return revision
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
     def get_one_by_label_and_parent(
486
     def get_one_by_label_and_parent(
454
             self,
487
             self,
455
             content_label: str,
488
             content_label: str,