Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Narvaez <dwnarvaez@gmail.com>2012-12-28 16:44:06 (GMT)
committer Daniel Narvaez <dwnarvaez@gmail.com>2012-12-28 16:44:06 (GMT)
commit08c27487173faf6a86b5fe20e6b545033b6d1638 (patch)
tree6b412c3c7bd0f7d72ad3c5d20221b740778c63bd
parent542477741abe0135c652a78911a0eb9aec9b1a19 (diff)
Rework initialization
To avoid duplicatin environ setup calls.
-rw-r--r--commands/common.py27
-rw-r--r--devbot/build.py11
-rw-r--r--devbot/config.py11
-rw-r--r--devbot/main.py18
-rw-r--r--devbot/run.py5
-rw-r--r--devbot/shell.py4
-rw-r--r--devbot/test.py5
-rw-r--r--tests/devbot/common.py3
8 files changed, 31 insertions, 53 deletions
diff --git a/commands/common.py b/commands/common.py
index a7e16d1..4091545 100644
--- a/commands/common.py
+++ b/commands/common.py
@@ -5,23 +5,16 @@ base_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
sys.path.append(base_dir)
-from devbot import config
-from devbot import git
+from devbot import main
def setup(log_name=None):
- args = {"config_dir": os.path.join(base_dir, "config"),
- "install_dir": os.path.join(base_dir, "install"),
- "source_dir": os.path.join(base_dir, "source"),
- "build_dir": os.path.join(base_dir, "build"),
- "state_dir": os.path.join(base_dir, "state"),
- "prefs_path": os.path.join(base_dir, "prefs"),
- "logs_dir": os.path.join(base_dir, "logs")}
-
- if log_name:
- args["log_name"] = log_name
-
- if "SUGAR_BUILDBOT" in os.environ:
- args["relocatable"] = True
-
- config.setup(**args)
+ main.setup({"config_dir": os.path.join(base_dir, "config"),
+ "install_dir": os.path.join(base_dir, "install"),
+ "source_dir": os.path.join(base_dir, "source"),
+ "build_dir": os.path.join(base_dir, "build"),
+ "state_dir": os.path.join(base_dir, "state"),
+ "prefs_path": os.path.join(base_dir, "prefs"),
+ "logs_dir": os.path.join(base_dir, "logs"),
+ "relocatable": "SUGAR_BUILDBOT" in os.environ,
+ "log_name": log_name})
diff --git a/devbot/build.py b/devbot/build.py
index c83c15a..6380c6e 100644
--- a/devbot/build.py
+++ b/devbot/build.py
@@ -8,7 +8,6 @@ from distutils.sysconfig import parse_makefile
from devbot import command
from devbot import config
-from devbot import environ
from devbot import state
from devbot import utils
from devbot import release
@@ -19,8 +18,6 @@ _distributors = {}
def build_one(module_name):
- environ.setup()
-
for module in config.load_modules():
if module.name == module_name:
return _build_module(module)
@@ -29,8 +26,6 @@ def build_one(module_name):
def pull_one(module_name):
- environ.setup()
-
for module in config.load_modules():
if module.name == module_name:
return _pull_module(module)
@@ -39,8 +34,6 @@ def pull_one(module_name):
def pull(lazy=False):
- environ.setup()
-
to_pull = []
for module in config.load_modules():
git_module = git.get_module(module)
@@ -62,8 +55,6 @@ def build(full=False):
state.clean(build_only=True)
clean()
- environ.setup()
-
state.full_build_touch()
pull(lazy=True)
@@ -90,8 +81,6 @@ def build(full=False):
def distribute():
- environ.setup()
-
for module in config.load_modules():
if module.distribute:
if not _distribute_module(module):
diff --git a/devbot/config.py b/devbot/config.py
index 936b183..e3782f2 100644
--- a/devbot/config.py
+++ b/devbot/config.py
@@ -1,11 +1,8 @@
-import imp
import json
import os
-import pkgutil
import tempfile
from devbot import distro
-from devbot import plugins
from devbot import utils
config_dir = None
@@ -64,8 +61,6 @@ class Module:
def setup(**kwargs):
- _load_plugins()
-
global config_dir
config_dir = kwargs.get("config_dir", None)
@@ -192,12 +187,6 @@ def _filter_if(item):
return eval(item["if"], globals)
-def _load_plugins():
- for loader, name, ispkg in pkgutil.iter_modules(plugins.__path__):
- f, filename, desc = imp.find_module(name, plugins.__path__)
- imp.load_module(name, f, filename, desc)
-
-
def _read_index(dir_name):
if config_dir is None:
return []
diff --git a/devbot/main.py b/devbot/main.py
new file mode 100644
index 0000000..3e14a72
--- /dev/null
+++ b/devbot/main.py
@@ -0,0 +1,18 @@
+import pkgutil
+import imp
+
+from devbot import config
+from devbot import environ
+from devbot import plugins
+
+
+def load_plugins():
+ for loader, name, ispkg in pkgutil.iter_modules(plugins.__path__):
+ f, filename, desc = imp.find_module(name, plugins.__path__)
+ imp.load_module(name, f, filename, desc)
+
+
+def setup(config_args):
+ load_plugins()
+ config.setup(**config_args)
+ environ.setup()
diff --git a/devbot/run.py b/devbot/run.py
index 8f55d65..08ebe94 100644
--- a/devbot/run.py
+++ b/devbot/run.py
@@ -6,13 +6,10 @@ import sys
import time
import tempfile
-from devbot import environ
from devbot import config
def run(command):
- environ.setup()
-
args = [command, "--home-dir", config.home_dir]
resolution = config.get_pref("RESOLUTION")
@@ -33,8 +30,6 @@ def run(command):
def run_test(command, test_path):
- environ.setup()
-
temp_dir = tempfile.mkdtemp("sugar-build-test")
display_path = os.path.join(temp_dir, "display")
diff --git a/devbot/shell.py b/devbot/shell.py
index be2730d..0b00c95 100644
--- a/devbot/shell.py
+++ b/devbot/shell.py
@@ -2,11 +2,7 @@
import os
-from devbot import environ
-
def start(rcfile):
- environ.setup()
-
bash_path = "/bin/bash"
os.execlp(bash_path, bash_path, "--rcfile", rcfile)
diff --git a/devbot/test.py b/devbot/test.py
index fefb91a..d3bd0a0 100644
--- a/devbot/test.py
+++ b/devbot/test.py
@@ -2,14 +2,11 @@ import os
import subprocess
from devbot import config
-from devbot import environ
from devbot import command
from devbot import xvfb
def test_one(module_name):
- environ.setup()
-
for module in config.load_modules():
if module.name == module_name:
return _test_module(module)
@@ -18,8 +15,6 @@ def test_one(module_name):
def test():
- environ.setup()
-
modules = config.load_modules()
for module in modules:
if not _test_module(module):
diff --git a/tests/devbot/common.py b/tests/devbot/common.py
index 548bd3e..1a48673 100644
--- a/tests/devbot/common.py
+++ b/tests/devbot/common.py
@@ -3,6 +3,7 @@ import unittest
import tempfile
from devbot import config
+from devbot import main
class DevbotTestCase(unittest.TestCase):
@@ -12,6 +13,8 @@ class DevbotTestCase(unittest.TestCase):
def setup_config(self, extra_args):
temp_dir = tempfile.gettempdir()
+ main.load_plugins()
+
args = {"logs_dir": os.path.join(temp_dir, "logs"),
"source_dir": os.path.join(temp_dir, "source"),
"build_dir": os.path.join(temp_dir, "build"),