#1 Hide modified repositories from the output of 'fedora-third-party list'
Merged 2 years ago by otaylor. Opened 2 years ago by otaylor.
otaylor/fedora-third-party hide-modified-repositories  into  main

file modified
+8 -2
@@ -66,7 +66,7 @@ 

  repositories are enabled, enable DNF repositories and create Flatpak

  remotes.

  

- ### list [*--csv* | *--columns=col1,col2*]

+ ### list [*-a* | *--all* | *--csv* | *--columns=col1,col2*]

  

  Prints the list of currently configured repositories. By default, the list

  will be pretty-printed in tabular form with headers. The *--csv* option can
@@ -82,6 +82,10 @@ 

  the current columns, you can assume that the values will

  not be quoted.

  

+ Flatpak repositories with the `keep_unfiltered` option set are hidden by

+ default from the list if there is a matching remote without a filter.

+ *a* or *--all* can be passed to show all repositories.

+ 

  ## CONFIGURATION

  

  Repositories are configured by files in `/usr/lib/fedora-third-party/conf.d`.
@@ -102,12 +106,14 @@ 

  [somerepo]

  # The Flatpak remote must match and also be 'somerepo'

  type=flatpak

+ 

  # Path to a flatpakrepo file defining the remote. If it's a relative

  # path, it will be interpreted relative to the directory where the

  # config file is.

  flatpakrepo=somerepo.flatpakrepo

  # If present, 'fedora-third-party disable' will leave this repository

- # untouched if it has been modified to not have a filter.

+ # untouched if it has been modified to not have a filter, and it will

+ # also be hidden from the output of 'fedora-third-party list'

  keep_unfiltered=yes

  ```

  

file modified
+8 -2
@@ -81,20 +81,26 @@ 

  

  

  @cli.command()

+ @click.option("-a", "--all", is_flag=True,

+               help="Show repositories even if they are replaced by a system repository")

  @click.option("--csv", is_flag=True,

                help="Print output in csv form")

  @click.option("--columns",

                help="Comma separated list of columns [name,type]",

                default="name,type")

  @pass_config

- def list(cfg: config.Config, csv: bool, columns: str):

+ def list(cfg: config.Config, all: bool, csv: bool, columns: str):

      """List currently configured repositories"""

  

      table = Table()

      table.add_column("name", "Name", "name")

      table.add_column("type", "Type", "type")

  

-     repositories = sorted(cfg.list_repositories(), key=lambda x: x.name)

+     repositories = cfg.list_repositories()

+     if not all:

+         repositories = [r for r in cfg.list_repositories() if not r.is_hidden()]

+ 

+     repositories = sorted(repositories, key=lambda x: x.name)

      table.dump(repositories, csv=csv, columns=[x.strip() for x in columns.split(",")])

  

  

@@ -29,6 +29,9 @@ 

      def disable(self):

          pass

  

+     def is_hidden(self):

+         return False

+ 

      def is_seen(self):

          return self.cfg.is_repository_seen(self)

  
@@ -81,6 +84,17 @@ 

          if not os.path.isabs(self.flatpakrepo):

              self.flatpakrepo = str(self.cfg.libconfdir / self.flatpakrepo)

  

+     def get_existing_remote(self):

+         return next((r for r in get_flatpak_remotes() if r.name == self.name), None)

+ 

+     def is_hidden(self):

+         if self.keep_unfiltered:

+             remote = self.get_existing_remote()

+             if remote and remote.filter is None:

+                 return True

+ 

+         return False

+ 

      def run_flatpak(self, args):

          command = ["flatpak"]

          command += args
@@ -89,8 +103,7 @@ 

          subprocess.check_call(command)

  

      def enable(self):

-         remotes = get_flatpak_remotes()

-         if not any(self.name == remote.name for remote in remotes):

+         if not self.get_existing_remote():

              self.run_flatpak(['remote-add', '--from', self.name, self.flatpakrepo])

              self.cfg.set_repository_added(self, True)

  
@@ -99,7 +112,7 @@ 

          if not self.cfg.is_repository_added(self):

              return

  

-         remote = next((r for r in get_flatpak_remotes() if r.name == self.name), None)

+         remote = self.get_existing_remote()

          if remote is None:

              return

  

file modified
+26
@@ -116,6 +116,32 @@ 

      """)

  

  

+ def test_cli_list_hide_unfiltered(setup):

+     setup.set_flatpak_remotes({

+         "flathub": "-"

+     })

+ 

+     runner = CliRunner()

+     result = runner.invoke(cli, ['list'], obj=setup.cfg)

+     assert not result.exception

+     assert result.exit_code == 0

+     assert result.output == dedent("""\

+         Name                            Type

+         ------------------------------- ----

+         rpmfusion-nonfree-nvidia-driver dnf

+     """)

+ 

+     result = runner.invoke(cli, ['list', '-a'], obj=setup.cfg)

+     assert not result.exception

+     assert result.exit_code == 0

+     assert result.output == dedent("""\

+         Name                            Type

+         ------------------------------- -------

+         flathub                         flatpak

+         rpmfusion-nonfree-nvidia-driver dnf

+     """)

+ 

+ 

  def test_cli_list_csv(setup):

      runner = CliRunner()

      result = runner.invoke(cli, ['list', '--csv'], obj=setup.cfg)

file modified
+12
@@ -108,3 +108,15 @@ 

      repository.disable()

      assert setup.calls == [

      ]

+ 

+ 

+ def test_flatpak_repository_hide_unfiltered(setup):

+     repository = make_flatpak_repository(setup)

+ 

+     repository.enable()

+ 

+     setup.set_flatpak_remotes({

+         "myrepo": "-"

+     })

+ 

+     assert repository.is_hidden()

When a Flatpak repository (such as the Fedora Flathub Selection) repository
is modified to remove the filter (typically by reinstalling a new
flatpakrepo file for the same repository), hide it from the
'fedora-third-party list' output, so that a tool like GNOME Software
will no longer display it as a third-party repository.

@mcrha - does this look like it would work to improve the handling in GNOME Software?

Pull-Request has been merged by otaylor

2 years ago

worked as expected here.