Skip to content

Wiki Index

MoinEditEntries

A sorted collection of Moin revision entry objects

create_home_page(self)

Builds a synthetic home page to link all the wiki entries together

Source code in moin2gitwiki/wikiindex.py
def create_home_page(self) -> Tuple[MoinEditEntry, str]:
    """Builds a synthetic home page to link all the wiki entries together"""
    revision = MoinEditEntry(
        edit_date=datetime.now(),
        page_revision="1",
        edit_type=MoinEditType.PAGE,
        page_name="Home",
        attachment="",
        comment="Synthetic Home Page",
        page_path="Home",
        user=self.ctx.users.get_user_by_id_or_anonymous("0"),
        ctx=self.ctx,
    )
    pages = {}
    for entry in self.entries:
        page_path = entry.markdown_page_name()
        page_split = entry.page_name.split("(2f)")
        page_name = page_split.pop()
        pages[page_path] = (
            len(page_split) * "  "
        ) + f"- [{page_name}]({page_path})\n"
        while len(page_split) > 0:
            page_path = "_".join(page_split)
            page_name = page_split.pop()
            if page_path not in pages:
                pages[page_path] = (len(page_split) * "  ") + f"- {page_name}\n"

    content = "# Home Page\n\n"
    for item in sorted(pages.keys()):
        content += pages[item]
    content += "\n----\n"

    return (revision, content)

MoinEditEntry

Represents a Moin page revision

There are multiple revisions per page.

Attributes:

Name Type Description
edit_date datetime

The date of the edit

page_revision str

The revision id of this revision - a string of a zero padded number

edit_type MoinEditType

Moin edit type

page_name str

The name of the page from the index file

previous_page_name str

The name the page previously had if renamed

page_path str

The name on the filesystem of the page

attachment str

attachment field - not used

comment str

comment filed - only used for git comments

user Moin2GitUser

the mapped moin user

ctx

Context - there for moin_path and logging

attachment_content_bytes(self)

The content of the attachment retrieved as a byte string

Source code in moin2gitwiki/wikiindex.py
def attachment_content_bytes(self):
    """The content of the attachment retrieved as a byte string"""
    data = self.attachment_content_path().read_bytes()
    return data

attachment_content_path(self)

The file pathname of the attachment file

Source code in moin2gitwiki/wikiindex.py
def attachment_content_path(self):
    """The file pathname of the attachment file"""
    if self.attachment is None:
        raise ValueError("No attachment path set")
    return self.ctx.moin_data.joinpath(
        "pages",
        self.page_path,
        "attachments",
        self.attachment,
    )

attachment_destination(self)

The new pathname of the attachment file

Source code in moin2gitwiki/wikiindex.py
def attachment_destination(self):
    """The new pathname of the attachment file"""
    if self.attachment is None:
        raise ValueError("No attachment path set")
    return os.path.join(
        "_attachments",
        self.page_path,
        self.attachment,
    )

markdown_page_name(self)

Page name translated

Source code in moin2gitwiki/wikiindex.py
def markdown_page_name(self):
    """Page name translated"""
    return self.markdown_transform(self.page_name)

markdown_page_path(self)

Page path translated

Source code in moin2gitwiki/wikiindex.py
def markdown_page_path(self):
    """Page path translated"""
    return self.markdown_transform(self.page_name) + ".md"

markdown_transform(self, thing)

Translates the (2f) to _ for use in Markdown page names

Source code in moin2gitwiki/wikiindex.py
def markdown_transform(self, thing: str) -> str:
    """Translates the (2f) to _ for use in Markdown page names"""
    return thing.replace("(2f)", "_")

page_name_unescaped(self)

Unescape the page name

Source code in moin2gitwiki/wikiindex.py
def page_name_unescaped(self) -> str:
    """Unescape the page name"""
    return self.unescape(self.page_name)

page_path_unescaped(self)

Unescape the page path

Source code in moin2gitwiki/wikiindex.py
def page_path_unescaped(self) -> str:
    """Unescape the page path"""
    return self.unescape(self.page_path)

unescape(self, thing)

Uescape a wiki name - translate (2f) to /

Source code in moin2gitwiki/wikiindex.py
def unescape(self, thing: str) -> str:
    """Uescape a wiki name - translate (2f) to /"""
    return thing.replace("(2f)", "/")

wiki_content(self)

The content of the wiki revision as an array of strings

Source code in moin2gitwiki/wikiindex.py
def wiki_content(self):
    """The content of the wiki revision as an array of strings"""
    lines = []
    try:
        lines = self.wiki_content_path().read_text().splitlines(keepends=False)
    except OSError:
        lines = None
    return lines

wiki_content_bytes(self)

The content of the wiki revision retrieved as a byte string

Source code in moin2gitwiki/wikiindex.py
def wiki_content_bytes(self):
    """The content of the wiki revision retrieved as a byte string"""
    lines = self.wiki_content()
    if lines is None:
        return lines
    else:
        lines.append("")
        return "\n".join(lines).encode("utf-8")

wiki_content_path(self)

The file pathname of the revision file

Source code in moin2gitwiki/wikiindex.py
def wiki_content_path(self):
    """The file pathname of the revision file"""
    return self.ctx.moin_data.joinpath(
        "pages",
        self.page_path,
        "revisions",
        self.page_revision,
    )

MoinEditType

An enumeration.