user1932645
user1932645

Reputation:

Checking repository and updating

I'm making a game using the (very) old Python library, PyGame. But that's not what I'm here to ask about.

How do I make a code that would check the repositories in a server with the latest build, check if the build is newer or the same, and if newer prompt the user to download (or deny) the update of the game, as it will be developed in multiple versions and will allow players to gradually update as we make changes.

Like Minecraft does once an update comes out and it prompts you to update... But in Python

Upvotes: 1

Views: 443

Answers (1)

jadkik94
jadkik94

Reputation: 7078

There are 3 things you need for this:

  1. A server where you will store all the information about the updates and versions.

    • It can be a web server (for Python, see flask, web.py, django, pylons, etc., or PHP or whatever) which can have a single page.
    • It will take the current version as input (GET/POST requests) and output the updates available (in a format that can be parsed, JSON preferably, or XML or just plain text).
    • These can be fetched from a database (see MySQL, postgresql, or any ORM that works with your choice of web server, sqlalchemy)
    • Or by checking the names of the files available on the server (if the files will be hosted on the same web server) (the names will have a pattern XXX-r24-20121224.tar.gz and you'll check the list of files with glob or something).
  2. A piece of code that will query the server every time you start your game to check with the web server if there are updates. You can use requests or urllib2 for example.

  3. A piece of code that will download and update your actual game.

    • The web server should give you a link to where the update file is
    • From there you will have to download it (with requests or urllib2)
    • Unzip it (using zipfile or tarfile) and replace your actual files with that.
    • Now it all depends on how your files are laid out:
      • If you're distributing the source code, what you could do is build it all in a package, and then you just replace the whole package.
      • The zipfile package and Python actually account for that, and they give you an option to only put the python files in the zip file and Python gives you an option to add said zip file to the PYTHONPATH and import directly from there.
      • If you're compiling it with py2exe or anything, it'll be a different issue: you might be able to only update one zip file, or replace the actual DLLs and stuff, which might be a big mess.
      • If it's a deb package or similar, you might want to use that to update, and ask the user to do it or something.

I hope this helps, even if it's very abstract. This had to be done :)

Now I'll give my own (biased) opinion: If you already have a website running, use that to add a single page for such a thing. Otherwise I'd recommend a free hosting that will allow you to set up a website using flask. I'd recommend that because it would be very easy to get it running in no time, plus it will allow you to use the great ORM sqlAlchemy. Also, I wouldn't bother with more than telling the user there is a new version and let them figure out where to get it. That's unless you are only distributing it in one standard way all over.

Upvotes: 1

Related Questions