--- /dev/null
+#!/usr/bin/python -tt
+# vim: ai ts=4 sts=4 et sw=4
+#
+# Copyright (c) 2012 Intel, Inc.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; version 2 of the License
+#
+# 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., 59
+# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+"""Implementation of subcmd: import
+"""
+
+import os
+import time
+import tempfile
+import glob
+import shutil
+
+import msger
+import runner
+import utils
+from conf import configmgr
+import git
+import errors
+
+USER = configmgr.get('user', 'build')
+TMPDIR = configmgr.get('tmpdir')
+COMM_NAME = configmgr.get('commit_name', 'import')
+COMM_EMAIL = configmgr.get('commit_email', 'import')
+
+def do(opts, args):
+
+ workdir = os.getcwd()
+ tmpdir = '%s/%s' % (TMPDIR, USER)
+
+ import pdb;pdb.set_trace()
+ if len(args) != 1:
+ msger.error('missning argument, please reference gbs import-orig --help.')
+ else:
+ tarball = args[0]
+
+ try:
+ repo = git.Git('.')
+ except errors.GitInvalid:
+ msger.error("No git repository found.")
+
+ tardir = tempfile.mkdtemp(prefix='%s/' % (tmpdir))
+ msger.info('unpack upstream tar ball ...')
+ upstream = utils.UpstreamTarball(tarball)
+ (pkgname, pkgversion) = upstream.guess_version() or ('', '')
+ upstream.unpack(tardir)
+
+ tag = repo.version_to_tag("%(version)s", pkgversion)
+ msg = "Upstream version %s" % (pkgversion)
+
+ if opts.upstream_branch:
+ upstream_branch = opts.upstream_branch
+ else:
+ upstream_branch = 'upstream'
+ if not repo.has_branch(upstream_branch):
+ msger.error('upstream branch not exist, please create one manually')
+
+ os.chdir(repo.path)
+ repo.clean_branch(upstream_branch)
+ repo.checkout_branch(upstream_branch)
+ if repo.find_tag(tag):
+ msger.error('dont need to import, already in version %s' % tag)
+
+ msger.info('submit the upstream data')
+ commit = repo.commit_dir(upstream.unpacked, msg,
+ author = {'name':COMM_NAME,
+ 'email':COMM_EMAIL
+ }
+ )
+ if commit:
+ msger.info('create tag named: %s' % tag)
+ repo.create_tag(tag, msg, commit)
+
+ repo.checkout_branch('master')
+
+ if not opts.no_merge:
+ try:
+ msger.info('merge imported upstream branch to master branch')
+ repo.merge(tag)
+ except:
+ msger.error('Merge failed, please resolve')
+
+ msger.info('done.')
"""does the repository contain any uncommitted modifications"""
gitsts = self.status()
- if 'M ' in gitsts or ' M' in gitsts:
+ if 'M ' in gitsts or ' M' in gitsts or \
+ 'A ' in gitsts or ' A ' in gitsts:
return False
else:
return True
else:
return (br in self.get_branches()[1])
+ def checkout_branch(self, br):
+ """checkout repository branch 'br'
+ """
+ options = [br]
+ with Workdir(self.path):
+ self._exec_git('checkout', options)
+
+ def clean_branch(self, br):
+ """Clean up repository branch 'br'
+ """
+
+ options = ['-dfx']
+ with Workdir(self.path):
+ self.checkout_branch(br)
+ runner.quiet('rm .git/index')
+ self._exec_git('clean', options)
+
def commit_dir(self, unpack_dir, msg, branch = 'master', other_parents=None,
author={}, committer={}, create_missing_branch=False):
options = ['.', '-f']
self._exec_git("add", options)
+ import pdb;pdb.set_trace()
+ if self.is_clean():
+ return None
+
options = ['--quiet','-a', '-m %s' % msg,]
self._exec_git("commit", options)
import os
import glob
import platform
+import re
import msger
import runner
unpackArchive = UnpackTarArchive(self.path, dir, filters)
except gbpc.CommandExecFailed:
raise GbpError
+
+ def guess_version(self, extra_regex=r''):
+ """
+ Guess the package name and version from the filename of an upstream
+ archive.
+ """
+ known_compressions = [ args[1][-1] for args in compressor_opts.items() ]
+
+ version_chars = r'[a-zA-Z\d\.\~\-\:\+]'
+ extensions = r'\.tar\.(%s)' % "|".join(known_compressions)
+
+ version_filters = map ( lambda x: x % (version_chars, extensions),
+ ( # Tizen package_<version>-tizen.tar.gz:
+ r'^(?P<package>[a-z\d\.\+\-]+)-(?P<version>%s+)-tizen%s',
+ # Upstream package-<version>.tar.gz:
+ r'^(?P<package>[a-zA-Z\d\.\+\-]+)-(?P<version>[0-9]%s*)%s'))
+ if extra_regex:
+ version_filters = extra_regex + version_filters
+
+ for filter in version_filters:
+ m = re.match(filter, os.path.basename(self.path))
+ if m:
+ return (m.group('package'), m.group('version'))
+
from gitbuildsys import cmd_import as cmd
cmd.do(opts, args)
+ @cmdln.alias("import-orig")
+ @cmdln.option('--author-name',
+ default=None,
+ dest='author_name',
+ help='author name of git commit')
+ @cmdln.option('--author-email',
+ default=None,
+ dest='author_email',
+ help='author email of git commit')
+ @cmdln.option('--upstream_branch',
+ default=None,
+ dest='upstream_branch',
+ help='specify upstream branch for new version of package')
+ @cmdln.option('--no-merge',
+ action="store_true",
+ default=False,
+ dest='no_merge',
+ help='Dont merge new upstream branch to master branch, please user merge it manually')
+
+ def do_import_orig(self, subcmd, opts, *args):
+ """${cmd_name}: Import tar ball to upstream branch
+
+ Usage:
+ gbs import-orig [options] original-tar-ball
+
+
+ Examples:
+ $ gbs import original-tar-ball
+ ${cmd_option_list}
+ """
+
+ from gitbuildsys import cmd_import_orig as cmd
+ cmd.do(opts, args)
+
+
@cmdln.alias("cfg")
@cmdln.option('-s', '--section',