Manages comments in unpacked Word documents.
| 610 | |
| 611 | |
| 612 | class Document: |
| 613 | """Manages comments in unpacked Word documents.""" |
| 614 | |
| 615 | def __init__( |
| 616 | self, |
| 617 | unpacked_dir, |
| 618 | rsid=None, |
| 619 | track_revisions=False, |
| 620 | author="Claude", |
| 621 | initials="C", |
| 622 | ): |
| 623 | """ |
| 624 | Initialize with path to unpacked Word document directory. |
| 625 | Automatically sets up comment infrastructure (people.xml, RSIDs). |
| 626 | |
| 627 | Args: |
| 628 | unpacked_dir: Path to unpacked DOCX directory (must contain word/ subdirectory) |
| 629 | rsid: Optional RSID to use for all comment elements. If not provided, one will be generated. |
| 630 | track_revisions: If True, enables track revisions in settings.xml (default: False) |
| 631 | author: Default author name for comments (default: "Claude") |
| 632 | initials: Default author initials for comments (default: "C") |
| 633 | """ |
| 634 | self.original_path = Path(unpacked_dir) |
| 635 | |
| 636 | if not self.original_path.exists() or not self.original_path.is_dir(): |
| 637 | raise ValueError(f"Directory not found: {unpacked_dir}") |
| 638 | |
| 639 | # Create temporary directory with subdirectories for unpacked content and baseline |
| 640 | self.temp_dir = tempfile.mkdtemp(prefix="docx_") |
| 641 | self.unpacked_path = Path(self.temp_dir) / "unpacked" |
| 642 | shutil.copytree(self.original_path, self.unpacked_path) |
| 643 | |
| 644 | # Pack original directory into temporary .docx for validation baseline (outside unpacked dir) |
| 645 | self.original_docx = Path(self.temp_dir) / "original.docx" |
| 646 | pack_document(self.original_path, self.original_docx, validate=False) |
| 647 | |
| 648 | self.word_path = self.unpacked_path / "word" |
| 649 | |
| 650 | # Generate RSID if not provided |
| 651 | self.rsid = rsid if rsid else _generate_rsid() |
| 652 | print(f"Using RSID: {self.rsid}") |
| 653 | |
| 654 | # Set default author and initials |
| 655 | self.author = author |
| 656 | self.initials = initials |
| 657 | |
| 658 | # Cache for lazy-loaded editors |
| 659 | self._editors = {} |
| 660 | |
| 661 | # Comment file paths |
| 662 | self.comments_path = self.word_path / "comments.xml" |
| 663 | self.comments_extended_path = self.word_path / "commentsExtended.xml" |
| 664 | self.comments_ids_path = self.word_path / "commentsIds.xml" |
| 665 | self.comments_extensible_path = self.word_path / "commentsExtensible.xml" |
| 666 | |
| 667 | # Load existing comments and determine next ID (before setup modifies files) |
| 668 | self.existing_comments = self._load_existing_comments() |
| 669 | self.next_comment_id = self._get_next_comment_id() |
nothing calls this directly
no outgoing calls
no test coverage detected