Adding linked build packages to test-trigger info. 76/137476/3
authorhyokeun <hyokeun.jeon@samsung.com>
Thu, 6 Jul 2017 05:55:31 +0000 (14:55 +0900)
committerhyokeun <hyokeun.jeon@samsung.com>
Thu, 6 Jul 2017 06:07:21 +0000 (15:07 +0900)
1. Read manifest xml file if exist.
2. Add 'linked_build_packages': ['blah', 'blah'] into .prerelease.description file.

Change-Id: I6e251bd632bd95fc824f35345e2ae2e275ecaf44

job_test_trigger_info_update.py

index 9cb51fc..ddbd572 100644 (file)
@@ -17,6 +17,7 @@ import os
 import sys
 import json
 import re
+import requests
 
 from common.buildtrigger import trigger_info
 from common.git import Git, clone_gitproject
@@ -24,12 +25,72 @@ from common.prerelease import is_prerelease_project
 
 from gbp.git.args import GitArgs
 
+import xml.etree.cElementTree as ElementTree
+
 GIT_FILE_NAME = 'prerelease.description'
 
 class LocalError(Exception):
     """Local error exception."""
     pass
 
+def get_manifest_filelists_snapshot(profile, request_url, timeout=5, group=None):
+        """ get manifest filelists from snapshot"""
+        #p = re.compile(r'alt=\"\[(TXT|DIR|   )]*\]\".*<a href=\"(.*)\">')
+        p = re.compile(r'.*<a href=\"(.*)\">')
+
+        if not request_url:
+            return {}
+        print request_url
+        # get data from url
+        for loop in range(10):
+            try:
+                f = requests.get(request_url,
+                                 auth=(profile['snapshot_username'],
+                                       profile['snapshot_password']),
+                                 timeout=timeout)
+                if f.status_code == 200:
+                    break
+            except requests.exceptions.Timeout as e:
+                print(e)
+                continue
+            except requests.exceptions.ConnectionError as e:
+                print(e)
+                continue
+            except Exception as e:
+                print(e)
+                raise Exception('exception from get manifest filelists')
+
+        results = {}
+        exclude_pkgs = []
+        found_links = p.findall(f.text)
+        for link in found_links:
+            if link == '../':
+                continue
+            if not link.endswith('.xml'):
+                continue
+            manifest_url = os.path.join(request_url, link)
+            f = requests.get(manifest_url,
+                             auth=(profile['snapshot_username'],
+                                   profile['snapshot_password']),
+                             timeout=timeout)
+            try:
+                tree = ElementTree.fromstring(f.text)
+            except ElementTree.ParseError:
+                raise ElementTree.ParseError
+            for result in tree.findall('project'):
+                if '_preloadapp.xml' in link:
+                    exclude_pkgs.append(''.join(result.get('path')))
+                else:
+                    results[''.join(result.get('path'))] = result.get('revision')
+
+        if group == 'abs':
+            preloadapp_pkgs = {}
+            for app in exclude_pkgs:
+                preloadapp_pkgs[app] = results[app]
+            return preloadapp_pkgs
+
+        return results
+
 def main():
     """The main body"""
 
@@ -41,8 +102,6 @@ def main():
                          % (project))
     print '\n\"Title\": \"%s\"' % project
 
-    saved_info = json.dumps(saved_info)
-
     if not is_prerelease_project(project):
         print '%s is not prerelease project' % project
         return 1
@@ -54,6 +113,21 @@ def main():
     except Exception as err:
         raise LocalError('Cannot determine target branch (%s)' % err)
 
+    # Append linked built packages
+    manifest_list = []
+    try:
+        manifest_list = get_manifest_filelists_snapshot( \
+                            {'snapshot_username': '', \
+                             'snapshot_password': ''}, \
+                            os.path.join(saved_info.get('download_url'), 'builddata/manifest'), \
+                            timeout=5, group=None).keys()
+    except Exception as err:
+        print repr(err)
+    for t in saved_info.get('projects'):
+        if t in manifest_list:
+            manifest_list.remove(t)
+    saved_info['linked_build_projects'] = manifest_list
+
     #TODO: tizen_{profile}_tpk branch hack
     if branch.endswith('_tpk'):
         branch = branch.split('_%s_tpk' % target_project.split(':')[-1].lower())[0]
@@ -67,6 +141,8 @@ def main():
         print 'Error cloning %s' % os.getenv('TEST_TRIGGER_GIT_PATH')
         return 2
 
+    saved_info = json.dumps(saved_info)
+
     mygit = Git(prjdir)
     if mygit.has_branch('origin/' + branch, remote = True):
         mygit.checkout(branch)