summaryrefslogtreecommitdiffstats
path: root/scripts/oe-publish-sdk
diff options
context:
space:
mode:
authorQi.Chen@windriver.com <Qi.Chen@windriver.com>2015-09-07 13:42:26 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-09-09 14:27:43 +0100
commit2aaa59ed8e3bb72385e962ec3594da709b18fad8 (patch)
tree3ca8d84a46cd7d33654513422a6c152c4897bf57 /scripts/oe-publish-sdk
parentad959638c0def49661d87fe5b7435cebe63897b9 (diff)
downloadpoky-2aaa59ed8e3bb72385e962ec3594da709b18fad8.tar.gz
oe-publish-sdk: add script
Add a script to publish an extensible SDK that has previously been built to a specified destination. This published SDK is intended to be accessed by the devtool sdk-update command from an installed copy of the extensible SDK. e.g. oe-publish-sdk <ext-sdk> <destination> (From OE-Core rev: c201ab826046b30281341107b3e6a35204f5c9d8) Signed-off-by: Chen Qi <Qi.Chen@windriver.com> Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/oe-publish-sdk')
-rwxr-xr-xscripts/oe-publish-sdk143
1 files changed, 143 insertions, 0 deletions
diff --git a/scripts/oe-publish-sdk b/scripts/oe-publish-sdk
new file mode 100755
index 0000000000..1737c9f3bc
--- /dev/null
+++ b/scripts/oe-publish-sdk
@@ -0,0 +1,143 @@
1#!/usr/bin/env python
2
3# OpenEmbedded SDK publishing tool
4
5# oe-publish-sdk publish <ext-sdk> <destination>
6# <ext-sdk>: extensible SDK to publish (path to the installer shell script)
7# <destination>: local or remote location which servers as an SDK update server
8# e.g.
9# oe-publish-sdk /path/to/sdk-ext.sh /mnt/poky/sdk-ext
10# oe-publish-sdk /path/to/sdk-ext.sh user@host:/opt/poky/sdk-ext
11#
12
13import sys
14import os
15import argparse
16import glob
17import re
18import subprocess
19import logging
20import shutil
21import errno
22
23scripts_path = os.path.dirname(os.path.realpath(__file__))
24lib_path = scripts_path + '/lib'
25sys.path = sys.path + [lib_path]
26import scriptutils
27logger = scriptutils.logger_create('sdktool')
28
29def mkdir(d):
30 try:
31 os.makedirs(d)
32 except OSError as e:
33 if e.errno != errno.EEXIST:
34 raise e
35
36def publish(args):
37 logger.debug("In publish function")
38 target_sdk = args.sdk
39 destination = args.dest
40 logger.debug("target_sdk = %s, update_server = %s" % (target_sdk, destination))
41 sdk_basename = os.path.basename(target_sdk)
42
43 # Ensure the SDK exists
44 if not os.path.exists(target_sdk):
45 logger.error("%s doesn't exist" % target_sdk)
46 return -1
47
48 if ':' in destination:
49 is_remote = True
50 host, destdir = destination.split(':')
51 dest_sdk = os.path.join(destdir, sdk_basename)
52 else:
53 is_remote = False
54 dest_sdk = os.path.join(destination, sdk_basename)
55
56 # Making sure the directory exists
57 logger.debug("Making sure the destination directory exists")
58 if not is_remote:
59 mkdir(destination)
60 else:
61 cmd = "ssh %s 'mkdir -p %s'" % (host, destdir)
62 ret = subprocess.call(cmd, shell=True)
63 if ret != 0:
64 logger.error("Making directory %s on %s failed" % (destdir, host))
65 return ret
66
67 # Copying the SDK to the destination
68 logger.info("Copying the SDK to destination")
69 if not is_remote:
70 if os.path.exists(dest_sdk):
71 os.remove(dest_sdk)
72 if (os.stat(target_sdk).st_dev == os.stat(destination).st_dev):
73 os.link(target_sdk, dest_sdk)
74 else:
75 shutil.copy(target_sdk, dest_sdk)
76 else:
77 cmd = "scp %s %s" % (target_sdk, destination)
78 ret = subprocess.call(cmd, shell=True)
79 if ret != 0:
80 logger.error("scp %s %s failed" % (target_sdk, destination))
81 return ret
82
83 # Unpack the SDK
84 logger.info("Unpacking SDK")
85 if not is_remote:
86 cmd = "sh %s -n -y -d %s" % (dest_sdk, destination)
87 ret = subprocess.call(cmd, shell=True)
88 if ret == 0:
89 logger.info('Successfully unpacked %s to %s' % (dest_sdk, destination))
90 else:
91 logger.error('Failed to unpack %s to %s' % (dest_sdk, destination))
92 return ret
93 else:
94 cmd = "ssh %s 'sh %s -n -y -d %s'" % (host, dest_sdk, destdir)
95 ret = subprocess.call(cmd, shell=True)
96 if ret == 0:
97 logger.info('Successfully unpacked %s to %s' % (dest_sdk, destdir))
98 else:
99 logger.error('Failed to unpack %s to %s' % (dest_sdk, destdir))
100 return ret
101
102 # Setting up the git repo
103 if not is_remote:
104 cmd = 'set -e; cd %s/layers; if [ ! -e .git ]; then git init .; mv .git/hooks/post-update.sample .git/hooks/post-update; fi; git add -A .; git commit -q -m "init repo" || true;' % destination
105 else:
106 cmd = "ssh %s 'set -e; cd %s/layers; if [ ! -e .git ]; then git init .; mv .git/hooks/post-update.sample .git/hooks/post-update; fi; git add -A .; git commit -q -m \"init repo\" || true;'" % (host, destdir)
107 ret = subprocess.call(cmd, shell=True)
108 if ret == 0:
109 logger.info('SDK published successfully')
110 else:
111 logger.error('Failed to set up layer git repo')
112 return ret
113
114
115def main():
116 parser = argparse.ArgumentParser(description="OpenEmbedded development tool",
117 epilog="Use %(prog)s <subcommand> --help to get help on a specific command")
118 parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
119 parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true')
120
121 parser.add_argument('sdk', help='Extensible SDK to publish')
122 parser.add_argument('dest', help='Destination to publish SDK to')
123
124 parser.set_defaults(func=publish)
125
126 args = parser.parse_args()
127
128 if args.debug:
129 logger.setLevel(logging.DEBUG)
130 elif args.quiet:
131 logger.setLevel(logging.ERROR)
132
133 ret = args.func(args)
134 return ret
135
136if __name__ == "__main__":
137 try:
138 ret = main()
139 except Exception:
140 ret = 1
141 import traceback
142 traceback.print_exc(5)
143 sys.exit(ret)