| 607 | |
| 608 | # Hash files in directory |
| 609 | def hashFiles(self, dir_inner_path, ignore_pattern=None, optional_pattern=None): |
| 610 | files_node = {} |
| 611 | files_optional_node = {} |
| 612 | if dir_inner_path and not self.isValidRelativePath(dir_inner_path): |
| 613 | ignored = True |
| 614 | self.log.error("- [ERROR] Only ascii encoded directories allowed: %s" % dir_inner_path) |
| 615 | |
| 616 | for file_relative_path in self.site.storage.walk(dir_inner_path, ignore_pattern): |
| 617 | file_name = helper.getFilename(file_relative_path) |
| 618 | |
| 619 | ignored = optional = False |
| 620 | if file_name == "content.json": |
| 621 | ignored = True |
| 622 | elif file_name.startswith(".") or file_name.endswith("-old") or file_name.endswith("-new"): |
| 623 | ignored = True |
| 624 | elif not self.isValidRelativePath(file_relative_path): |
| 625 | ignored = True |
| 626 | self.log.error("- [ERROR] Invalid filename: %s" % file_relative_path) |
| 627 | elif dir_inner_path == "" and self.site.storage.getDbFile() and file_relative_path.startswith(self.site.storage.getDbFile()): |
| 628 | ignored = True |
| 629 | elif optional_pattern and SafeRe.match(optional_pattern, file_relative_path): |
| 630 | optional = True |
| 631 | |
| 632 | if ignored: # Ignore content.json, defined regexp and files starting with . |
| 633 | self.log.info("- [SKIPPED] %s" % file_relative_path) |
| 634 | else: |
| 635 | if optional: |
| 636 | self.log.info("- [OPTIONAL] %s" % file_relative_path) |
| 637 | files_optional_node.update( |
| 638 | self.hashFile(dir_inner_path, file_relative_path, optional=True) |
| 639 | ) |
| 640 | else: |
| 641 | self.log.info("- %s" % file_relative_path) |
| 642 | files_node.update( |
| 643 | self.hashFile(dir_inner_path, file_relative_path) |
| 644 | ) |
| 645 | return files_node, files_optional_node |
| 646 | |
| 647 | # Create and sign a content.json |
| 648 | # Return: The new content if filewrite = False |