Left: | ||
Right: |
OLD | NEW |
---|---|
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """The path helper.""" | 2 """The path helper.""" |
3 | 3 |
4 from dfvfs.lib import definitions as dfvfs_definitions | 4 from dfvfs.lib import definitions as dfvfs_definitions |
5 | 5 |
6 from plaso.lib import py2to3 | 6 from plaso.lib import py2to3 |
7 | 7 |
8 | 8 |
9 class PathHelper(object): | 9 class PathHelper(object): |
10 """Class that implements the path helper.""" | 10 """Class that implements the path helper.""" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 path_segments[index] = lookup_table.get(lookup_key, path_segment) | 44 path_segments[index] = lookup_table.get(lookup_key, path_segment) |
45 | 45 |
46 return u'\\'.join(path_segments) | 46 return u'\\'.join(path_segments) |
47 | 47 |
48 @classmethod | 48 @classmethod |
49 def GetDisplayNameForPathSpec( | 49 def GetDisplayNameForPathSpec( |
50 cls, path_spec, mount_path=None, text_prepend=None): | 50 cls, path_spec, mount_path=None, text_prepend=None): |
51 """Retrieves the display name of a path specification. | 51 """Retrieves the display name of a path specification. |
52 | 52 |
53 Args: | 53 Args: |
54 path_spec (dfvfs.PathSpec): path specification. | 54 path_spec (dfvfs.PathSpec): path specification. |
onager
2017/01/19 16:46:24
path_specification, to be consistent
Joachim Metz
2017/01/22 15:03:13
Ack, will revisit at a later time.
| |
55 mount_path (Optional[str]): path where the file system that is used | 55 mount_path (Optional[str]): path where the file system that is used |
56 by the path specification is mounted, such as "/mnt/image". The | 56 by the path specification is mounted, such as "/mnt/image". The |
57 mount path will be stripped from the absolute path defined by | 57 mount path will be stripped from the absolute path defined by |
58 the path specification. | 58 the path specification. |
59 text_prepend (Optional[str]): text to prepend. | 59 text_prepend (Optional[str]): text to prepend. |
60 | 60 |
61 Returns: | 61 Returns: |
62 str: human readable version of the path specification. | 62 str: human readable version of the path specification or None. |
63 """ | 63 """ |
64 relative_path = cls.GetRelativePathFromPathSpec( | 64 if not path_spec: |
65 return | |
66 | |
67 relative_path = cls.GetRelativePathForPathSpec( | |
65 path_spec, mount_path=mount_path) | 68 path_spec, mount_path=mount_path) |
66 if not relative_path: | 69 if not relative_path: |
67 return path_spec.type_indicator | 70 return path_spec.type_indicator |
68 | 71 |
69 if text_prepend: | 72 if text_prepend: |
70 relative_path = u'{0:s}{1:s}'.format(text_prepend, relative_path) | 73 relative_path = u'{0:s}{1:s}'.format(text_prepend, relative_path) |
71 | 74 |
72 parent_path_spec = path_spec.parent | 75 parent_path_spec = path_spec.parent |
73 if parent_path_spec and path_spec.type_indicator in [ | 76 if parent_path_spec and path_spec.type_indicator in [ |
74 dfvfs_definitions.TYPE_INDICATOR_BZIP2, | 77 dfvfs_definitions.TYPE_INDICATOR_BZIP2, |
75 dfvfs_definitions.TYPE_INDICATOR_GZIP]: | 78 dfvfs_definitions.TYPE_INDICATOR_GZIP]: |
76 parent_path_spec = parent_path_spec.parent | 79 parent_path_spec = parent_path_spec.parent |
77 | 80 |
78 if parent_path_spec and parent_path_spec.type_indicator in [ | 81 if parent_path_spec and parent_path_spec.type_indicator in [ |
79 dfvfs_definitions.TYPE_INDICATOR_VSHADOW]: | 82 dfvfs_definitions.TYPE_INDICATOR_VSHADOW]: |
80 store_index = getattr(path_spec.parent, u'store_index', None) | 83 store_index = getattr(path_spec.parent, u'store_index', None) |
81 if store_index is not None: | 84 if store_index is not None: |
82 return u'VSS{0:d}:{1:s}:{2:s}'.format( | 85 return u'VSS{0:d}:{1:s}:{2:s}'.format( |
83 store_index + 1, path_spec.type_indicator, relative_path) | 86 store_index + 1, path_spec.type_indicator, relative_path) |
84 | 87 |
85 return u'{0:s}:{1:s}'.format(path_spec.type_indicator, relative_path) | 88 return u'{0:s}:{1:s}'.format(path_spec.type_indicator, relative_path) |
86 | 89 |
87 @classmethod | 90 @classmethod |
88 def GetRelativePathFromPathSpec(cls, path_spec, mount_path=None): | 91 def GetRelativePathForPathSpec(cls, path_spec, mount_path=None): |
onager
2017/01/19 16:46:24
path_specification, to be consistent
Joachim Metz
2017/01/22 15:03:14
Ack, will revisit at a later time.
| |
89 """Retrieves the relative path of a path specification. | 92 """Retrieves the relative path of a path specification. |
90 | 93 |
91 If a mount path is defined the path will be relative to the mount point, | 94 If a mount path is defined the path will be relative to the mount point, |
92 otherwise the path is relative to the root of the file system that is used | 95 otherwise the path is relative to the root of the file system that is used |
93 by the path specification. | 96 by the path specification. |
94 | 97 |
95 Args: | 98 Args: |
96 path_spec (dfvfs.PathSpec): path specification. | 99 path_spec (dfvfs.PathSpec): path specification. |
97 mount_path (Optional[str]): path where the file system that is used | 100 mount_path (Optional[str]): path where the file system that is used |
98 by the path specification is mounted, such as "/mnt/image". The | 101 by the path specification is mounted, such as "/mnt/image". The |
(...skipping 22 matching lines...) Expand all Loading... | |
121 if path_spec.type_indicator != dfvfs_definitions.TYPE_INDICATOR_OS: | 124 if path_spec.type_indicator != dfvfs_definitions.TYPE_INDICATOR_OS: |
122 return location | 125 return location |
123 | 126 |
124 # If we are parsing a mount point we don't want to include the full | 127 # If we are parsing a mount point we don't want to include the full |
125 # path to file's location here, we are only interested in the path | 128 # path to file's location here, we are only interested in the path |
126 # relative to the mount point. | 129 # relative to the mount point. |
127 if mount_path: | 130 if mount_path: |
128 _, _, location = location.partition(mount_path) | 131 _, _, location = location.partition(mount_path) |
129 | 132 |
130 return location | 133 return location |
OLD | NEW |