From ef7e91a969637ce20c341f360a27ee545aec2e93 Mon Sep 17 00:00:00 2001 From: hasan wan Date: Tue, 5 Jun 2012 14:11:30 +0800 Subject: [PATCH] enable repo authenticate --- gitbuildsys/cmd_build.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++- gitbuildsys/conf.py | 17 ++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/gitbuildsys/cmd_build.py b/gitbuildsys/cmd_build.py index 9d64c49..cf81941 100644 --- a/gitbuildsys/cmd_build.py +++ b/gitbuildsys/cmd_build.py @@ -23,6 +23,7 @@ import os import glob import subprocess import urlparse +import re import msger import utils @@ -147,6 +148,57 @@ def setup_qemu_emulator(): return qemu_emulator +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): @@ -193,9 +245,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.') @@ -252,7 +309,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. msger.debug("running command %s" % cmd) diff --git a/gitbuildsys/conf.py b/gitbuildsys/conf.py index aa74866..c6ea41d 100644 --- a/gitbuildsys/conf.py +++ b/gitbuildsys/conf.py @@ -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' -- 2.7.4