| 1120 | |
| 1121 | |
| 1122 | class DiffFormatter(BaseFormatter): |
| 1123 | KEY_DESCRIPTIONS = { |
| 1124 | "path": "archived file path", |
| 1125 | "change": "all available changes", |
| 1126 | "content": "file content change", |
| 1127 | "mode": "file mode change", |
| 1128 | "type": "file type change", |
| 1129 | "owner": "file owner (user/group) change", |
| 1130 | "user": "file user change", |
| 1131 | "group": "file group change", |
| 1132 | "link": "file link change", |
| 1133 | "directory": "file directory change", |
| 1134 | "blkdev": "file block device change", |
| 1135 | "chrdev": "file character device change", |
| 1136 | "fifo": "file fifo change", |
| 1137 | "mtime": "file modification time change", |
| 1138 | "ctime": "file change time change", |
| 1139 | "isomtime": "file modification time change (ISO 8601)", |
| 1140 | "isoctime": "file creation time change (ISO 8601)", |
| 1141 | } |
| 1142 | KEY_GROUPS = ( |
| 1143 | ("path", "change"), |
| 1144 | ("content", "mode", "type", "owner", "group", "user"), |
| 1145 | ("link", "directory", "blkdev", "chrdev", "fifo"), |
| 1146 | ("mtime", "ctime", "isomtime", "isoctime"), |
| 1147 | ) |
| 1148 | METADATA = ("mode", "type", "owner", "group", "user", "mtime", "ctime") |
| 1149 | |
| 1150 | def __init__(self, format, content_only=False): |
| 1151 | static_data = {} | self.FIXED_KEYS |
| 1152 | super().__init__(format or "{content}{link}{directory}{blkdev}{chrdev}{fifo} {path}{NL}", static_data) |
| 1153 | self.content_only = content_only |
| 1154 | self.format_keys = {f[1] for f in Formatter().parse(format)} |
| 1155 | self.call_keys = { |
| 1156 | "content": self.format_content, |
| 1157 | "mode": self.format_mode, |
| 1158 | "type": partial(self.format_mode, filetype=True), |
| 1159 | "owner": partial(self.format_owner), |
| 1160 | "group": partial(self.format_owner, spec="group"), |
| 1161 | "user": partial(self.format_owner, spec="user"), |
| 1162 | "link": partial(self.format_other, "link"), |
| 1163 | "directory": partial(self.format_other, "directory"), |
| 1164 | "blkdev": partial(self.format_other, "blkdev"), |
| 1165 | "chrdev": partial(self.format_other, "chrdev"), |
| 1166 | "fifo": partial(self.format_other, "fifo"), |
| 1167 | "mtime": partial(self.format_time, "mtime"), |
| 1168 | "ctime": partial(self.format_time, "ctime"), |
| 1169 | "isomtime": partial(self.format_iso_time, "mtime"), |
| 1170 | "isoctime": partial(self.format_iso_time, "ctime"), |
| 1171 | } |
| 1172 | self.used_call_keys = set(self.call_keys) & self.format_keys |
| 1173 | if self.content_only: |
| 1174 | self.used_call_keys -= set(self.METADATA) |
| 1175 | |
| 1176 | def get_item_data(self, item: "ItemDiff", jsonline=False) -> dict: |
| 1177 | diff_data = {} |
| 1178 | for key in self.used_call_keys: |
| 1179 | diff_data[key] = self.call_keys[key](item) |