abhishek-ram / django-pyas2

AS2 file transfer Server built on Python and Django.
https://django-pyas2.readthedocs.io
GNU General Public License v3.0
78 stars 31 forks source link

extend utils run_post_send/run_post_receive for integration #53

Closed gainskills closed 3 years ago

gainskills commented 3 years ago

extend utils run_post_send/run_post_receive for integration (it only supports external command, right now could do with utils cust_run_post_send/cust_run_post_receive

abhishek-ram commented 3 years ago

I don't think this solution works, because the only way to cust_run_post_send and cust_run_post_receive is to fork the repo and define it in the class which defeats the purpose of this change.

One approach could be:

  1. Define a setting like CUSTOM_RUN_POST_SEND = "path_to_func.cust_post_send"
  2. Load the function in pyas2.settings
  3. Call the custom function if set:
    if pyas2_settings.CUSTOM_RUN_POST_SEND:
    pyas2_settings.CUSTOM_RUN_POST_SEND(message)
    else:
    run_post_send(message)
gainskills commented 3 years ago

I don't think this solution works, because the only way to cust_run_post_send and cust_run_post_receive is to fork the repo and define it in the class which defeats the purpose of this change.

One approach could be:

  1. Define a setting like CUSTOM_RUN_POST_SEND = "path_to_func.cust_post_send"
  2. Load the function in pyas2.settings
  3. Call the custom function if set:
if pyas2_settings.CUSTOM_RUN_POST_SEND:
    pyas2_settings.CUSTOM_RUN_POST_SEND(message)
else:
    run_post_send(message)

@abhishek-ram thanks for your comment. I did a test before I post the PR, it works for me.

I also agree with your suggestion about having a setting to link functions for integration.

But, with the dependency, could you please suggest how to handle the dependency?

Thanks,

abhishek-ram commented 3 years ago

I know it works but I meant not working from a usability stand point.

What do you mean by dependency, can you elaborate?

gainskills commented 3 years ago
  1. I agree on that the implementation should be more elegant
  2. The dependency means, the library needs to concern about third party libraries depency. I might misunderstand your point. Could you please share more details about it?
abhishek-ram commented 3 years ago

Basically in the settings file of your django project you would define something like

PYAS2 = {
    "CUSTOM_RUN_POST_SEND": "path_to_func.cust_post_send"
}

and in the pyas2.settings module you would load it like so:

from django.utils.module_loading import import_string

CUSTOM_RUN_POST_SEND = APP_SETTINGS.get("CUSTOM_RUN_POST_SEND")
if CUSTOM_RUN_POST_SEND: 
    CUSTOM_RUN_POST_SEND = import_string(CUSTOM_RUN_POST_SEND)

You can then use CUSTOM_RUN_POST_SEND wherever post send is called and call this function instead.

gainskills commented 3 years ago

Basically in the settings file of your django project you would define something like

PYAS2 = {
    "CUSTOM_RUN_POST_SEND": "path_to_func.cust_post_send"
}

and in the pyas2.settings module you would load it like so:

from django.utils.module_loading import import_string

CUSTOM_RUN_POST_SEND = APP_SETTINGS.get("CUSTOM_RUN_POST_SEND")
if CUSTOM_RUN_POST_SEND: 
    CUSTOM_RUN_POST_SEND = import_string(CUSTOM_RUN_POST_SEND)

You can then use CUSTOM_RUN_POST_SEND wherever post send is called and call this function instead.

Thanks for sharing this. Could you please roll the change out?

Thanks,