[pitivi/1.0] flatpak: Pass only the flatpakrepo URL for remotes



commit 5568d46cd0d776befd8fd7d690d1270b7cfb20c8
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Mon Apr 16 21:21:43 2018 +0200

    flatpak: Pass only the flatpakrepo URL for remotes
    
    Clarifies a bit what the add() method does.

 build/flatpak/pitivi-flatpak | 76 +++++++++++++++++++-------------------------
 1 file changed, 33 insertions(+), 43 deletions(-)
---
diff --git a/build/flatpak/pitivi-flatpak b/build/flatpak/pitivi-flatpak
index 593a260f..d164645a 100755
--- a/build/flatpak/pitivi-flatpak
+++ b/build/flatpak/pitivi-flatpak
@@ -190,14 +190,16 @@ class FlatpakRepos(FlatpakObject):
 
     def __init__(self, user=True):
         FlatpakObject.__init__(self, user=user)
+        # The remote repositories, name -> FlatpakRepo
         self.repos = {}
         self.update()
 
     def update(self):
         self.repos = {}
-        repo_defs = [rd for rd in
-                     self.flatpak("remote-list", "-d").split("\n") if rd]
-        for repo in repo_defs:
+        remotes = [row
+                   for row in self.flatpak("remote-list", "-d").split("\n")
+                   if row]
+        for repo in remotes:
             for components in [repo.split(" "), repo.split("\t")]:
                 if len(components) == 1:
                     components = repo.split("\t")
@@ -223,65 +225,55 @@ class FlatpakRepos(FlatpakObject):
                 Console.message("No valid URI found for: %s", repo)
                 continue
 
-            self.repos[name] = FlatpakRepo(name, desc, url, repos=self)
+            self.repos[name] = FlatpakRepo(name, url, desc, repos=self)
 
         self.packages = FlatpakPackages(self)
 
-    def add(self, repo, override=True):
+    def add(self, name, flatpakrepo_url, override=True):
+        flatpakrepo = tempfile.NamedTemporaryFile(mode="w")
+        urlretrieve(flatpakrepo_url, flatpakrepo.name)
+        repo = configparser.ConfigParser()
+        repo.read(flatpakrepo.name)
+        url = repo["Flatpak Repo"]["Url"]
+
         same_name = None
-        for name, tmprepo in self.repos.items():
-            if repo.url == tmprepo.url:
+        for tmpname, tmprepo in self.repos.items():
+            if url == tmprepo.url:
                 return tmprepo
-            if repo.name == name:
+            if name == tmpname:
                 same_name = tmprepo
 
         if same_name:
+            Console.message("Flatpak remote with the same name already exists: %s", same_name)
             if not override:
+                Console.message("%sNote the URL is %s, not %s%s",
+                                Colors.WARNING, same_name.url, url, Colors.ENDC)
                 return None
 
-            self.flatpak("remote-modify", repo.name, "--url=" + repo.url,
+            Console.message("The URL is different. Overriding.")
+            self.flatpak("remote-modify", name, "--url=" + url,
                          comment="Setting repo %s URL from %s to %s"
-                         % (repo.name, same_name.url, repo.url))
-            same_name.url = repo.url
+                         % (name, same_name.url, url))
+            same_name.url = url
             return same_name
 
-        self.flatpak("remote-add", "--if-not-exists", repo.name, "--from",
-                     repo.repo_file.name,
-                     comment="Adding repo %s" % repo.name)
-        repo.repos = self
-        return repo
+        self.flatpak("remote-add", "--if-not-exists", name,
+                     "--from", flatpakrepo_url,
+                     comment="Adding repo %s" % name)
+        self.update()
+        return self.repos[name]
 
 
 class FlatpakRepo(FlatpakObject):  # pylint: disable=too-few-public-methods
 
-    def __init__(self, name, desc=None, url=None,  # pylint: disable=too-many-arguments
-                 repo_file=None, user=True, repos=None):
+    def __init__(self, name, url, desc=None, user=True, repos=None):  # pylint: disable=too-many-arguments
         FlatpakObject.__init__(self, user=user)
 
         self.name = name
-        self.url = url
+        assert name
         self.desc = desc
-        self.repo_file_name = repo_file
-        self._repo_file = None
         self.repos = repos
-        assert name
-        if repo_file and not url:
-            repo = configparser.ConfigParser()
-            repo.read(self.repo_file.name)
-            self.url = repo["Flatpak Repo"]["Url"]
-        else:
-            assert url
-
-    @property
-    def repo_file(self):
-        if self._repo_file:
-            return self._repo_file
-
-        assert self.repo_file_name
-        self._repo_file = tempfile.NamedTemporaryFile(mode="w")
-        urlretrieve(self.repo_file_name, self._repo_file.name)
-
-        return self._repo_file
+        self.url = url
 
 
 class FlatpakPackage(FlatpakObject):
@@ -410,10 +402,8 @@ class PitiviFlatpak:  # pylint: disable=too-many-instance-attributes
         self.check_flatpak()
 
         repos = FlatpakRepos()
-        self.sdk_repo = repos.add(
-            FlatpakRepo("gnome",
-                        url="https://dl.flathub.org/repo/";,
-                        repo_file="https://dl.flathub.org/repo/flathub.flatpakrepo";))
+        self.sdk_repo = repos.add("gnome",
+                                  "https://dl.flathub.org/repo/flathub.flatpakrepo";)
 
         sdk_branch = SDK_BRANCH[self.branch]
         self.runtime = FlatpakPackage(


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]