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

SDNTB-604 Move NTB related feed parser and formatter from planning to NTB repo #1363

Merged
merged 3 commits into from
Oct 25, 2019

Conversation

ride90
Copy link
Contributor

@ride90 ride90 commented Oct 16, 2019

This PR goes side by side with superdesk/superdesk-ntb#344.
PR for NTB is broken because it has planning 1.7 as a dependency, instead, I've triggered a test instance superdesk/superdesk-ntb#345 (https://ntbpr-345.test.superdesk.org).

NOTE: I was able to ingest and output events on a test instance https://ntbpr-345.test.superdesk.org

@ride90 ride90 added this to the 1.9.0 milestone Oct 16, 2019
@coveralls
Copy link

coveralls commented Oct 16, 2019

Coverage Status

Coverage decreased (-0.8%) to 69.798% when pulling effc783 on ride90:SDNTB-604 into 4b2ce3d on superdesk:master.

@@ -117,7 +121,7 @@ def _update(self, provider, update):
content = io.BytesIO(attachment)
res = process_file_from_stream(content, part.get_content_type())
file_name, content_type, metadata = res
if isinstance(parser, NTBEventXMLFeedParser):
if NTBEventXMLFeedParser and isinstance(parser, NTBEventXMLFeedParser):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of attempting to import the NTBEventXMLFeedParser and testing isinstance, I think it might be better to use something similar to can_parse of the registered feed parser itself. This way these 3 usages for both NTBEventXMLFeedParser and IcsTwoFeedParser can be removed and move the logic into the parser themselves.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logic we have right now in event_file_service.py, event_http_service.py and event_email_service.py checks a class anyway. I don't see a way how a method in a parser can help here. We can avoid attempting to import NTBEventXMLFeedParser and import 'IcsTwoFeedParser' by checking a class name if parser.__class__.__name__ == 'NTBEventXMLFeedParser' which is IMO a less reliable.
Can you provide me an example of how you see a method similar to can_parse ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @MarkLark86 , any update on it ⬆️ ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use python's getattr to determine if the parser has a specific method defined, otherwise use the default. The purpose is to remove all specific NTB/ICS code from these services.

You could use something like the following:

if getattr(parser, 'parse_email'):
    parser.parse_email(....)
else:
    logger.warn('Ingesting event with unknown parser'
    new_items.append(parser.parse(data, provider)

And then implement something similar to parse_file and parse_http.

This will make it easier to maintain the code by separating out the implementation of the parser from the service entirely.

Copy link
Contributor Author

@ride90 ride90 Oct 24, 2019

Choose a reason for hiding this comment

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

@MarkLark86 check it, please.
Сorresponding сommit for NTB superdesk/superdesk-ntb@9d21317

P.S. We must restrict parsers per feeding service again. It was done some time ago, but it is time to do it again. For example, I don't think that all parsers should be available when EventHTTPFeedingService selected and etc. Anyway, this is out of the scope of this pr.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good to go

@ride90 ride90 merged commit 3529552 into superdesk:master Oct 25, 2019
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.

3 participants