Implement repa update 73/140173/3
authorYonghee Han <onstudy@samsung.com>
Mon, 24 Jul 2017 05:30:25 +0000 (14:30 +0900)
committerYonghee Han <onstudy@samsung.com>
Mon, 24 Jul 2017 05:55:32 +0000 (14:55 +0900)
    repa update can change the reference project in arget project.

    repa update should help RE to mantain the target projects.
    ex) repa update <submission> --refprj <reference project>

Change-Id: Icd42b15d8da636bcd7353088e815377d31d3cc6f

packaging/repa.spec
repa.1
repa/main.py
repa/update.py [new file with mode: 0644]
setup.py

index 35f79e03219ca3b2b926fc371b8013258af60777..63cf1e51f2fae174ca91a8e2b4f5fe94e5705e61 100644 (file)
@@ -1,5 +1,5 @@
 Name:           repa
-Version:        0.5
+Version:        0.6
 Summary:        Release Engineering Process Assistant
 %if 0%{?opensuse_bs}
 Release:        1.<CI_CNT>.<B_CNT>
diff --git a/repa.1 b/repa.1
index bbed6eb87aec3e8595c3f61e347b0eaea04d4bf7..4a1a42af8032d5a92f4274706cf19a6a40ec73b0 100644 (file)
--- a/repa.1
+++ b/repa.1
@@ -58,6 +58,9 @@ Submission group is a temporary group of submissions, created for testing purpos
 .RS 2
 11. \fBremove\fR - remove submission
 .RE
+.RS 2
+12. \fBupdate\fR - update submission
+.RE
 
 .\" ===========================================================================
 .\" Global options
@@ -533,6 +536,30 @@ Provide a comment with the explanation of a reason for remove. This is mandatory
 Run editor to edit comment. Editor is taken from EDITOR environment variable.
 .RE
 
+.\"
+.\" The "update" command description
+.\"
+.SS \fBupdate\fR <submission> [options]
+
+.RS 2
+Update submission
+
+.\"
+.\" The "remove" command's options
+.\"
+.RS 2
+\fBOPTIONS\fR
+.RS 2
+.B \-h, \-\-help
+.RS 2
+Print short help text about the "update" command and exit.
+.RE
+
+.PP
+.B \-r \-\-refprj COMMENT
+.RS 2
+Provide a update with the reference project. This is mandatory option.
+.RE
 
 .SH CONFIGURATION FILE
 
@@ -548,7 +575,7 @@ Example:
 [general]
 .RE
 .RS 2
-apiurl = https://api.tizen.org
+apiurl = https://build.tizen.org
 .RE
 .RS 2
 apiuser = your_user_name
@@ -557,7 +584,7 @@ apiuser = your_user_name
 apipasswd = your_password
 .RE
 .RS 2
-jenkins_url = https://build.tizen.org/robot
+jenkins_url = https://robot.tizen.org
 .RE
 .RS 2
 jenkins_user = your_jenkins_user_name
index 37f62db9dce16df73ef7aa440e55e44cc6cdc86f..68bfac839ac0fc42fe7ec90a7070368904fe428c 100755 (executable)
@@ -57,7 +57,7 @@ def parse_args(argv):
         ArgumentParser(prog='repa',
                        description='Release Engineering Process Assistant')
     parser.add_argument('--version', action='version',
-                        version='%(prog)s version 0.5')
+                        version='%(prog)s version 0.6')
     parser.add_argument('-s', '--section', default='general',
                         help='config section to use')
     parser.add_argument('-p', '--project', help='target project',
diff --git a/repa/update.py b/repa/update.py
new file mode 100644 (file)
index 0000000..fbf6f78
--- /dev/null
@@ -0,0 +1,105 @@
+#!/usr/bin/env python
+#
+# This file is part of REPA: Release Engineering Process Assistant.
+#
+# Copyright (C) 2013 Intel Corporation
+#
+# REPA is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# version 2 as published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+"""
+REPA: Release Engineering Process Assistant.
+
+Copyright (C) Intel Corporation 2013
+Licence: GPL version 2
+Author: Ed Bartosh <eduard.bartosh@intel.com>
+
+List module.
+Get list of submissions.
+"""
+
+import sys
+import json
+from xml.etree import cElementTree as ET
+
+from repa.common import get_project_by_name
+from repa.obs import OBS
+
+from repa.main import sub_main
+
+def set_update_reference_project(obs, prj, ref_target_prj=None):
+    """ Set update reference for project """
+
+    if ref_target_prj is None:
+       raise RepaException("Update reference is not supported. ")
+
+    meta = obs.get_meta(prj)
+    # repalace link project 
+    xml_meta = ET.fromstring(''.join(meta))
+    for link_project in xml_meta.findall('link'):
+        link_project.set('project', ref_target_prj)
+    # replace repository path
+    for repo_element in xml_meta.findall('repository'):
+        for element in repo_element.findall('path'):
+            element.set('project',ref_target_prj)
+    # replace description
+    description = json.loads(xml_meta.find('description').text)
+    if description:
+        description['ref_obs_target_prj'] = ref_target_prj
+        xml_meta.find('description').text = json.dumps(description)
+    obs.set_meta(ET.tostring(xml_meta), prj)
+
+def update(obs, name, target, ref_target_prj):
+    """update meta of information about submission"""
+    prj, meta, build_results = get_project_by_name(obs, name, target)
+
+    if meta['ref_obs_target_prj']:
+        print 'old_ref: %s new_ref: %s' %(meta['ref_obs_target_prj'],
+                                           ref_target_prj)
+    else:
+        raise RepaException("update is not supported. "
+                                "ref_obs_target_prj values: %s" % \
+                                (ref_obs_target_prj))
+
+    if not obs.exists(ref_target_prj):
+        raise RepaException("update is not supported. "
+                            "ref_target_prj %s is not exists" % \
+                            (ref_target_prj))
+    set_update_reference_project(obs, prj, ref_target_prj)
+
+class Update(object):
+    """Subcommand: Update meta of information about submission."""
+
+    name = 'update'
+    description = 'Update meta of Information about submission'
+    help = description
+
+    @staticmethod
+    def add_arguments(parser, config):
+        """
+        Add arguments to the parser. Called from [sub_]main.
+        Set defaults for arguments from config.
+        """
+        parser.add_argument('submission', help='submission or group')
+        parser.add_argument('-r', '--refprj',
+                            help='Update reference project in project')
+    @staticmethod
+    def run(argv):
+        """Command line entry point. Called from [sub_]main"""
+        obs = OBS(argv.apiurl, argv.apiuser, argv.apipasswd)
+        return update(obs, argv.submission, argv.project, argv.refprj)
+
+
+if __name__ == '__main__':
+    sys.exit(sub_main(sys.argv[1:], Update()))
index 53515aaf8fedc6b751dd2e5df2eb1a55b95f6b83..5f7f4e9af3ee5206fca17d63db561adc18e011ad 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -31,7 +31,7 @@ import os
 from setuptools import setup
 
 setup(name="repa",
-      version='0.5',
+      version='0.6',
       author='Ed Bartosh',
       author_email='eduard.bartosh@intel.com',
       packages=['repa'],
@@ -52,5 +52,6 @@ setup(name="repa",
                               'rebuild = repa.rebuild:Rebuild',
                               'lock = repa.lock:Lock',
                               'unlock = repa.unlock:Unlock',
+                              'update = repa.update:Update',
                               'remove = repa.remove:Remove']
       })