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

Temporary file/directory support #1540

Open
1 of 5 tasks
heinezen opened this issue Sep 17, 2023 · 5 comments
Open
1 of 5 tasks

Temporary file/directory support #1540

heinezen opened this issue Sep 17, 2023 · 5 comments
Labels
area: assets Involved with assets (images, sounds, ...) good first issue Suitable for newcomers lang: c++ Done in C++ code lang: python Done in Python code nice new thing ☺ A new feature that was not there before

Comments

@heinezen
Copy link
Member

heinezen commented Sep 17, 2023

Required Skills: Python or C++

Difficulty: Easy

It would be nice if we could create temporary files/directories in our current file system abstraction API. We currently only use temporary structures in the converter, but they could be useful in other places, e.g. for unzipping archives or on-disk caching.

Creation of temporary files could be implemented in our Python file API or our C++ file API or in both. The Python-side implementation is more preferrable at the moment, since the converter is written Python and temporary files already have an active use case there.

The easiest way to implement support probably is to add a method that calls the underlying system libraries for temporary file/directory creation:

  • Python: tempfile module
  • C++: std::filesystem and std::tmpfile

The retrieved path is then wrapped in our Path/Directory classes and returned by the method.

Tasks:

  • Create temp file/dir and wrap them in openage file system API (Python)
  • Create temp file/dir and wrap them in openage file system API (C++)
  • Delete temp file/dir explicitely when object is destroyed
  • Use new implementation in code (currently only in converter)
  • (optional) Add method for checking if a file/dir is temporary

Further Reading

@heinezen heinezen added nice new thing ☺ A new feature that was not there before lang: c++ Done in C++ code lang: python Done in Python code good first issue Suitable for newcomers area: assets Involved with assets (images, sounds, ...) labels Sep 17, 2023
@heinezen heinezen added the hacktoberfest For newcomers from Hacktoberfest event label Sep 27, 2023
@heinezen heinezen pinned this issue Oct 22, 2023
@Ashhar-24
Copy link
Contributor

Hey @heinezen , I'm interested in working with this issue.
I'm new to open source but I've beginner level experience in working with Python and C++ both.
Can you please assign me this issue.

And also can you please elaborate more about the tasks that exactly what I've to do.
Thanks for your cooperation :)

@heinezen
Copy link
Member Author

@Ashhar-24 Hey, I assigned you to to the issue nw :)

Most of what we want from the task should be in the issue description already. The general goal is to make temporary file creation/access more easier than it is right now.

For a start, I think you should try out these steps:

  1. Compile and run the project one if you haven't already. Development works much better when you can test your own code :D
  2. Look at the current usage of tempfile in our code, e.g.
    def download_trial() -> AnyStr:
    """
    Download and extract the AoC trial version.
    Does not work yet. TODO: Find an exe unpack solution that works on all platforms
    """
    print(f"Downloading AoC trial version from {TRIAL_URL}")
    # pylint: disable=consider-using-with
    tempdir = tempfile.mkdtemp()
    with urlopen(TRIAL_URL) as response:
    with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
    shutil.copyfileobj(response, tmp_file)
    from ....cabextract.cab import CABFile
    cab = CABFile(tmp_file, 0x65678)
    sourcedir = Directory(tempdir).root
    print(f"Extracting game files to {sourcedir}...")
    dirs = [cab.root]
    # Loop over all files in the CAB archive and extract them
    # to the tempdir
    while len(dirs) > 0:
    cur_src_dir = dirs[0]
    cur_tgt_dir = sourcedir
    for part in cur_src_dir.parts:
    cur_tgt_dir = cur_tgt_dir[part]
    cur_tgt_dir.mkdirs()
    dirs.remove(cur_src_dir)
    for path in cur_src_dir.iterdir():
    if path.is_dir():
    dirs.append(path)
    if path.is_file():
    with cur_tgt_dir[path.name].open("wb") as target_file:
    with path.open("rb") as source_file:
    target_file.write(source_file.read())
    return tempdir
  3. openage has its own path interface that acts as a wrapper around system paths. It should be extended to get tempfile support. I think the easiest way to implement it in there is to add a staticmethod that first creates a temporary file using tempfile, then wraps it in our Path object and returns the reulting Path.

I think this should give you a good idea how to start. If you get stuck, you can ask more questions in the Matrix chat.

@heinezen heinezen removed the hacktoberfest For newcomers from Hacktoberfest event label Nov 4, 2023
@viswes31
Copy link

Hey @heinezen , I'm interested in working with this issue.
I'm new to open source but I've 10+ experience Python and C++ both.
I see some of the tasks in this issue are still open.
Can I work on this issue ?

Thank you :)

@TheJJ
Copy link
Member

TheJJ commented Apr 15, 2024

go for it!

@heinezen
Copy link
Member Author

@viswes31 Everything from the tasklist that's not ticked is still up for grabs ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: assets Involved with assets (images, sounds, ...) good first issue Suitable for newcomers lang: c++ Done in C++ code lang: python Done in Python code nice new thing ☺ A new feature that was not there before
Projects
Status: converter
Status: 🔖 TODO
Development

No branches or pull requests

4 participants