diff options
-rwxr-xr-x | bitbake/lib/bb/ui/crumbs/builder.py | 125 | ||||
-rw-r--r-- | bitbake/lib/bb/ui/crumbs/template.py | 187 |
2 files changed, 18 insertions, 294 deletions
diff --git a/bitbake/lib/bb/ui/crumbs/builder.py b/bitbake/lib/bb/ui/crumbs/builder.py index b5cfd9e917..2f7c496fea 100755 --- a/bitbake/lib/bb/ui/crumbs/builder.py +++ b/bitbake/lib/bb/ui/crumbs/builder.py | |||
@@ -30,7 +30,6 @@ import shlex | |||
30 | import re | 30 | import re |
31 | import logging | 31 | import logging |
32 | import sys | 32 | import sys |
33 | from bb.ui.crumbs.template import TemplateMgr | ||
34 | from bb.ui.crumbs.imageconfigurationpage import ImageConfigurationPage | 33 | from bb.ui.crumbs.imageconfigurationpage import ImageConfigurationPage |
35 | from bb.ui.crumbs.recipeselectionpage import RecipeSelectionPage | 34 | from bb.ui.crumbs.recipeselectionpage import RecipeSelectionPage |
36 | from bb.ui.crumbs.packageselectionpage import PackageSelectionPage | 35 | from bb.ui.crumbs.packageselectionpage import PackageSelectionPage |
@@ -192,36 +191,7 @@ class Configuration: | |||
192 | self.split_proxy("socks", params["socks_proxy"]) | 191 | self.split_proxy("socks", params["socks_proxy"]) |
193 | self.split_proxy("cvs", params["cvs_proxy_host"] + ":" + params["cvs_proxy_port"]) | 192 | self.split_proxy("cvs", params["cvs_proxy_host"] + ":" + params["cvs_proxy_port"]) |
194 | 193 | ||
195 | def load(self, template): | ||
196 | try: | ||
197 | self.image_rootfs_size = int(template.getVar("IMAGE_ROOTFS_SIZE")) | ||
198 | except: | ||
199 | pass | ||
200 | try: | ||
201 | self.image_extra_size = int(template.getVar("IMAGE_EXTRA_SPACE")) | ||
202 | except: | ||
203 | pass | ||
204 | # image_overhead_factor is read-only. | ||
205 | self.incompat_license = template.getVar("INCOMPATIBLE_LICENSE") | ||
206 | self.curr_sdk_machine = template.getVar("SDKMACHINE") | ||
207 | self.extra_setting = eval(template.getVar("EXTRA_SETTING")) | ||
208 | self.toolchain_build = eval(template.getVar("TOOLCHAIN_BUILD")) | ||
209 | self.image_fstypes = template.getVar("IMAGE_FSTYPES") | ||
210 | # image/recipes/packages | ||
211 | self.selected_image = template.getVar("__SELECTED_IMAGE__") | ||
212 | self.selected_recipes = template.getVar("DEPENDS").split() | ||
213 | self.selected_packages = template.getVar("IMAGE_INSTALL").split() | ||
214 | # proxy | ||
215 | self.enable_proxy = eval(template.getVar("enable_proxy")) | ||
216 | self.same_proxy = eval(template.getVar("use_same_proxy")) | ||
217 | self.split_proxy("http", template.getVar("http_proxy")) | ||
218 | self.split_proxy("https", template.getVar("https_proxy")) | ||
219 | self.split_proxy("ftp", template.getVar("ftp_proxy")) | ||
220 | self.split_proxy("socks", template.getVar("all_proxy")) | ||
221 | self.split_proxy("cvs", template.getVar("CVS_PROXY_HOST") + ":" + template.getVar("CVS_PROXY_PORT")) | ||
222 | |||
223 | def save(self, handler, template, defaults=False): | 194 | def save(self, handler, template, defaults=False): |
224 | template.setVar("VERSION", "%s" % hobVer) | ||
225 | # bblayers.conf | 195 | # bblayers.conf |
226 | handler.set_var_in_file("BBLAYERS", self.layers, "bblayers.conf") | 196 | handler.set_var_in_file("BBLAYERS", self.layers, "bblayers.conf") |
227 | # local.conf | 197 | # local.conf |
@@ -240,29 +210,29 @@ class Configuration: | |||
240 | handler.set_var_in_file("PARALLEL_MAKE", "-j %s" % self.pmake, "local.conf") | 210 | handler.set_var_in_file("PARALLEL_MAKE", "-j %s" % self.pmake, "local.conf") |
241 | handler.set_var_in_file("BB_NUMBER_THREADS", self.bbthread, "local.conf") | 211 | handler.set_var_in_file("BB_NUMBER_THREADS", self.bbthread, "local.conf") |
242 | handler.set_var_in_file("PACKAGE_CLASSES", " ".join(["package_" + i for i in self.curr_package_format.split()]), "local.conf") | 212 | handler.set_var_in_file("PACKAGE_CLASSES", " ".join(["package_" + i for i in self.curr_package_format.split()]), "local.conf") |
243 | template.setVar("IMAGE_ROOTFS_SIZE", self.image_rootfs_size) | 213 | handler.set_var_in_file("IMAGE_ROOTFS_SIZE", self.image_rootfs_size, "local.conf") |
244 | template.setVar("IMAGE_EXTRA_SPACE", self.image_extra_size) | 214 | handler.set_var_in_file("IMAGE_EXTRA_SPACE", self.image_extra_size, "local.conf") |
245 | template.setVar("INCOMPATIBLE_LICENSE", self.incompat_license) | 215 | handler.set_var_in_file("INCOMPATIBLE_LICENSE", self.incompat_license, "local.conf") |
246 | template.setVar("SDKMACHINE", self.curr_sdk_machine) | 216 | handler.set_var_in_file("SDKMACHINE", self.curr_sdk_machine, "local.conf") |
247 | handler.set_var_in_file("CONF_VERSION", self.conf_version, "local.conf") | 217 | handler.set_var_in_file("CONF_VERSION", self.conf_version, "local.conf") |
248 | handler.set_var_in_file("LCONF_VERSION", self.lconf_version, "bblayers.conf") | 218 | handler.set_var_in_file("LCONF_VERSION", self.lconf_version, "bblayers.conf") |
249 | template.setVar("EXTRA_SETTING", self.extra_setting) | 219 | handler.set_var_in_file("EXTRA_SETTING", self.extra_setting, "local.conf") |
250 | template.setVar("TOOLCHAIN_BUILD", self.toolchain_build) | 220 | handler.set_var_in_file("TOOLCHAIN_BUILD", self.toolchain_build, "local.conf") |
251 | template.setVar("IMAGE_FSTYPES", self.image_fstypes) | 221 | handler.set_var_in_file("IMAGE_FSTYPES", self.image_fstypes, "local.conf") |
252 | if not defaults: | 222 | if not defaults: |
253 | # image/recipes/packages | 223 | # image/recipes/packages |
254 | template.setVar("__SELECTED_IMAGE__", self.selected_image) | 224 | handler.set_var_in_file("__SELECTED_IMAGE__", self.selected_image, "local.conf") |
255 | template.setVar("DEPENDS", self.selected_recipes) | 225 | handler.set_var_in_file("DEPENDS", self.selected_recipes, "local.conf") |
256 | template.setVar("IMAGE_INSTALL", self.user_selected_packages) | 226 | handler.set_var_in_file("IMAGE_INSTALL", self.user_selected_packages, "local.conf") |
257 | # proxy | 227 | # proxy |
258 | template.setVar("enable_proxy", self.enable_proxy) | 228 | handler.set_var_in_file("enable_proxy", self.enable_proxy, "local.conf") |
259 | template.setVar("use_same_proxy", self.same_proxy) | 229 | handler.set_var_in_file("use_same_proxy", self.same_proxy, "local.conf") |
260 | template.setVar("http_proxy", self.combine_proxy("http")) | 230 | handler.set_var_in_file("http_proxy", self.combine_proxy("http"), "local.conf") |
261 | template.setVar("https_proxy", self.combine_proxy("https")) | 231 | handler.set_var_in_file("https_proxy", self.combine_proxy("https"), "local.conf") |
262 | template.setVar("ftp_proxy", self.combine_proxy("ftp")) | 232 | handler.set_var_in_file("ftp_proxy", self.combine_proxy("ftp"), "local.conf") |
263 | template.setVar("all_proxy", self.combine_proxy("socks")) | 233 | handler.set_var_in_file("all_proxy", self.combine_proxy("socks"), "local.conf") |
264 | template.setVar("CVS_PROXY_HOST", self.combine_host_only("cvs")) | 234 | handler.set_var_in_file("CVS_PROXY_HOST", self.combine_host_only("cvs"), "local.conf") |
265 | template.setVar("CVS_PROXY_PORT", self.combine_port_only("cvs")) | 235 | handler.set_var_in_file("CVS_PROXY_PORT", self.combine_port_only("cvs"), "local.conf") |
266 | 236 | ||
267 | def __str__(self): | 237 | def __str__(self): |
268 | s = "VERSION: '%s', BBLAYERS: '%s', MACHINE: '%s', DISTRO: '%s', DL_DIR: '%s'," % \ | 238 | s = "VERSION: '%s', BBLAYERS: '%s', MACHINE: '%s', DISTRO: '%s', DL_DIR: '%s'," % \ |
@@ -407,8 +377,6 @@ class Builder(gtk.Window): | |||
407 | # handler | 377 | # handler |
408 | self.handler = hobHandler | 378 | self.handler = hobHandler |
409 | 379 | ||
410 | self.template = None | ||
411 | |||
412 | # logger | 380 | # logger |
413 | self.logger = logging.getLogger("BitBake") | 381 | self.logger = logging.getLogger("BitBake") |
414 | self.consolelog = None | 382 | self.consolelog = None |
@@ -552,7 +520,6 @@ class Builder(gtk.Window): | |||
552 | self.handler.init_cooker() | 520 | self.handler.init_cooker() |
553 | self.handler.set_extra_inherit("image_types") | 521 | self.handler.set_extra_inherit("image_types") |
554 | self.generate_configuration() | 522 | self.generate_configuration() |
555 | self.load_template(TemplateMgr.convert_to_template_pathfilename("default", ".hob/")) | ||
556 | 523 | ||
557 | def update_config_async(self): | 524 | def update_config_async(self): |
558 | self.switch_page(self.MACHINE_SELECTION) | 525 | self.switch_page(self.MACHINE_SELECTION) |
@@ -635,61 +602,6 @@ class Builder(gtk.Window): | |||
635 | def cancel_parse_sync(self): | 602 | def cancel_parse_sync(self): |
636 | self.handler.cancel_parse() | 603 | self.handler.cancel_parse() |
637 | 604 | ||
638 | def load_template(self, path): | ||
639 | if not os.path.isfile(path): | ||
640 | return False | ||
641 | |||
642 | self.template = TemplateMgr() | ||
643 | # check compatibility | ||
644 | tempVer = self.template.getVersion(path) | ||
645 | if not tempVer or int(tempVer) < hobVer: | ||
646 | self.template.destroy() | ||
647 | self.template = None | ||
648 | return False | ||
649 | |||
650 | try: | ||
651 | self.template.load(path) | ||
652 | self.configuration.load(self.template) | ||
653 | except Exception as e: | ||
654 | self.show_error_dialog("Hob Exception - %s" % (str(e))) | ||
655 | self.reset() | ||
656 | finally: | ||
657 | self.template.destroy() | ||
658 | self.template = None | ||
659 | |||
660 | for layer in self.configuration.layers: | ||
661 | if not os.path.exists(layer+'/conf/layer.conf'): | ||
662 | return False | ||
663 | |||
664 | self.set_user_config_extra() | ||
665 | return True | ||
666 | |||
667 | def save_template(self, path, defaults=False): | ||
668 | if path.rfind("/") == -1: | ||
669 | filename = "default" | ||
670 | path = "." | ||
671 | else: | ||
672 | filename = path[path.rfind("/") + 1:len(path)] | ||
673 | path = path[0:path.rfind("/")] | ||
674 | |||
675 | self.template = TemplateMgr() | ||
676 | try: | ||
677 | self.template.open(filename, path) | ||
678 | self.configuration.save(self.handler, self.template, defaults) | ||
679 | |||
680 | self.template.save() | ||
681 | except Exception as e: | ||
682 | self.show_error_dialog("Hob Exception - %s" % (str(e))) | ||
683 | self.reset() | ||
684 | finally: | ||
685 | self.template.destroy() | ||
686 | self.template = None | ||
687 | |||
688 | def save_defaults(self): | ||
689 | if not os.path.exists(".hob/"): | ||
690 | os.mkdir(".hob/") | ||
691 | self.save_template(".hob/default", True) | ||
692 | |||
693 | def switch_page(self, next_step): | 605 | def switch_page(self, next_step): |
694 | # Main Workflow (Business Logic) | 606 | # Main Workflow (Business Logic) |
695 | self.nb.set_current_page(self.__step2page__[next_step]) | 607 | self.nb.set_current_page(self.__step2page__[next_step]) |
@@ -1255,7 +1167,6 @@ class Builder(gtk.Window): | |||
1255 | response = dialog.run() | 1167 | response = dialog.run() |
1256 | if response == gtk.RESPONSE_YES: | 1168 | if response == gtk.RESPONSE_YES: |
1257 | self.configuration.layers = dialog.layers | 1169 | self.configuration.layers = dialog.layers |
1258 | self.save_defaults() # remember layers | ||
1259 | # DO refresh layers | 1170 | # DO refresh layers |
1260 | if dialog.layers_changed: | 1171 | if dialog.layers_changed: |
1261 | self.update_config_async() | 1172 | self.update_config_async() |
diff --git a/bitbake/lib/bb/ui/crumbs/template.py b/bitbake/lib/bb/ui/crumbs/template.py deleted file mode 100644 index 92c438f000..0000000000 --- a/bitbake/lib/bb/ui/crumbs/template.py +++ /dev/null | |||
@@ -1,187 +0,0 @@ | |||
1 | # | ||
2 | # BitBake Graphical GTK User Interface | ||
3 | # | ||
4 | # Copyright (C) 2011 Intel Corporation | ||
5 | # | ||
6 | # Authored by Shane Wang <shane.wang@intel.com> | ||
7 | # | ||
8 | # This program is free software; you can redistribute it and/or modify | ||
9 | # it under the terms of the GNU General Public License version 2 as | ||
10 | # published by the Free Software Foundation. | ||
11 | # | ||
12 | # This program is distributed in the hope that it will be useful, | ||
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | # GNU General Public License for more details. | ||
16 | # | ||
17 | # You should have received a copy of the GNU General Public License along | ||
18 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
20 | |||
21 | import gobject | ||
22 | import os | ||
23 | import re | ||
24 | |||
25 | class File(gobject.GObject): | ||
26 | |||
27 | def __init__(self, pathfilename, suffix): | ||
28 | if not pathfilename.endswith(suffix): | ||
29 | pathfilename = "%s%s" % (pathfilename, suffix) | ||
30 | gobject.GObject.__init__(self) | ||
31 | self.pathfilename = pathfilename | ||
32 | |||
33 | def readFile(self): | ||
34 | if not os.path.isfile(self.pathfilename): | ||
35 | return None | ||
36 | if not os.path.exists(self.pathfilename): | ||
37 | return None | ||
38 | |||
39 | with open(self.pathfilename, 'r') as f: | ||
40 | contents = f.readlines() | ||
41 | f.close() | ||
42 | |||
43 | return contents | ||
44 | |||
45 | def writeFile(self, contents): | ||
46 | if os.path.exists(self.pathfilename): | ||
47 | orig = "%s.orig" % self.pathfilename | ||
48 | if os.path.exists(orig): | ||
49 | os.remove(orig) | ||
50 | os.rename(self.pathfilename, orig) | ||
51 | |||
52 | with open(self.pathfilename, 'w') as f: | ||
53 | f.write(contents) | ||
54 | f.close() | ||
55 | |||
56 | class ConfigFile(File): | ||
57 | """ | ||
58 | This object does save general config file. (say bblayers.conf, or local.conf). Again, it is the base class for other template files and image bb files. | ||
59 | """ | ||
60 | def __init__(self, pathfilename, suffix = None, header = None): | ||
61 | if suffix: | ||
62 | File.__init__(self, pathfilename, suffix) | ||
63 | else: | ||
64 | File.__init__(self, pathfilename, ".conf") | ||
65 | if header: | ||
66 | self.header = header | ||
67 | else: | ||
68 | self.header = "# Config generated by Hob\n\n" | ||
69 | self.dictionary = {} | ||
70 | |||
71 | def setVar(self, var, val): | ||
72 | if isinstance(val, list): | ||
73 | liststr = "" | ||
74 | if val: | ||
75 | i = 0 | ||
76 | for value in val: | ||
77 | if i < len(val) - 1: | ||
78 | liststr += "%s " % value | ||
79 | else: | ||
80 | liststr += "%s" % value | ||
81 | i += 1 | ||
82 | self.dictionary[var] = liststr | ||
83 | else: | ||
84 | self.dictionary[var] = val | ||
85 | |||
86 | def save(self): | ||
87 | contents = self.header | ||
88 | for var, val in self.dictionary.items(): | ||
89 | contents += "%s = \"%s\"\n" % (var, val) | ||
90 | File.writeFile(self, contents) | ||
91 | |||
92 | class HobTemplateFile(ConfigFile): | ||
93 | """ | ||
94 | This object does save or load hob specific file. | ||
95 | """ | ||
96 | def __init__(self, pathfilename): | ||
97 | ConfigFile.__init__(self, pathfilename, ".hob", "# Hob Template generated by Hob\n\n") | ||
98 | |||
99 | def getVar(self, var): | ||
100 | if var in self.dictionary: | ||
101 | return self.dictionary[var] | ||
102 | else: | ||
103 | return "" | ||
104 | |||
105 | def getVersion(self): | ||
106 | contents = ConfigFile.readFile(self) | ||
107 | |||
108 | pattern = "^\s*(\S+)\s*=\s*(\".*?\")" | ||
109 | |||
110 | for line in contents: | ||
111 | match = re.search(pattern, line) | ||
112 | if match: | ||
113 | if match.group(1) == "VERSION": | ||
114 | return match.group(2).strip('"') | ||
115 | return None | ||
116 | |||
117 | def load(self): | ||
118 | contents = ConfigFile.readFile(self) | ||
119 | self.dictionary.clear() | ||
120 | |||
121 | pattern = "^\s*(\S+)\s*=\s*(\".*?\")" | ||
122 | |||
123 | for line in contents: | ||
124 | match = re.search(pattern, line) | ||
125 | if match: | ||
126 | var = match.group(1) | ||
127 | val = match.group(2).strip('"') | ||
128 | self.dictionary[var] = val | ||
129 | return self.dictionary | ||
130 | |||
131 | class RecipeFile(ConfigFile): | ||
132 | """ | ||
133 | This object is for image bb file. | ||
134 | """ | ||
135 | def __init__(self, pathfilename): | ||
136 | ConfigFile.__init__(self, pathfilename, ".bb", "# Recipe generated by Hob\n\ninherit core-image\n") | ||
137 | |||
138 | class TemplateMgr(gobject.GObject): | ||
139 | |||
140 | __gRecipeVars__ = ["DEPENDS", "IMAGE_INSTALL"] | ||
141 | |||
142 | def __init__(self): | ||
143 | gobject.GObject.__init__(self) | ||
144 | self.template_hob = None | ||
145 | self.bblayers_conf = None | ||
146 | self.local_conf = None | ||
147 | self.image_bb = None | ||
148 | |||
149 | @classmethod | ||
150 | def convert_to_template_pathfilename(cls, filename, path): | ||
151 | return "%s/%s%s%s" % (path, "template-", filename, ".hob") | ||
152 | |||
153 | @classmethod | ||
154 | def convert_to_image_pathfilename(cls, filename, path): | ||
155 | return "%s/%s%s%s" % (path, "hob-image-", filename, ".bb") | ||
156 | |||
157 | def open(self, filename, path): | ||
158 | self.template_hob = HobTemplateFile(TemplateMgr.convert_to_template_pathfilename(filename, path)) | ||
159 | self.image_bb = RecipeFile(TemplateMgr.convert_to_image_pathfilename(filename, path)) | ||
160 | |||
161 | def setVar(self, var, val): | ||
162 | if var in TemplateMgr.__gRecipeVars__: | ||
163 | self.image_bb.setVar(var, val) | ||
164 | |||
165 | self.template_hob.setVar(var, val) | ||
166 | |||
167 | def save(self): | ||
168 | self.image_bb.save() | ||
169 | self.template_hob.save() | ||
170 | |||
171 | def getVersion(self, path): | ||
172 | return HobTemplateFile(path).getVersion() | ||
173 | |||
174 | def load(self, path): | ||
175 | self.template_hob = HobTemplateFile(path) | ||
176 | self.dictionary = self.template_hob.load() | ||
177 | |||
178 | def getVar(self, var): | ||
179 | return self.template_hob.getVar(var) | ||
180 | |||
181 | def destroy(self): | ||
182 | if self.template_hob: | ||
183 | del self.template_hob | ||
184 | template_hob = None | ||
185 | if self.image_bb: | ||
186 | del self.image_bb | ||
187 | self.image_bb = None | ||