summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/ui/crumbs/template.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/ui/crumbs/template.py')
-rw-r--r--bitbake/lib/bb/ui/crumbs/template.py187
1 files changed, 0 insertions, 187 deletions
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
21import gobject
22import os
23import re
24
25class 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
56class 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
92class 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
131class 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
138class 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