Patchwork [bitbake-devel,17/94] bitbake: buildinfohelper: clean-up the imports

login
register
mail settings
Submitter Alexandru DAMIAN
Date Sept. 24, 2013, 4:51 p.m.
Message ID <fc38c7d663057cc9830787977175c389fb181e06.1380041477.git.alexandru.damian@intel.com>
Download mbox | patch
Permalink /patch/58723/
State New
Headers show

Comments

Alexandru DAMIAN - Sept. 24, 2013, 4:51 p.m.
From: Alexandru DAMIAN <alexandru.damian@intel.com>

As per convention, we do all imports at the beginning of file.

Also, globally set Django settings in the Django interface file.

Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
---
 bitbake/lib/bb/ui/buildinfohelper.py | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

Patch

diff --git a/bitbake/lib/bb/ui/buildinfohelper.py b/bitbake/lib/bb/ui/buildinfohelper.py
index e12750e..f7f98d8 100644
--- a/bitbake/lib/bb/ui/buildinfohelper.py
+++ b/bitbake/lib/bb/ui/buildinfohelper.py
@@ -3,6 +3,11 @@  import sys
 import uuid
 
 
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "webhob.whbmain.settings")
+
+import webhob.whbmain.settings as whb_django_settings
+from webhob.orm.models import Machine, Build, Task, Recipe, Build_Layer, Layer
+
 class ORMWrapper(object):
     """ This class creates the dictionaries needed to store information in the database
         following the format defined by the Django models. It is also used to save this
@@ -27,7 +32,6 @@  class ORMWrapper(object):
 
     def create_machine_object(self, machine_information):
         # This needs to be imported after we have configured the Django settings file
-        from webhob.orm.models import Machine
 
         machine = Machine.objects.get_or_create(name=machine_information['name'],
                                                 description=machine_information['description'])
@@ -59,7 +63,6 @@  class ORMWrapper(object):
 
     def create_build_object(self, build_info):
         # This needs to be imported after we have configured the Django settings file
-        from webhob.orm.models import Build
 
         build = Build.objects.create(uuid=build_info['uuid'],
                                     target=build_info['target'],
@@ -80,7 +83,6 @@  class ORMWrapper(object):
 
     def update_build_object(self, build_obj, errors, warnings, taskfailures):
         # This needs to be imported after we have configured the Django settings file
-        from webhob.orm.models import Build
 
         outcome = 0
         if errors or taskfailures:
@@ -128,8 +130,6 @@  class ORMWrapper(object):
 
     def create_task_object(self, task_information):
         # This needs to be imported after we have configured the Django settings file
-        from webhob.orm.models import Task
-
         identifier = task_information['recipe'].name + task_information['task_name']
 
         task_object = Task.objects.get_or_create(
@@ -262,7 +262,6 @@  class ORMWrapper(object):
 
     def get_recipe_object(self, event):
         # This needs to be imported after we have configured the Django settings file
-        from webhob.orm.models import Recipe
 
         recipe_information = self.get_recipe_information(event)
 
@@ -305,7 +304,6 @@  class ORMWrapper(object):
 
     def get_build_layer_object(self, event):
         # This needs to be imported after we have configured the Django settings file
-        from webhob.orm.models import Build_Layer
 
         build_layer_information = self.get_build_layer_information(event)
 
@@ -334,7 +332,6 @@  class ORMWrapper(object):
 
     def get_layer_object(self, event):
         # This needs to be imported after we have configured the Django settings file
-        from webhob.orm.models import Layer
 
         layer_information = self.get_layer_information(event)
 
@@ -366,8 +363,6 @@  class BuildInfoHelper(object):
         self.orm_wrapper = ORMWrapper(server)
 
     def configure_django(self):
-        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "webhob.whbmain.settings")
-        import webhob.whbmain.settings as whb_django_settings
         # Add webhob to sys path for importing modules
         sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'webhob'))