-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic config_tree implementation #354
Conversation
Miauwkeru
commented
Aug 11, 2023
- Add basic unix registry parts
- Create Config parser
- simplify get logic
- Detect configuration files
- add todo
- Add a generic space delimited config parser
- Update hacked together "registry"
67d0df5
to
34c62bf
Compare
@@ -742,6 +743,7 @@ def cmd_cat(self, args: argparse.Namespace, stdout: TextIO) -> Optional[bool]: | |||
fh = path.open() | |||
shutil.copyfileobj(fh, stdout) | |||
stdout.flush() | |||
print("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left over from debug code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was so the prompt after using cat
would start at a new line.
4b28d3c
to
8e1ec61
Compare
|
||
|
||
CONFIG_MAP: dict[str, LinuxConfigurationParser] = { | ||
"ini": Ini, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you could add these extensions:
- xml (for now uses fallbackparser, which is a constant for now pointing to txtparser)
- txt (txtparser, just a blob of text)
- json (fallback)
- cnf (default)
- conf (default)
- sample (txtparser)
- template (txtparser)
Then we at least have ~90% a working PoC, now xml behaves really weird.
Codecov Report
@@ Coverage Diff @@
## main #354 +/- ##
==========================================
+ Coverage 70.70% 70.77% +0.06%
==========================================
Files 235 236 +1
Lines 18098 18310 +212
==========================================
+ Hits 12796 12958 +162
- Misses 5302 5352 +50
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also wonder if aligning closer with the Windows registry implementation would make more sense, instead of the filesystem implementation.
|
||
@abstractmethod | ||
def parse_file(self, fh: TextIO) -> None: | ||
... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't @abstractmethod
only work if the class inherits from ABC
?
I'd probably just do the same as we do in the rest of Dissect, which is to not bother with ABC
(it's pretty heavy) and just raise NotImplementedError()
.
|
||
# TODO: Look if I can just create a parsing function and attach it to the | ||
# the parser below. | ||
class LinuxConfigurationParser: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class LinuxConfigurationParser: | |
class ConfigurationParser: |
I think the namespace makes it clear enough.
|
||
class Txt(LinuxConfigurationParser): | ||
def parse_file(self, fh: TextIO) -> None: | ||
self.parsed_data = {"content": fh.read(), "size": str(fh.tell())} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason you make a string out of size
?
|
||
def parse_file(self, fh: TextIO) -> None: | ||
new_info = {} | ||
for line in fh.readlines(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for line in fh.readlines(): | |
for line in fh: |
self.parsed_data = new_info | ||
|
||
|
||
CONFIG_MAP: dict[str, LinuxConfigurationParser] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CONFIG_MAP: dict[str, LinuxConfigurationParser] = { | |
CONFIG_MAP: dict[str, type[LinuxConfigurationParser]] = { |
} | ||
|
||
|
||
class ConfigurationFs(VirtualFilesystem): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class ConfigurationFs(VirtualFilesystem): | |
class ConfigurationFilesystem(VirtualFilesystem): |
|
||
|
||
class ConfigurationFs(VirtualFilesystem): | ||
__fstype__: str = "META:registry" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__fstype__: str = "META:registry" | |
__fstype__: str = "META:configuration" |