Skip to content
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

Add a check-metadata command #36

Merged
merged 6 commits into from
Jul 24, 2024
Merged

Conversation

ClmntBcqt
Copy link
Contributor

PR for issue #15


def handle(self, *args, **options) :
for page in Page.load_glob(path = list(map(lambda p : Path(p).absolute(), options["content path"])), all = True) :
missing_metadata = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For better extensibilité, the alogrithm should be exported into a reusable function.

Example:

for page in Page.load_glob(path = list(map(lambda p : Path(p).absolute(), options["content path"])), all = True) :
    metadata_status = get_metadata_status_for(page)
    self.stdout.write("{:3.0f}% : {}".format(
        metadata_status.complete_percent,
        page.path.relative_to(page.content_page_dir)
    )
    if not metadata_status.is_complete():
        print [...]

Copy link
Member

@lebouquetin lebouquetin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a last suggested (but not required) improvment. You decide if you merge like this or if you implement the suggestion then merge.

self.missing.append(required_metadata)
elif page.metadata[required_metadata] == "" :
self.empty.append(required_metadata)
self.complete = self.missing == [] and self.empty == []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest addind parenthesis for readability self.complete = (self.missing == []) and (self.empty == [])

For readability comparison:

self.complete = self.missing == [] and self.empty == []
self.complete = (self.missing == [] and self.empty == [])
self.complete = (self.missing == []) and (self.empty == [])

Note that in the second line, black will remove parenthesis


metadata_status = MetadataStatus()
metadata_status.get_metadata_status_for(page)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the way you implement it, I suggest to rename get_metadata_status_for() to process()

So you use it like:

            metadata_status = MetadataStatus()
            metadata_status.process(page)

Another way would be to implement get_metadata_status_for() as a class method returning a MetadataStatus instance:

            metadata_status = MetadataStatus.get_metadata_status_for(page)

Note: this is not required for merge but it would make the code more readable for future maintainance


class MetadataStatus :

def get_metadata_status_for(page) :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard way to implement classmethod is:

  @classmethod
  def get_metadata_status_for(cls, page) :
    [...]

@ClmntBcqt ClmntBcqt merged commit d262481 into main Jul 24, 2024
2 checks passed
@ClmntBcqt ClmntBcqt deleted the feat__15_check_metadata_command branch July 24, 2024 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants