Repository: lutris/lutris

Issue:
Version 0.5.9.1 CLI is broken.
### Bug description

I am using Gentoo Linux (multilib profile), and I am using Python 3.9.9. I have recently installed Lutris, and I get the following error when using the '-s' flag to list my Steam games.
```
jamie@TuxBox ~ $ lutris -s
2021-12-15 19:04:59,704: Starting Lutris 0.5.9.1
2021-12-15 19:04:59,832: No cores found
2021-12-15 19:05:02,350: Startup complete
2021-12-15 19:05:02,353: Using NVIDIA drivers 495.44 for x86_64
2021-12-15 19:05:02,353: GPU: Unknown
2021-12-15 19:05:02,354: GPU: 10DE:13C2 10DE:1116 (nvidia drivers)
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/lutris/gui/application.py", line 348, in do_command_line
    self.print_steam_list(command_line)
  File "/usr/lib/python3.9/site-packages/lutris/gui/application.py", line 598, in print_steam_list
    for path in steamapps_paths[platform]:
TypeError: 'dict_values' object is not subscriptable
2021-12-15 19:05:02,455: Shutting down Lutris
jamie@TuxBox ~ $
```

This also occurs for the --list-steam-folders option:
```
jamie@TuxBox ~ $ lutris --list-steam-folders
2021-12-15 19:09:41,515: Starting Lutris 0.5.9.1
2021-12-15 19:09:41,643: No cores found
2021-12-15 19:09:43,463: Failed to read content length on response from https://api.github.com/repos/lutris/dxvk/releases
2021-12-15 19:09:43,966: Failed to read content length on response from https://api.github.com/repos/lutris/dxvk-nvapi/releases
2021-12-15 19:09:44,457: Failed to read content length on response from https://api.github.com/repos/lutris/vkd3d/releases
2021-12-15 19:09:44,952: Startup complete
2021-12-15 19:09:44,955: Using NVIDIA drivers 495.44 for x86_64
2021-12-15 19:09:44,956: GPU: Unknown
2021-12-15 19:09:44,957: GPU: 10DE:13C2 10DE:1116 (nvidia drivers)
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/lutris/gui/application.py", line 352, in do_command_line
    self.print_steam_folders(command_line)
  File "/usr/lib/python3.9/site-packages/lutris/gui/application.py", line 627, in print_steam_folders
    for path in steamapps_paths[platform]:
TypeError: 'dict_values' object is not subscriptable
2021-12-15 19:09:45,056: Shutting down Lutris
jamie@TuxBox ~ $
```

And the '-o' option just boots me into Lutris:
```
jamie@TuxBox ~ $ lutris -o
2021-12-15 19:11:16,467: Starting Lutris 0.5.9.1
2021-12-15 19:11:16,596: No cores found
2021-12-15 19:11:18,855: Startup complete
2021-12-15 19:11:18,858: Using NVIDIA drivers 495.44 for x86_64
2021-12-15 19:11:18,859: GPU: Unknown
2021-12-15 19:11:18,860: GPU: 10DE:13C2 10DE:1116 (nvidia drivers)
2021-12-15 19:11:20,776: Unable to load icon from image /home/jamie/.cache/lutris/steam/banners/2064-read-only-memories.jpg
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/lutris/gui/lutriswindow.py", line 455, in update_store
    self.game_store.add_game(game)
  File "/usr/lib/python3.9/site-packages/lutris/gui/views/store.py", line 158, in add_game
    game.get_pixbuf(),
  File "/usr/lib/python3.9/site-packages/lutris/gui/views/store_item.py", line 107, in get_pixbuf
    return get_pixbuf(image_path, self.service_media.size, is_installed=self.installed)
  File "/usr/lib/python3.9/site-packages/lutris/gui/widgets/utils.py", line 62, in get_pixbuf
    pixbuf.composite(
AttributeError: 'NoneType' object has no attribute 'composite'

```

-l seems to be fine though
```
amie@TuxBox ~ $ lutris -l
2021-12-15 19:13:43,672: Starting Lutris 0.5.9.1
2021-12-15 19:13:43,799: No cores found
2021-12-15 19:13:46,043: Startup complete
2021-12-15 19:13:46,045: Using NVIDIA drivers 495.44 for x86_64
2021-12-15 19:13:46,046: GPU: Unknown
2021-12-15 19:13:46,047: GPU: 10DE:13C2 10DE:1116 (nvidia drivers)
2021-12-15 19:13:46,136: Shutting down Lutris
jamie@TuxBox ~ $
```

### How to Reproduce

Steps to reproduce the behavior:

Execute the command _lutris -s_ or _lutris --list-steam-folders_ or _lutris -o_


### Expected behavior

The CLI commands should perform as they are described in _lutris -h_

### Log output

```shell
jamie@TuxBox ~ $ lutris -d
2021-12-15 19:14:27,447: Starting Lutris 0.5.9.1
2021-12-15 19:14:27,576: No cores found
2021-12-15 19:14:29,984: Failed to read content length on response from https://api.github.com/repos/lutris/vkd3d/releases
2021-12-15 19:14:30,471: Failed to read content length on response from https://api.github.com/repos/lutris/d3d_extras/releases
2021-12-15 19:14:30,473: Startup complete
INFO     2021-12-15 19:14:30,476 [startup.check_driver:53]:Using NVIDIA drivers 495.44 for x86_64
INFO     2021-12-15 19:14:30,477 [startup.check_driver:57]:GPU: Unknown
INFO     2021-12-15 19:14:30,478 [startup.check_driver:73]:GPU: 10DE:13C2 10DE:1116 (nvidia drivers)
DEBUG    2021-12-15 19:14:32,375 [lutriswindow.update_store:451]:Showing 310 games
ERROR    2021-12-15 19:14:32,378 [utils.get_pixbuf:51]:Unable to load icon from image /home/jamie/.cache/lutris/steam/banners/2064-read-only-memories.jpg
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/lutris/gui/lutriswindow.py", line 455, in update_store
    self.game_store.add_game(game)
  File "/usr/lib/python3.9/site-packages/lutris/gui/views/store.py", line 158, in add_game
    game.get_pixbuf(),
  File "/usr/lib/python3.9/site-packages/lutris/gui/views/store_item.py", line 107, in get_pixbuf
    return get_pixbuf(image_path, self.service_media.size, is_installed=self.installed)
  File "/usr/lib/python3.9/site-packages/lutris/gui/widgets/utils.py", line 62, in get_pixbuf
    pixbuf.composite(
AttributeError: 'NoneType' object has no attribute 'composite'
```


### System Information

```shell
Gentoo Linux, kernel version 5.15.6, Python version 3.9.9
```


### Media (optional)

_No response_

### Checklist:

- [X] I'm not asking for support with a game or the wine runner.
- [X] I have followed the above mentioned guides and have all the graphics and wine dependencies installed.
- [X] I have checked for existing issues that describe my problem prior to opening this one.
- [X] I understand that improperly formatted bug reports may be closed without explanation.


Discussion:

Resolving patch:
diff --git a/lutris/gui/application.py b/lutris/gui/application.py
--- a/lutris/gui/application.py
+++ b/lutris/gui/application.py
@@ -604,7 +604,7 @@ def print_game_json(self, command_line, game_list):
     def print_steam_list(self, command_line):
         steamapps_paths = get_steamapps_paths()
         for platform in ("linux", "windows"):
-            for path in steamapps_paths[platform]:
+            for path in steamapps_paths[platform] if steamapps_paths else []:
                 appmanifest_files = get_appmanifests(path)
                 for appmanifest_file in appmanifest_files:
                     appmanifest = AppManifest(os.path.join(path, appmanifest_file))
@@ -634,7 +634,7 @@ def execute_command(command):
     def print_steam_folders(self, command_line):
         steamapps_paths = get_steamapps_paths()
         for platform in ("linux", "windows"):
-            for path in steamapps_paths[platform]:
+            for path in steamapps_paths[platform] if steamapps_paths else []:
                 self._print(command_line, path)
 
     def do_shutdown(self):  # pylint: disable=arguments-differ
diff --git a/lutris/gui/widgets/utils.py b/lutris/gui/widgets/utils.py
--- a/lutris/gui/widgets/utils.py
+++ b/lutris/gui/widgets/utils.py
@@ -59,19 +59,20 @@ def get_pixbuf(image, size, fallback=None, is_installed=True):
         return pixbuf
     overlay = os.path.join(datapath.get(), "media/unavailable.png")
     transparent_pixbuf = get_overlay(overlay, size).copy()
-    pixbuf.composite(
-        transparent_pixbuf,
-        0,
-        0,
-        size[0],
-        size[1],
-        0,
-        0,
-        1,
-        1,
-        GdkPixbuf.InterpType.NEAREST,
-        100,
-    )
+    if pixbuf:
+        pixbuf.composite(
+            transparent_pixbuf,
+            0,
+            0,
+            size[0],
+            size[1],
+            0,
+            0,
+            1,
+            1,
+            GdkPixbuf.InterpType.NEAREST,
+            100,
+        )
     return transparent_pixbuf
 
 


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
new file mode 100644
--- /dev/null
+++ b/tests/test_cli.py
@@ -0,0 +1,20 @@
+from unittest import TestCase
+
+import gi
+
+gi.require_version('Gtk', '3.0')
+
+
+from lutris.gui.application import Application
+
+
+class TestPrint(TestCase):
+
+    def setUp(self):
+        self.lutris_application = Application()
+
+    def test_print_steam_list(self):
+        self.lutris_application.print_steam_list('cmd')
+
+    def test_print_steam_folders(self):
+        self.lutris_application.print_steam_folders('cmd')