file
File
Bases: MdObj
A stored file.
This is typically not needed by the end-user.
Source code in mkreports/md/file.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
__init__(path, page_info, allow_copy=True, use_hash=False)
Store a file in the page-store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Union[str, Path]
|
Path to the file, relative to current directory or absolute. |
required |
page_info |
PageInfo
|
PageInfo for the page where the file should be stored. |
required |
allow_copy |
bool
|
Is the file allowed to be copied? Otherwise, original location is used. |
True
|
use_hash |
bool
|
If copy is allowed, renames the file to include the file hash. |
False
|
Source code in mkreports/md/file.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
hash()
Calculate the hash of the file.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Md5-hash as a string. |
Source code in mkreports/md/file.py
150 151 152 153 154 155 156 157 158 159 160 161 |
|
md5_hash_file(path)
Get md5 hash of a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
Absolute path or relative to current directory of the file. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The md5 hash of the file. |
Source code in mkreports/md/file.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
relpath_html(target, page_path)
Relative path as to be used for html. This is a bit more complicated, as some markdown pages are encoded as a directory (with implicit index.html being called).
The paths can be relative or absolute. If relative, should be relative to same directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
Path
|
The target path |
required |
page_path |
Path
|
Path of the current page. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Relative path as a string. |
Source code in mkreports/md/file.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
store_asset_relpath(asset_path_mkreports, page_info)
Store an asset and return relative path to it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
asset_path |
Path
|
Relative asset path inside 'mkreports' |
required |
page_info |
PageInfo
|
PageInfo for the page in use |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Path to the asset as it should be used from html |
Source code in mkreports/md/file.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
true_stem(path)
True stem of a path, without all suffixes, not just last.
Source code in mkreports/md/file.py
14 15 16 |
|