summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
authorbrian avery <avery.brian@gmail.com>2015-10-07 15:17:35 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-10-11 05:33:06 +0100
commit8068aa3b0f60bbbc1ad4287971507a2974c58321 (patch)
treef562c611800de0120889ff91d9f42e1b1f79932a /bitbake/lib
parent7d7823e597138a57d3cf16f39dae95b23becf1e8 (diff)
downloadpoky-8068aa3b0f60bbbc1ad4287971507a2974c58321.tar.gz
bitbake: toaster: get rid of interactivity in bldcontrol
removed layer dir questions and base off TOASTER_DIR removed build dir questions and base off TOASTER_DIR base configuration file off of TOASTER_CONF fixed some pylint issues [YOCTO #8217] (Bitbake rev: d5811968b5f22093365f381fb7e75ab46e5269c2) Signed-off-by: brian avery <avery.brian@gmail.com> Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r--bitbake/lib/toaster/bldcontrol/management/commands/checksettings.py138
1 files changed, 37 insertions, 101 deletions
diff --git a/bitbake/lib/toaster/bldcontrol/management/commands/checksettings.py b/bitbake/lib/toaster/bldcontrol/management/commands/checksettings.py
index b2c573c9eb..5e70437b24 100644
--- a/bitbake/lib/toaster/bldcontrol/management/commands/checksettings.py
+++ b/bitbake/lib/toaster/bldcontrol/management/commands/checksettings.py
@@ -4,7 +4,7 @@ from bldcontrol.bbcontroller import getBuildEnvironmentController, ShellCmdExcep
4from bldcontrol.models import BuildRequest, BuildEnvironment, BRError 4from bldcontrol.models import BuildRequest, BuildEnvironment, BRError
5from orm.models import ToasterSetting, Build 5from orm.models import ToasterSetting, Build
6import os 6import os
7import sys, traceback 7import traceback
8 8
9def DN(path): 9def DN(path):
10 if path is None: 10 if path is None:
@@ -21,7 +21,7 @@ class Command(NoArgsCommand):
21 super(Command, self).__init__(*args, **kwargs) 21 super(Command, self).__init__(*args, **kwargs)
22 self.guesspath = DN(DN(DN(DN(DN(DN(DN(__file__))))))) 22 self.guesspath = DN(DN(DN(DN(DN(DN(DN(__file__)))))))
23 23
24 def _find_first_path_for_file(self, startdirectory, filename, level = 0): 24 def _find_first_path_for_file(self, startdirectory, filename, level=0):
25 if level < 0: 25 if level < 0:
26 return None 26 return None
27 dirs = [] 27 dirs = []
@@ -38,7 +38,7 @@ class Command(NoArgsCommand):
38 return ret 38 return ret
39 return None 39 return None
40 40
41 def _recursive_list_directories(self, startdirectory, level = 0): 41 def _recursive_list_directories(self, startdirectory, level=0):
42 if level < 0: 42 if level < 0:
43 return [] 43 return []
44 dirs = [] 44 dirs = []
@@ -50,49 +50,23 @@ class Command(NoArgsCommand):
50 except OSError: 50 except OSError:
51 pass 51 pass
52 for j in dirs: 52 for j in dirs:
53 dirs = dirs + self._recursive_list_directories(j, level - 1) 53 dirs = dirs + self._recursive_list_directories(j, level - 1)
54 return dirs 54 return dirs
55 55
56 56
57 def _get_suggested_sourcedir(self, be):
58 if be.betype != BuildEnvironment.TYPE_LOCAL:
59 return ""
60 return DN(DN(DN(self._find_first_path_for_file(self.guesspath, "toasterconf.json", 4))))
61
62 def _get_suggested_builddir(self, be):
63 if be.betype != BuildEnvironment.TYPE_LOCAL:
64 return ""
65 return DN(self._find_first_path_for_file(DN(self.guesspath), "bblayers.conf", 4))
66
67 def _verify_build_environment(self): 57 def _verify_build_environment(self):
68 # refuse to start if we have no build environments 58 # provide a local build env. This will be extended later to include non local
69 while BuildEnvironment.objects.count() == 0: 59 if BuildEnvironment.objects.count() == 0:
70 print(" !! No build environments found. Toaster needs at least one build environment in order to be able to run builds.\n" + 60 BuildEnvironment.objects.create(betype=BuildEnvironment.TYPE_LOCAL)
71 "You can manually define build environments in the database table bldcontrol_buildenvironment.\n" +
72 "Or Toaster can define a simple localhost-based build environment for you.")
73
74 i = raw_input(" -- Do you want to create a basic localhost build environment ? (Y/n) ");
75 if not len(i) or i.startswith("y") or i.startswith("Y"):
76 BuildEnvironment.objects.create(pk = 1, betype = 0)
77 else:
78 raise Exception("Toaster cannot start without build environments. Aborting.")
79
80 61
81 # we make sure we have builddir and sourcedir for all defined build envionments 62 # we make sure we have builddir and sourcedir for all defined build envionments
82 for be in BuildEnvironment.objects.all(): 63 for be in BuildEnvironment.objects.all():
83 be.needs_import = False 64 be.needs_import = False
84 def _verify_be(): 65 def _verify_be():
85 is_changed = False 66 is_changed = False
86 print("\nVerifying the build environment. If the local build environment is not properly configured, you will be asked to configure it.")
87 67
88 def _update_sourcedir(): 68 def _update_sourcedir():
89 suggesteddir = self._get_suggested_sourcedir(be) 69 be.sourcedir = os.environ.get('TOASTER_DIR')
90 if len(suggesteddir) > 0:
91 be.sourcedir = raw_input("This is the directory Toaster uses to check out the source code of the layers you will build. Toaster will create new clones of the layers, so existing content in the chosen directory will not be changed.\nToaster suggests you use \"%s\" as your layers checkout directory. If you select this directory, a layer like \"meta-intel\" will end up in \"%s/meta-intel\".\nPress Enter to select \"%s\" or type the full path to a different directory. If you provide your own directory, it must be a parent of the cloned directory for the sources you are using to run Toaster: " % (suggesteddir, suggesteddir, suggesteddir))
92 else:
93 be.sourcedir = raw_input("Toaster needs to know in which directory it should check out the source code of the layers you will build. The directory should be a parent of the cloned directory for the sources you are using to run Toaster. Toaster will create new clones of the layers, so existing content in the chosen directory will not be changed.\nType the full path to the directory (for example: \"%s\": " % os.environ.get('HOME', '/tmp/'))
94 if len(be.sourcedir) == 0 and len(suggesteddir) > 0:
95 be.sourcedir = suggesteddir
96 return True 70 return True
97 71
98 if len(be.sourcedir) == 0: 72 if len(be.sourcedir) == 0:
@@ -103,23 +77,13 @@ class Command(NoArgsCommand):
103 print "\n -- Validation: The layers checkout directory must be set to an absolute path." 77 print "\n -- Validation: The layers checkout directory must be set to an absolute path."
104 is_changed = _update_sourcedir() 78 is_changed = _update_sourcedir()
105 79
106 if not be.sourcedir in DN(__file__):
107 print "\n -- Validation: The layers checkout directory must be a parent of the current checkout."
108 is_changed = _update_sourcedir()
109
110 if is_changed: 80 if is_changed:
111 if be.betype == BuildEnvironment.TYPE_LOCAL: 81 if be.betype == BuildEnvironment.TYPE_LOCAL:
112 be.needs_import = True 82 be.needs_import = True
113 return True 83 return True
114 84
115 def _update_builddir(): 85 def _update_builddir():
116 suggesteddir = self._get_suggested_builddir(be) 86 be.builddir = os.environ.get('TOASTER_DIR')+"/build"
117 if len(suggesteddir) > 0:
118 be.builddir = raw_input("Toaster needs to know where your build directory is located.\nThe build directory is where all the artifacts created by your builds will be stored. Toaster suggests \"%s\".\nPress Enter to select \"%s\" or type the full path to a different directory: " % (suggesteddir, suggesteddir))
119 else:
120 be.builddir = raw_input("Toaster needs to know where is your build directory.\nThe build directory is where all the artifacts created by your builds will be stored. Type the full path to the directory (for example: \" %s/build\")" % os.environ.get('HOME','/tmp/'))
121 if len(be.builddir) == 0 and len(suggesteddir) > 0:
122 be.builddir = suggesteddir
123 return True 87 return True
124 88
125 if len(be.builddir) == 0: 89 if len(be.builddir) == 0:
@@ -138,79 +102,51 @@ class Command(NoArgsCommand):
138 102
139 103
140 if be.needs_import: 104 if be.needs_import:
141 print "\nToaster can use a SINGLE predefined configuration file to set up default project settings and layer information sources.\n" 105 try:
142 106 config_file = os.environ.get('TOASTER_CONF')
143 # find configuration files 107 print "\nImporting file: %s" % config_file
144 config_files = [] 108 from loadconf import Command as LoadConfigCommand
145 for dirname in self._recursive_list_directories(be.sourcedir,2): 109
146 if os.path.exists(os.path.join(dirname, ".templateconf")): 110 LoadConfigCommand()._import_layer_config(config_file)
147 import subprocess 111 # we run lsupdates after config update
148 proc = subprocess.Popen('bash -c ". '+os.path.join(dirname, ".templateconf")+'; echo \"\$TEMPLATECONF\""', shell=True, stdout=subprocess.PIPE) 112 print "\nLayer configuration imported. Updating information from the layer sources, please wait.\nYou can re-update any time later by running bitbake/lib/toaster/manage.py lsupdates"
149 conffilepath, stderroroutput = proc.communicate() 113 from django.core.management import call_command
150 proc.wait() 114 call_command("lsupdates")
151 if proc.returncode != 0: 115
152 raise Exception("Failed to source TEMPLATECONF: %s" % stderroroutput) 116 # we don't look for any other config files
153 117 return is_changed
154 conffilepath = os.path.join(conffilepath.strip(), "toasterconf.json") 118 except Exception as e:
155 candidatefilepath = os.path.join(dirname, conffilepath) 119 print "Failure while trying to import the toaster config file %s: %s" %\
156 if "toaster_cloned" in candidatefilepath: 120 (config_file, e)
157 continue 121 traceback.print_exc(e)
158 if os.path.exists(candidatefilepath):
159 config_files.append(candidatefilepath)
160
161 if len(config_files) > 0:
162 print "Toaster will list now the configuration files that it found. Select the number to use the desired configuration file."
163 for cf in config_files:
164 print " [%d] - %s" % (config_files.index(cf) + 1, cf)
165 print "\n [0] - Exit without importing any file"
166 try:
167 i = raw_input("\nEnter your option: ")
168 if len(i) and (int(i) - 1 >= 0 and int(i) - 1 < len(config_files)):
169 print "\nImporting file: %s" % config_files[int(i)-1]
170 from loadconf import Command as LoadConfigCommand
171
172 LoadConfigCommand()._import_layer_config(config_files[int(i)-1])
173 # we run lsupdates after config update
174 print "\nLayer configuration imported. Updating information from the layer sources, please wait.\nYou can re-update any time later by running bitbake/lib/toaster/manage.py lsupdates"
175 from django.core.management import call_command
176 call_command("lsupdates")
177
178 # we don't look for any other config files
179 return is_changed
180 except Exception as e:
181 print "Failure while trying to import the toaster config file: %s" % e
182 traceback.print_exc(e)
183 else:
184 print "\nToaster could not find a configuration file. You need to configure Toaster manually using the web interface, or create a configuration file and use\n bitbake/lib/toaster/managepy.py loadconf [filename]\n command to load it. You can use https://wiki.yoctoproject.org/wiki/File:Toasterconf.json.txt.patch as a starting point."
185
186
187
188 122
189 return is_changed 123 return is_changed
190 124
191 while (_verify_be()): 125 while _verify_be():
192 pass 126 pass
193 return 0 127 return 0
194 128
195 def _verify_default_settings(self): 129 def _verify_default_settings(self):
196 # verify that default settings are there 130 # verify that default settings are there
197 if ToasterSetting.objects.filter(name = 'DEFAULT_RELEASE').count() != 1: 131 if ToasterSetting.objects.filter(name='DEFAULT_RELEASE').count() != 1:
198 ToasterSetting.objects.filter(name = 'DEFAULT_RELEASE').delete() 132 ToasterSetting.objects.filter(name='DEFAULT_RELEASE').delete()
199 ToasterSetting.objects.get_or_create(name = 'DEFAULT_RELEASE', value = '') 133 ToasterSetting.objects.get_or_create(name='DEFAULT_RELEASE', value='')
200 return 0 134 return 0
201 135
202 def _verify_builds_in_progress(self): 136 def _verify_builds_in_progress(self):
203 # we are just starting up. we must not have any builds in progress, or build environments taken 137 # we are just starting up. we must not have any builds in progress, or build environments taken
204 for b in BuildRequest.objects.filter(state = BuildRequest.REQ_INPROGRESS): 138 for b in BuildRequest.objects.filter(state=BuildRequest.REQ_INPROGRESS):
205 BRError.objects.create(req = b, errtype = "toaster", errmsg = "Toaster found this build IN PROGRESS while Toaster started up. This is an inconsistent state, and the build was marked as failed") 139 BRError.objects.create(req=b, errtype="toaster",
140 errmsg=
141 "Toaster found this build IN PROGRESS while Toaster started up. This is an inconsistent state, and the build was marked as failed")
206 142
207 BuildRequest.objects.filter(state = BuildRequest.REQ_INPROGRESS).update(state = BuildRequest.REQ_FAILED) 143 BuildRequest.objects.filter(state=BuildRequest.REQ_INPROGRESS).update(state=BuildRequest.REQ_FAILED)
208 144
209 BuildEnvironment.objects.update(lock = BuildEnvironment.LOCK_FREE) 145 BuildEnvironment.objects.update(lock=BuildEnvironment.LOCK_FREE)
210 146
211 # also mark "In Progress builds as failures" 147 # also mark "In Progress builds as failures"
212 from django.utils import timezone 148 from django.utils import timezone
213 Build.objects.filter(outcome = Build.IN_PROGRESS).update(outcome = Build.FAILED, completed_on = timezone.now()) 149 Build.objects.filter(outcome=Build.IN_PROGRESS).update(outcome=Build.FAILED, completed_on=timezone.now())
214 150
215 return 0 151 return 0
216 152