Add OBS functions for meta change 90/213490/1
authorHyokeun Jeon <hyokeun.jeon@samsung.com>
Fri, 6 Sep 2019 01:41:19 +0000 (10:41 +0900)
committerHyokeun Jeon <hyokeun.jeon@samsung.com>
Fri, 6 Sep 2019 01:41:19 +0000 (10:41 +0900)
Change-Id: Idaca67b82755461f95bf55b1c9a06c289c8e074e

common/buildservice.py

index 868d18a..a304a2b 100755 (executable)
@@ -1495,3 +1495,58 @@ class BuildService(OSC):
                     path_project.append(element.get('project'))
         return list(set(path_project))
 
+    def add_repositoris(self, prj, repo_arch_data):
+        """
+        add repository - architecture to a project
+        repo_arch_data = {'repository': ['arch1', 'arch2', ...], ...}
+        """
+
+        path = core.quote_plus(prj),
+        kind = 'prj'
+        data = core.meta_exists(metatype=kind,
+                                path_args=path,
+                                template_args=None,
+                                create_new=False)
+        if not data:
+            return
+
+        root = ElementTree.fromstring(''.join(data))
+        for repo in repo_arch_data:
+            repo_elem = ElementTree.Element('repository', name=repo)
+            for arch in repo_arch_data[repo]:
+                arch_elem = ElementTree.Element('arch')
+                arch_elem.text = arch
+                repo_elem.insert(100, arch_elem)
+            root.insert(100, repo_elem)
+
+        core.edit_meta(metatype=kind,
+                       path_args=path,
+                       data=ElementTree.tostring(root))
+
+    def add_path_project(self, prj, base_project):
+        """
+        add path project to each repository
+        """
+
+        base_repo_list = self.get_repositories(base_project)
+
+        path = core.quote_plus(prj),
+        kind = 'prj'
+        data = core.meta_exists(metatype=kind,
+                                path_args=path,
+                                template_args=None,
+                                create_new=False)
+        if not data:
+            return
+
+        root = ElementTree.fromstring(''.join(data))
+
+        for repo in root.findall('repository'):
+            for r in base_repo_list:
+                path_elem = ElementTree.Element('path', project=base_project, repository=r)
+                repo.insert(100, path_elem)
+
+        core.edit_meta(metatype=kind,
+                       path_args=path,
+                       data=ElementTree.tostring(root))
+