Add submit text template mechanism 73/13273/6
authorJohannes Quast <johannes.quast@intel.com>
Mon, 2 Dec 2013 13:47:39 +0000 (14:47 +0100)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Fri, 6 Dec 2013 03:57:25 +0000 (19:57 -0800)
The text template used by gbs submit can be changed
using a special gbs submit template file.

Fixes: DEVT-126
Change-Id: Ic9ba27698980ae229431fbbd8c5152297287add5
Signed-off-by: Johannes Quast <johannes.quast@intel.com>
gitbuildsys/cmd_submit.py

index 9308d68423e83c8447aa183d41198139ffe00ea7..89ab53066fc6b7e7dc2ce585587dd986d2066676 100644 (file)
@@ -28,6 +28,24 @@ from gitbuildsys.log import LOGGER as log
 
 from gbp.rpm.git import GitRepositoryError, RpmGitRepository
 
+def _lookup_submit_template():
+    """
+    Look for submit templates in current project,
+    user and system settings location
+    """
+
+    lookup_paths = (
+      '.gbs/templates/submit_message',
+      '~/.gbs/templates/submit_message',
+      '/etc/gbs/templates/submit_message')
+
+
+    for path in lookup_paths:
+        abs_path = os.path.abspath(os.path.expanduser(path))
+        if os.path.exists(abs_path):
+            return abs_path
+
+    return None
 
 
 def get_message():
@@ -38,6 +56,14 @@ def get_message():
 # Please enter the message for your tag. Lines starting with '#'
 # will be ignored, and an empty message aborts the submission.
 #'''
+
+    #check for additional submit template
+    template_path = _lookup_submit_template()
+    if template_path:
+        with open(template_path, 'r') as template_file:
+            submit_template = template_file.read()
+            prompt = submit_template
+
     raw = edit(prompt)
     useful = [i for i in raw.splitlines() if not i.startswith('#') ]
     return os.linesep.join(useful).strip()