start the skeleton of "import" subcmd
authorJF Ding <jian-feng.ding@intel.com>
Tue, 13 Dec 2011 21:51:37 +0000 (13:51 -0800)
committerJF Ding <jian-feng.ding@intel.com>
Tue, 13 Dec 2011 21:51:37 +0000 (13:51 -0800)
data/import.sh [deleted file]
gitbuildsys/cmd_import.py [new file with mode: 0644]
gitbuildsys/errors.py
gitbuildsys/git.py
gitbuildsys/srcserver.py
setup.py
tools/gbs

diff --git a/data/import.sh b/data/import.sh
deleted file mode 100644 (file)
index 393cdce..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-set -x
-
-git_url=`git config remote.origin.url`
-
-prj_name=`basename $git_url`
-
-pkg=$1
-
-pkg_name=`basename $pkg`
-
-echo $prj_name
-
-#curl -i -Fjson='{"parameter": [{"name":"pkg", "value":"'$prj_name'"},{"name":"tag", "value":"'$tag'"}]}' -FSubmit=Build "http://gerrit2.bj.intel.com:8082/job/upload/build" -v
-
-curl -i -Fname=pkg.tar.bz2 -Ffile0=@"$pkg" -Fjson='{"parameter": [{"name": "pkg.tar.bz2", "file": "file0"},{"name":"pkg", "value":"'$pkg_name'"}]}' -FSubmit=Build "http://gerrit2.bj.intel.com:8082/job/uploader/build" -v
\ No newline at end of file
diff --git a/gitbuildsys/cmd_import.py b/gitbuildsys/cmd_import.py
new file mode 100644 (file)
index 0000000..70aa420
--- /dev/null
@@ -0,0 +1,54 @@
+#!/usr/bin/python -tt
+# vim: ai ts=4 sts=4 et sw=4
+#
+# Copyright (c) 2011 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
+
+# internal modules
+import msger
+import errors
+import git
+import srcserver as ss
+
+def do(opts, args):
+    if not args or len(args) != 1:
+        raise errors.Usage('Must specify the path of tarball and only one')
+
+    tarfp = args[0]
+    tarname = os.path.basename(tarfp)
+
+    gitname = os.path.basename(git.config('remote.origin.url'))
+
+
+    # FIXME "pkg_name" in shell means the obs prj?
+    if opts.obsprj:
+        obspkg = opts.obsprj
+    else:
+        obspkg = gitname
+
+    params = {'parameter': [
+                {"name": "pkg.tar.bz2", "file": "file0"},
+                {"name": "pkg", "value": tarname}
+             ]}
+
+    msger.info('uploading tarball %s to src server ...' % tarfp)
+    ss.upload(params, tarfp)
+    # TODO need to check the result and get the md5sum
+    # TODO update sources automatically?
index edc278c..404ea54 100644 (file)
@@ -37,3 +37,9 @@ class Abort(CmdError):
 
 class ConfigError(CmdError):
     keyword = '<config>'
+
+class GitInvalid(CmdError):
+    keywork = '<git>'
+
+    def __str__(self):
+        return 'Dir %s is not a valid git tree' % str(self.msg)
index 8f317b0..51f8b1a 100644 (file)
 # with this program; if not, write to the Free Software Foundation, Inc., 59
 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
+import os
+
 import runner
+import errors
 
 __all__ = ['config', 'branch', 'status', 'ls_files']
 
+def _run_git(cmd, args=[]):
+    if not os.path.isdir('.git'):
+        raise errors.GitInvalid(os.getcwd())
+
+    return runner.outs(['git', cmd] + args)
+
 def config(*args):
-    return runner.outs(['git', 'config'] + list(args))
+    return _run_git('config', list(args))
 
 def branch(all=False, current=False, *args):
-    cmdln = ['git', 'branch']
+    args = list(args)
     if all:
-        cmdln.append('-a')
-    cmdln += list(args)
+        args.insert(0, '-a')
 
-    branches = runner.outs(cmdln).splitlines()
+    branches = _run_git('branch', args).splitlines()
 
     curbr = ''
     for br in branches:
@@ -45,7 +53,7 @@ def branch(all=False, current=False, *args):
         return branches
 
 def status(*args):
-    outs = runner.outs(['git', 'status', '-s'] + list(args))
+    outs = _run_git('status', ['-s'] + list(args))
 
     sts = {}
     for line in outs.splitlines():
@@ -58,4 +66,5 @@ def status(*args):
     return sts
 
 def ls_files():
-    return runner.outs('git ls-files').splitlines()
+    return _run_git('ls-files').splitlines()
+
index 81a5c3d..8de015f 100644 (file)
@@ -39,6 +39,7 @@ def _call_curl(api, *opts, **fields):
         cmdln += ' -F%s=%s ' % (k, v)
 
     cmdln += '%s/%s' % (SRCSERVER, api.lstrip('/'))
+    msger.debug('curl cmdln: '+cmdln)
 
     return runner.outs(cmdln)
 
@@ -47,7 +48,7 @@ def build_lastid():
 
 def build_trigger(params, tarfp):
     _call_curl('job/build/build',
-               '-i', 
+               '-i',
                name=tarfp,
                file0='@'+tarfp,
                Submit='Build',
@@ -76,3 +77,11 @@ def build_mylastresult():
 
     return json.loads(retstr)
 
+def upload(params, tarfp):
+    _call_curl('job/upload/build',
+               '-i',
+               name='pkg.tar.bz2', # must wrong here, plz FIXME
+               file0='@'+tarfp,
+               Submit='Build',
+               json="%s" % json.dumps(params))
+
index 03bc551..cbc2576 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -34,7 +34,7 @@ if sys.version_info[:2] > (2, 5):
     if len(sys.argv) > 1 and 'install' in sys.argv:
         try:
             import platform
-            (dist, ver, id) = platform.linux_distribution()
+            (dist, ver, rid) = platform.linux_distribution()
 
             # for debian-like distros, mods will be installed to
             # ${PYTHONLIB}/dist-packages
index d59ae9b..aef0f83 100755 (executable)
--- a/tools/gbs
+++ b/tools/gbs
@@ -85,7 +85,7 @@ class TizenPkg(cmdln.Cmdln):
         """${cmd_name}: test building for current pkg
 
         Usage:
-            gbs build [OBS_project]
+            gbs build [options] [OBS_project]
 
         ${cmd_option_list}
         """
@@ -101,7 +101,7 @@ class TizenPkg(cmdln.Cmdln):
         """${cmd_name}: prepare packaging files for current pkg
 
         Usage:
-            gbs packaging
+            gbs packaging [options]
 
         ${cmd_option_list}
         """
@@ -109,12 +109,15 @@ class TizenPkg(cmdln.Cmdln):
         from gitbuildsys import cmd_packaging as cmd
         cmd.do(opts, args)
 
+    @cmdln.option('--obsprj', default=None,
+                  help='Specify OBS prj name if not the same as git')
+    @cmdln.alias("upload")
     @_fall_to_shell('import')
     def do_import(self, subcmd, opts, *args):
-        """${cmd_name}: import new tarballs for current pkg
+        """${cmd_name}: import/upload new tarballs for current pkg
 
         Usage:
-            gbs import
+            gbs import [options] <tarball>
 
         ${cmd_option_list}
         """