Skip to content

Commit

Permalink
fix: fixed bugs in ingestion of manpages
Browse files Browse the repository at this point in the history
  • Loading branch information
mundanevision20 authored Sep 16, 2024
1 parent b807e60 commit 6a8fba0
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions explainshell/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import collections
import re
import logging
from pprint import pprint

# from pprint import pprint

import pymongo
from bson import ObjectId
Expand Down Expand Up @@ -69,7 +70,7 @@ def to_store(self):
def __repr__(self):
t = self.clean_text()
t = t[: min(20, t.find("\n"))].lstrip()
return "<paragraph %d, %s: %r>" % (self.idx, self.section, t)
return f"<paragraph {self.idx}, {self.section}: {t}>"

def __eq__(self, other):
if not other:
Expand Down Expand Up @@ -108,6 +109,8 @@ def opts(self):
def from_store(cls, d):
p = Paragraph.from_store(d)

# logger.debug(str(vars(d)))

return cls(
p,
d["short"],
Expand All @@ -128,7 +131,7 @@ def to_store(self):
return d

def __str__(self):
return "(%s)" % ", ".join([str(x) for x in self.opts])
return "(" + ", ".join([str(x) for x in self.opts]) + ")"

def __repr__(self):
return f"<options for paragraph {self.idx}: {self}"
Expand Down Expand Up @@ -249,16 +252,34 @@ def from_store(d):
else:
synopsis = help_constants.NO_SYNOPSIS

partial_match = None
if "partialmatch" in d:
partial_match = d["partialmatch"]
elif "partial_match" in d:
partial_match = d["partial_match"]

multi_cmd = None
if "multicommand" in d:
multi_cmd = d["multicommand"]
elif "multi_cmd" in d:
multi_cmd = d["multi_cmd"]

nested_cmd = None
if "nestedcmd" in d:
nested_cmd = d["nestedcmd"]
elif "nested_cmd" in d:
nested_cmd = d["nested_cmd"]

return ManPage(
d["source"],
d["name"],
synopsis,
paragraphs,
[tuple(x) for x in d["aliases"]],
d["partialmatch"],
d["multicommand"],
partial_match,
multi_cmd,
d["updated"],
d.get("nestedcmd"),
nested_cmd,
)

@staticmethod
Expand Down Expand Up @@ -345,9 +366,11 @@ def find_man_page(self, name):
raise errors.ProgramDoesNotExist(name)

dsts = {d["dst"]: d["score"] for d in cursor}
cursor = list(self.manpage.find(
{"_id": {"$in": list(dsts.keys())}}, {"name": 1, "source": 1}
))
cursor = list(
self.manpage.find(
{"_id": {"$in": list(dsts.keys())}}, {"name": 1, "source": 1}
)
)
if len(list(cursor)) != len(dsts):
logger.error(
"one of %r mappings is missing in manpage collection "
Expand Down

0 comments on commit 6a8fba0

Please sign in to comment.