From: Zhang Qiang Date: Tue, 31 Jul 2012 08:32:29 +0000 (+0800) Subject: Create two functions for common code in export build and remotebuild modules X-Git-Tag: 0.9~26 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=57145bc1db0ff14e3e54d8a7daa15ae50711c2d3;p=tools%2Fgbs.git Create two functions for common code in export build and remotebuild modules --- diff --git a/gitbuildsys/cmd_build.py b/gitbuildsys/cmd_build.py index 511d189..1065a71 100644 --- a/gitbuildsys/cmd_build.py +++ b/gitbuildsys/cmd_build.py @@ -246,35 +246,11 @@ def do(opts, args): try: repo = RpmGitRepository(workdir) - if opts.commit: - repo.rev_parse(opts.commit) - is_clean, out = repo.is_clean() - status = repo.status() - untracked_files = status['??'] - uncommitted_files = [] - for stat in status: - if stat == '??': - continue - uncommitted_files.extend(status[stat]) - if not is_clean and not opts.include_all: - if untracked_files: - msger.warning('the following untracked files would NOT be '\ - 'included:\n %s' % '\n '.join(untracked_files)) - if uncommitted_files: - msger.warning('the following uncommitted changes would NOT be '\ - 'included:\n %s' % '\n '.join(uncommitted_files)) - msger.warning('you can specify \'--include-all\' option to '\ - 'include these uncommitted and untracked files.') - if opts.include_all: - if untracked_files: - msger.info('the following untracked files would be included' \ - ':\n %s' % '\n '.join(untracked_files)) - if uncommitted_files: - msger.info('the following uncommitted changes would be included'\ - ':\n %s' % '\n '.join(uncommitted_files)) except GitRepositoryError, err: msger.error(str(err)) + if not opts.incremental: + utils.gitStatusChecker(repo, opts) workdir = repo.path hostarch = get_hostarch() diff --git a/gitbuildsys/cmd_export.py b/gitbuildsys/cmd_export.py index 2f40435..112fd7f 100644 --- a/gitbuildsys/cmd_export.py +++ b/gitbuildsys/cmd_export.py @@ -63,35 +63,10 @@ def do(opts, args): try: repo = RpmGitRepository(workdir) - if opts.commit: - repo.rev_parse(opts.commit) - is_clean, out = repo.is_clean() - status = repo.status() - untracked_files = status['??'] - uncommitted_files = [] - for stat in status: - if stat == '??': - continue - uncommitted_files.extend(status[stat]) - if not is_clean and not opts.include_all: - if untracked_files: - msger.warning('the following untracked files would NOT be '\ - 'included:\n %s' % '\n '.join(untracked_files)) - if uncommitted_files: - msger.warning('the following uncommitted changes would NOT be '\ - 'included:\n %s' % '\n '.join(uncommitted_files)) - msger.warning('you can specify \'--include-all\' option to '\ - 'include these uncommitted and untracked files.') - if opts.include_all: - if untracked_files: - msger.info('the following untracked files would be included' \ - ':\n %s' % '\n '.join(untracked_files)) - if uncommitted_files: - msger.info('the following uncommitted changes would be included'\ - ':\n %s' % '\n '.join(uncommitted_files)) except GitRepositoryError, err: msger.error(str(err)) + utils.gitStatusChecker(repo, opts) workdir = repo.path if not os.path.exists("%s/packaging" % workdir): diff --git a/gitbuildsys/cmd_remotebuild.py b/gitbuildsys/cmd_remotebuild.py index 3ae024d..b53a9b1 100644 --- a/gitbuildsys/cmd_remotebuild.py +++ b/gitbuildsys/cmd_remotebuild.py @@ -32,7 +32,7 @@ import utils import gbp.rpm from gbp.scripts.buildpackage_rpm import main as gbp_build -from gbp.git import repository, GitRepositoryError +from gbp.rpm.git import GitRepositoryError, RpmGitRepository from gbp.errors import GbpError OSCRC_TEMPLATE = """[general] @@ -80,37 +80,12 @@ def do(opts, args): '--include-all') try: - repo = repository.GitRepository(workdir) - if opts.commit: - repo.rev_parse(opts.commit) - is_clean, out = repo.is_clean() - status = repo.status() - untracked_files = status['??'] - uncommitted_files = [] - for stat in status: - if stat == '??': - continue - uncommitted_files.extend(status[stat]) - if not is_clean and not opts.include_all and not \ - (opts.buildlog or opts.status): - if untracked_files: - msger.warning('the following untracked files would NOT be '\ - 'included:\n %s' % '\n '.join(untracked_files)) - if uncommitted_files: - msger.warning('the following uncommitted changes would NOT be '\ - 'included:\n %s' % '\n '.join(uncommitted_files)) - msger.warning('you can specify \'--include-all\' option to '\ - 'include these uncommitted and untracked files.') - if opts.include_all and not (opts.buildlog or opts.status): - if untracked_files: - msger.info('the following untracked files would be included' \ - ':\n %s' % '\n '.join(untracked_files)) - if uncommitted_files: - msger.info('the following uncommitted changes would be included'\ - ':\n %s' % '\n '.join(uncommitted_files)) - except repository.GitRepositoryError, err: + repo = RpmGitRepository(workdir) + except GitRepositoryError, err: msger.error(str(err)) + if not (opts.buildlog or opts.status): + utils.gitStatusChecker(repo, opts) workdir = repo.path tmpdir = os.path.join(workdir, 'packaging') diff --git a/gitbuildsys/utils.py b/gitbuildsys/utils.py index 092b79b..92e73ec 100644 --- a/gitbuildsys/utils.py +++ b/gitbuildsys/utils.py @@ -31,6 +31,8 @@ except ImportError: import errors import msger +from gbp.rpm.git import GitRepositoryError +from gbp.errors import GbpError class Workdir(object): def __init__(self, path): @@ -295,3 +297,36 @@ class RepoParser(object): return self.repourls[arch] + self.localrepos return None + +def gitStatusChecker(git, opts): + try: + if opts.commit: + git.rev_parse(opts.commit) + is_clean, out = git.is_clean() + status = git.status() + except (GbpError, GitRepositoryError), err: + msger.error(str(err)) + + untracked_files = status['??'] + uncommitted_files = [] + for stat in status: + if stat == '??': + continue + uncommitted_files.extend(status[stat]) + + if not is_clean and not opts.include_all: + if untracked_files: + msger.warning('the following untracked files would NOT be '\ + 'included:\n %s' % '\n '.join(untracked_files)) + if uncommitted_files: + msger.warning('the following uncommitted changes would NOT be '\ + 'included:\n %s' % '\n '.join(uncommitted_files)) + msger.warning('you can specify \'--include-all\' option to '\ + 'include these uncommitted and untracked files.') + if not is_clean and opts.include_all: + if untracked_files: + msger.info('the following untracked files would be included' \ + ':\n %s' % '\n '.join(untracked_files)) + if uncommitted_files: + msger.info('the following uncommitted changes would be included'\ + ':\n %s' % '\n '.join(uncommitted_files))