enable repo authenticate
authorhasan wan <hasan.wan@intel.com>
Sun, 3 Jun 2012 07:29:43 +0000 (15:29 +0800)
committerJF Ding <jian-feng.ding@intel.com>
Sun, 3 Jun 2012 08:56:40 +0000 (16:56 +0800)
gitbuildsys/cmd_build.py
gitbuildsys/conf.py

index 1cb8ac27aa5b0e01054f768060498e0afd6e55af..2e1a470dcc83db9ffd8b5667d487e7a8c2b4863b 100644 (file)
@@ -27,6 +27,7 @@ import glob
 import shutil
 import subprocess
 import urlparse
+import re
 
 import msger
 import runner
@@ -68,6 +69,58 @@ supportedarchs = [
             'armv7l',
           ]
 
+def get_reops_conf():
+
+    repos = set()
+    # get repo settings form build section
+    for opt in configmgr.options('build'):
+        if opt.startswith('repo'):
+            try:
+                (name, key) = opt.split('.')
+            except ValueError:
+                raise Exception("Invalid repo option: %s" % opt)
+            else:
+                if key not in ('url', 'user', 'passwdx'):
+                    raise Exception("Invalid repo option: %s" % opt)
+                repos.add(name)
+
+    # get repo settings form build section
+    repo_urls = []
+    repo_auths = []
+    for repo in repos:
+        repo_auth = ''
+        # get repo url
+        try:
+            repo_url = configmgr.get(repo + '.url', 'build')
+            repo_urls.append(repo_url)
+        except:
+            continue
+
+        try:
+            repo_server = re.match('(https?://.*?)/.*', repo_url).groups()[0]
+        except AttributeError:
+            raise Exception("Invalid repo url: %s" % opt)
+        repo_auth = 'url' + ':' + repo_server + ';'
+
+        valid = True
+        for key in ['user', 'passwdx']:
+            try:
+                value = configmgr.get(repo+'.'+ key, 'build').strip()
+            except:
+                valid = False
+                break
+            if not value:
+                valid = False
+                break
+            repo_auth = repo_auth + key + ':' + value + ';'
+
+        if not valid:
+            continue
+        repo_auth = repo_auth[:-1]
+        repo_auths.append(repo_auth)
+
+    return repo_urls, ''.join(repo_auths)
+
 def do(opts, args):
 
     workdir = os.getcwd()
@@ -115,9 +168,14 @@ def do(opts, args):
     if opts.debuginfo:
         cmd += ['--debug']
 
+    repos_urls_conf, repo_auth_conf = get_reops_conf()
+
     if opts.repositories:
         for repo in opts.repositories:
             cmd += ['--repository='+repo]
+    elif repos_urls_conf:
+        for url in repos_urls_conf:
+            cmd += ['--repository=' + url ]
     else:
         msger.error('No package repository specified.')
 
@@ -159,7 +217,7 @@ def do(opts, args):
             sucmd.pop()
         cmd = sucmd + ['-s', cmd[0], 'root', '--' ] + cmd[1:]
     else:
-        cmd = sucmd + cmd
+        cmd = sucmd + ['GBS_BUILD_REPOAUTH=%s' % repo_auth_conf ] + cmd
 
     # runner.show() can't support interactive mode, so use subprocess insterad.
     try:
index 3ec3415501c00519469fc1fc3079af6f38694d5b..794f0b7f1e46e9f0a2a35c36d0c2ae8be62c39ba 100644 (file)
@@ -167,7 +167,7 @@ class BrainConfigParser(SafeConfigParser):
             return -1
 
         SafeConfigParser.set(self, section, option, value)
-        
+
         # If the code reach here, it means the section and key are ok
         if replace_opt is None:
             o_kname = "%s.%s" % (section, option)
@@ -250,6 +250,14 @@ passwdx = $remotebuild__passwdx
 build_cmd = /usr/bin/build
 build_root= /var/tmp/build-root-gbs
 su-wrapper= sudo
+repo1.url=
+repo1.user=
+repo1.passwd=
+repo1.passwdx=
+repo2.url=
+repo2.user=
+repo2.passwd=
+repo2.passwdx=
 distconf= /usr/share/gbs/tizen-1.0.conf
 [import]
 commit_name=
@@ -377,6 +385,15 @@ commit_email=
         else:
             return False
 
+    def options(self, section='general'):
+        try:
+            return  self.cfgparser.options(section)
+        except NoSectionError:
+            if section in self.DEFAULTS:
+                return self.DEFAULTS[section]
+            else:
+                raise errors.ConfigError('invalid section %s' % (section))
+
     def get(self, opt, section='general'):
         if opt == 'passwd':
             opt = 'passwdx'