diff options
author | Tom Zanussi <tom.zanussi@linux.intel.com> | 2013-08-24 15:31:34 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-10-01 22:56:03 +0100 |
commit | 9fc88f96d40b17c90bac53b90045a87b2d2cff84 (patch) | |
tree | 63010e5aabf895697655baf89bd668d6752b3f97 /scripts/lib/mic/3rdparty/pykickstart/urlgrabber/sslfactory.py | |
parent | 53a1d9a788fd9f970af980da2ab975cca60685c4 (diff) | |
download | poky-9fc88f96d40b17c90bac53b90045a87b2d2cff84.tar.gz |
wic: Add mic w/pykickstart
This is the starting point for the implemention described in [YOCTO
3847] which came to the conclusion that it would make sense to use
kickstart syntax to implement image creation in OpenEmbedded. I
subsequently realized that there was an existing tool that already
implemented image creation using kickstart syntax, the Tizen/Meego mic
tool. As such, it made sense to use that as a starting point - this
commit essentially just copies the relevant Python code from the MIC
tool to the scripts/lib dir, where it can be accessed by the
previously created wic tool.
Most of this will be removed or renamed by later commits, since we're
initially focusing on partitioning only. Care should be taken so that
we can easily add back any additional functionality should we decide
later to expand the tool, though (we may also want to contribute our
local changes to the mic tool to the Tizen project if it makes sense,
and therefore should avoid gratuitous changes to the original code if
possible).
Added the /mic subdir from Tizen mic repo as a starting point:
git clone git://review.tizen.org/tools/mic.git
For reference, the top commit:
commit 20164175ddc234a17b8a12c33d04b012347b1530
Author: Gui Chen <gui.chen@intel.com>
Date: Sun Jun 30 22:32:16 2013 -0400
bump up to 0.19.2
Also added the /plugins subdir, moved to under the /mic subdir (to
match the default plugin_dir location in mic.conf.in, which was
renamed to yocto-image.conf (moved and renamed by later patches) and
put into /scripts.
(From OE-Core rev: 31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e)
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/mic/3rdparty/pykickstart/urlgrabber/sslfactory.py')
-rw-r--r-- | scripts/lib/mic/3rdparty/pykickstart/urlgrabber/sslfactory.py | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/scripts/lib/mic/3rdparty/pykickstart/urlgrabber/sslfactory.py b/scripts/lib/mic/3rdparty/pykickstart/urlgrabber/sslfactory.py new file mode 100644 index 0000000000..07848dac7c --- /dev/null +++ b/scripts/lib/mic/3rdparty/pykickstart/urlgrabber/sslfactory.py | |||
@@ -0,0 +1,90 @@ | |||
1 | # This library is free software; you can redistribute it and/or | ||
2 | # modify it under the terms of the GNU Lesser General Public | ||
3 | # License as published by the Free Software Foundation; either | ||
4 | # version 2.1 of the License, or (at your option) any later version. | ||
5 | # | ||
6 | # This library is distributed in the hope that it will be useful, | ||
7 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
8 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
9 | # Lesser General Public License for more details. | ||
10 | # | ||
11 | # You should have received a copy of the GNU Lesser General Public | ||
12 | # License along with this library; if not, write to the | ||
13 | # Free Software Foundation, Inc., | ||
14 | # 59 Temple Place, Suite 330, | ||
15 | # Boston, MA 02111-1307 USA | ||
16 | |||
17 | # This file is part of urlgrabber, a high-level cross-protocol url-grabber | ||
18 | |||
19 | import httplib | ||
20 | import urllib2 | ||
21 | |||
22 | try: | ||
23 | from M2Crypto import SSL | ||
24 | from M2Crypto import httpslib | ||
25 | from M2Crypto import m2urllib2 | ||
26 | |||
27 | SSL.Connection.clientPostConnectionCheck = None | ||
28 | have_m2crypto = True | ||
29 | except ImportError: | ||
30 | have_m2crypto = False | ||
31 | |||
32 | DEBUG = None | ||
33 | |||
34 | if have_m2crypto: | ||
35 | |||
36 | class M2SSLFactory: | ||
37 | |||
38 | def __init__(self, ssl_ca_cert, ssl_context): | ||
39 | self.ssl_context = self._get_ssl_context(ssl_ca_cert, ssl_context) | ||
40 | |||
41 | def _get_ssl_context(self, ssl_ca_cert, ssl_context): | ||
42 | """ | ||
43 | Create an ssl context using the CA cert file or ssl context. | ||
44 | |||
45 | The CA cert is used first if it was passed as an option. If not, | ||
46 | then the supplied ssl context is used. If no ssl context was supplied, | ||
47 | None is returned. | ||
48 | """ | ||
49 | if ssl_ca_cert: | ||
50 | context = SSL.Context() | ||
51 | context.load_verify_locations(ssl_ca_cert) | ||
52 | context.set_verify(SSL.verify_none, -1) | ||
53 | return context | ||
54 | else: | ||
55 | return ssl_context | ||
56 | |||
57 | def create_https_connection(self, host, response_class = None): | ||
58 | connection = httplib.HTTPSConnection(host, self.ssl_context) | ||
59 | if response_class: | ||
60 | connection.response_class = response_class | ||
61 | return connection | ||
62 | |||
63 | def create_opener(self, *handlers): | ||
64 | return m2urllib2.build_opener(self.ssl_context, *handlers) | ||
65 | |||
66 | |||
67 | class SSLFactory: | ||
68 | |||
69 | def create_https_connection(self, host, response_class = None): | ||
70 | connection = httplib.HTTPSConnection(host) | ||
71 | if response_class: | ||
72 | connection.response_class = response_class | ||
73 | return connection | ||
74 | |||
75 | def create_opener(self, *handlers): | ||
76 | return urllib2.build_opener(*handlers) | ||
77 | |||
78 | |||
79 | |||
80 | def get_factory(ssl_ca_cert = None, ssl_context = None): | ||
81 | """ Return an SSLFactory, based on if M2Crypto is available. """ | ||
82 | if have_m2crypto: | ||
83 | return M2SSLFactory(ssl_ca_cert, ssl_context) | ||
84 | else: | ||
85 | # Log here if someone provides the args but we don't use them. | ||
86 | if ssl_ca_cert or ssl_context: | ||
87 | if DEBUG: | ||
88 | DEBUG.warning("SSL arguments supplied, but M2Crypto is not available. " | ||
89 | "Using Python SSL.") | ||
90 | return SSLFactory() | ||