root / lib / build / __init__.py @ bad78e66
History | View | Annotate | Download (1.2 kB)
1 | f9897b6d | Michael Hanselmann | #
|
---|---|---|---|
2 | f9897b6d | Michael Hanselmann | #
|
3 | f9897b6d | Michael Hanselmann | |
4 | f9897b6d | Michael Hanselmann | # Copyright (C) 2009 Google Inc.
|
5 | f9897b6d | Michael Hanselmann | #
|
6 | f9897b6d | Michael Hanselmann | # This program is free software; you can redistribute it and/or modify
|
7 | f9897b6d | Michael Hanselmann | # it under the terms of the GNU General Public License as published by
|
8 | f9897b6d | Michael Hanselmann | # the Free Software Foundation; either version 2 of the License, or
|
9 | f9897b6d | Michael Hanselmann | # (at your option) any later version.
|
10 | f9897b6d | Michael Hanselmann | #
|
11 | f9897b6d | Michael Hanselmann | # This program is distributed in the hope that it will be useful, but
|
12 | f9897b6d | Michael Hanselmann | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | f9897b6d | Michael Hanselmann | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | f9897b6d | Michael Hanselmann | # General Public License for more details.
|
15 | f9897b6d | Michael Hanselmann | #
|
16 | f9897b6d | Michael Hanselmann | # You should have received a copy of the GNU General Public License
|
17 | f9897b6d | Michael Hanselmann | # along with this program; if not, write to the Free Software
|
18 | f9897b6d | Michael Hanselmann | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | f9897b6d | Michael Hanselmann | # 02110-1301, USA.
|
20 | e948770c | Michael Hanselmann | |
21 | 7260cfbe | Iustin Pop | """Module used during the Ganeti build process"""
|
22 | e948770c | Michael Hanselmann | |
23 | e948770c | Michael Hanselmann | import imp |
24 | e948770c | Michael Hanselmann | import os |
25 | e948770c | Michael Hanselmann | |
26 | e948770c | Michael Hanselmann | |
27 | e948770c | Michael Hanselmann | def LoadModule(filename): |
28 | e948770c | Michael Hanselmann | """Loads an external module by filename.
|
29 | e948770c | Michael Hanselmann |
|
30 | e948770c | Michael Hanselmann | Use this function with caution. Python will always write the compiled source
|
31 | e948770c | Michael Hanselmann | to a file named "${filename}c".
|
32 | e948770c | Michael Hanselmann |
|
33 | e948770c | Michael Hanselmann | @type filename: string
|
34 | e948770c | Michael Hanselmann | @param filename: Path to module
|
35 | e948770c | Michael Hanselmann |
|
36 | e948770c | Michael Hanselmann | """
|
37 | e948770c | Michael Hanselmann | (name, ext) = os.path.splitext(filename) |
38 | e948770c | Michael Hanselmann | |
39 | e948770c | Michael Hanselmann | fh = open(filename, "U") |
40 | e948770c | Michael Hanselmann | try:
|
41 | e948770c | Michael Hanselmann | return imp.load_module(name, fh, filename, (ext, "U", imp.PY_SOURCE)) |
42 | e948770c | Michael Hanselmann | finally:
|
43 | e948770c | Michael Hanselmann | fh.close() |