--- /dev/null
+#!/usr/bin/env python
+# vim: ai ts=4 sts=4 et sw=4
+#
+# Copyright (c) 2014, 2015, 2016 Samsung Electronics.Co.Ltd.
+#
+# 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.
+#
+import sys
+import os
+import glob
+import shutil
+import subprocess
+import tempfile
+
+from common.buildtrigger import trigger_info, trigger_next
+
+class LocalError(Exception):
+ """Local error exception."""
+ pass
+
+def execute(cmd, cwd = None):
+ try:
+ ret_code = subprocess.call(cmd, shell=True, cwd=cwd)
+ except OSError as err:
+ raise RuntimeException("Execution of %s failed: %s" %
+ (cmd, str(err)))
+ return ret_code
+
+def nuget_init(nuget_exe, nuget_source, nuget_apikey):
+ """ Init Nuget """
+ cmd = '%s setApiKey %s -Source %s' \
+ % (nuget_exe, nuget_apikey, nuget_source)
+ return execute(cmd)
+
+def nuget_push(nuget_exe, nuget_source, nupkg, tmpdir):
+ """ Push Nuget """
+ cmd = '%s push %s -Source %s' % (nuget_exe, nupkg, nuget_source)
+ return execute(cmd, tmpdir)
+
+def extract_rpms(repodir):
+ """ Extract rpms """
+ ngrpms = glob.glob(os.path.join(repodir, '*-nuget-*.rpm'))
+ tmpdir = tempfile.mkdtemp(prefix = 'nuget')
+ for rpm in ngrpms:
+ execute('rpm2cpio %s | cpio -idmv' % rpm, tmpdir)
+ return tmpdir
+
+def push_nuget_files(nuget_exe, nuget_source, tmpdir):
+ """ Push Nuget files """
+ nupkgs = glob.glob(os.path.join(tmpdir, 'nuget/*.nupkg'))
+ for nupkg in nupkgs:
+ nuget_push(nuget_exe, nuget_source, os.path.relpath(nupkg, tmpdir), tmpdir)
+
+def main():
+ """ Script entry point. """
+ print '---[JOB STARTED]-------------------------'
+
+ # get trigger_info
+ content = trigger_info(os.getenv("TRIGGER_INFO"))
+ project = content.get("project")
+ repo_path = content.get("repo_path")
+
+ # get NUGET configuration
+ if os.getenv("NUGET_UPDATE_ENABLE","0") != "1":
+ print "Skipping as NUGET_UPDATE_ENABLE=%s is not enabled " \
+ %(os.getenv("NUGET_UPDATE_ENABLE"))
+ return 0
+ if not project in os.getenv("NUGET_PROJECT"):
+ print "Skipping as %s project is not present in nuget project %s " \
+ %(project, os.getenv("NUGET_PROJECT"))
+ return 0
+
+ nuget_exe = "mono %s/jenkins-scripts/scripts/nuget.exe" %(os.getenv('WORKSPACE'))
+ nuget_source = os.getenv("NUGET_SOURCE")
+ nuget_apikey = os.getenv("NUGET_APIKEY")
+
+ base_path = os.getenv('PATH_REPO_BASE')
+
+ # Initialize NuGet
+ nuget_init(nuget_exe, nuget_source, nuget_apikey)
+
+ for repository in content.get("repo").keys():
+ for arch in content.get("repo")[repository].get("archs"):
+ if arch != "armv7l":
+ continue
+ else:
+ repo_arch_path = os.path.join(base_path,
+ repo_path,
+ "repos",
+ repository,
+ "packages",
+ arch
+ )
+ print "repo arch path = %s" %repo_arch_path
+ # Extract *-nuget-*.rpm files to tmpdir
+ tmpdir = extract_rpms(repo_arch_path)
+ print tmpdir
+ # Push .nupkg files in tmpdir to NuGet server
+ push_nuget_files(nuget_exe, nuget_source, tmpdir)
+ # Cleanup tmpdir
+ shutil.rmtree(tmpdir)
+
+ print '---[JOB ENDED]---------------------------'
+ return 0
+
+if __name__ == "__main__":
+ try:
+ sys.exit(main())
+ except LocalError, error:
+ print error
+ sys.exit(1)
+
+