add options to install from remote script (download to tmp)

This commit is contained in:
yucef sourani 2019-04-15 20:10:03 +03:00 committed by Mathieu Comandon
parent 2ae6ae5584
commit 7f3cef72d8

View file

@ -22,6 +22,8 @@ import signal
import sys
import gettext
from gettext import gettext as _
import requests
import tempfile
import gi
@ -113,6 +115,10 @@ class Application(Gtk.Application):
"install", ord("i"), GLib.OptionFlags.NONE, GLib.OptionArg.STRING,
_("Install a game from a yml file"), None,
)
self.add_main_option(
"remote_install", ord("r"), GLib.OptionFlags.NONE, GLib.OptionArg.STRING,
_("Install a game from a remote yml file"), None,
)
self.add_main_option(
"exec", ord("e"), GLib.OptionFlags.NONE, GLib.OptionArg.STRING,
_("Execute a program with the lutris runtime"), None,
@ -274,6 +280,24 @@ class Application(Gtk.Application):
if not os.path.isfile(installer_file):
self._print(command_line, "No such file: %s" % installer_file)
return 1
elif options.contains("remote_install"):
installer_file = options.lookup_value("remote_install").get_string()
self._print(command_line, "try to download %s started" % installer_file)
try:
filename_ = os.path.join(tempfile.gettempdir(),os.path.basename(installer_file))
with requests.get(installer_file, stream=True,allow_redirects=True) as r_:
r_.raise_for_status()
with open(filename_, 'wb') as f_:
for chunk in r_.iter_content(chunk_size=8192):
if chunk:
f_.write(chunk)
except Exception as e:
self._print(command_line, str(e))
self._print(command_line, "No such file: %s\nDownload file %s failed" %(filename_,installer_file))
return 1
else:
installer_file = filename_
action = "install"
db_game = None
if game_slug: