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

enh: Convenience wrapper for file download/upload #50

Open
MatPoppFHG opened this issue Feb 20, 2024 · 3 comments
Open

enh: Convenience wrapper for file download/upload #50

MatPoppFHG opened this issue Feb 20, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@MatPoppFHG
Copy link
Contributor

Currently a simple file-download takes 20-30 lines of code. This should be reduced to one line. Suggestion:

import osw
from osw.express import file_download

file: osw.model.LocalFile = file_download("https://wiki-dev.open-semantic-lab.org/w/img_auth.php/3/3b/OSWe7d2664d26334d99a10093557bba77d5.txt")

df = pd.load_csv(file.raw)

What should happen in background:

  • parse correct osw instance from link
  • look up if credentials for instance exist
    *if yes => log in , go on
    *if no => log in popup/prompt, with option to save credentials in local encrypted file
  • update local model (WikiFile, LocalFile)

suggestion for funciton definition:

def file_download(file: str , credentials_path = "usual/path/to/local/model", download_cache = "", osw_domain = None, return_binary = 
False) -> Union[path, bytesio]:
  """
  convenience function to quickly download a file from osw via a url that can conveniently be copied from the browser url line
  """
  if osw_domain is not None:
    ### prepend domain to file , else file must contain valid domain + osw id
@MatPoppFHG MatPoppFHG added the enhancement New feature or request label Feb 20, 2024
@LukasGold
Copy link
Contributor

LukasGold commented Feb 20, 2024

What we would still need or is currently problematic: the reload of the model.entity classes generated by the controller imports leads to errors when serializing objects because the model loaded at the top by importing osw dont match the models imported by the reload (not pointing to the same memory entry).

Option a) Therefore, in my opinion, just as the controllers are part of osw-python, the (File) models should also be part of it.
This is scalable and can be transferred now and in future to other schemata. Idea for implementation: Before overwriting and re-importing entity.py, check whether it would result in any changes at all. Can this be implemented at code generator level?

Option b) Alternatively, the models could be persisted and not be replaced if already loaded. This would require maintenance of osw-python parallel to the PagePackages

@SimonStier
Copy link
Contributor

SimonStier commented Feb 20, 2024

The actual file download can be condensed to 2 lines (see https://github.com/OpenSemanticLab/osw-python/blob/a30bb5e248bebcb75ec6e2c15f850f87b0f2b5cd/examples/file_upload_download.py#L60C1-L63C18)

wf2 = osw_obj.load_entity("File:OSWe7d2664d26334d99a10093557bba77d5.txt").cast(WikiFileController, osw=osw_obj) 
LocalFileController(path="dummy2.txt").put_from(wf2)

(the first line may look bloated, by this approach will be consistent for any controller, inkl. DeviceController, DbController, etc.)
So I guess the discussion is more about the osw initialization (login, schema download) and maybe a wrapper for the two lines above

@LukasGold
Copy link
Contributor

@MatPoppFHG A first draft is ready for review at: main...50-enh-osw-express

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

3 participants