Files
codezero/config/configuration.py
Bahadir Balban 403ab75805 Got the buildsystem to build multiple linux instances.
modified:   config/configuration.py
	modified:   config/projpaths.py
	modified:   configure.py
	modified:   scripts/linux/build_linux.py
	modified:   scripts/linux/build_rootfs.py
2009-09-13 18:29:57 +03:00

137 lines
4.3 KiB
Python

#! /usr/bin/env python2.6
# -*- mode: python; coding: utf-8; -*-
import os, sys, shelve, shutil, re
from projpaths import *
class Container:
name = None
type = None
id = None
lma_start = None
lma_end = None
vma_start = None
vma_end = None
class configuration:
arch = None
subarch = None
platform = None
all = []
containers = []
# Get all name value symbols
def get_all(self, name, val):
self.all.append([name, val])
# Convert line to name value pair, if possible
def line_to_name_value(self, line):
parts = line.split()
if len(parts) > 0:
if parts[0] == "#define":
return parts[1], parts[2]
return None
# Extract architecture from a name value pair
def get_arch(self, name, val):
if name[:len("CONFIG_ARCH_")] == "CONFIG_ARCH_":
parts = name.split("_", 3)
self.arch = parts[2].lower()
# Extract subarch from a name value pair
def get_subarch(self, name, val):
if name[:len("CONFIG_SUBARCH_")] == "CONFIG_SUBARCH_":
parts = name.split("_", 3)
self.subarch = parts[2].lower()
# Extract platform from a name value pair
def get_platform(self, name, val):
if name[:len("CONFIG_PLATFORM_")] == "CONFIG_PLATFORM_":
parts = name.split("_", 3)
self.platform = parts[2].lower()
# Extract number of containers
def get_ncontainers(self, name, val):
if name[:len("CONFIG_CONTAINERS")] == "CONFIG_CONTAINERS":
self.ncontainers = val
# TODO: Carry this over to Container() as static method???
def get_container_parameter(self, id, param, val):
if param[:len("VIRT_START")] == "VIRT_START":
self.containers[id].vma_start = val
elif param[:len("VIRT_END")] == "VIRT_END":
self.containers[id].vma_end = val
elif param[:len("PHYS_START")] == "PHYS_START":
self.containers[id].lma_start = val
elif param[:len("PHYS_END")] == "PHYS_END":
self.containers[id].lma_end = val
else:
param1, param2 = param.split("_", 2)
if param1 == "TYPE":
if param2 == "LINUX":
self.containers[id].type = "linux"
elif param2 == "C0_POSIX":
self.containers[id].type = "cps"
elif param2 == "BARE":
self.containers[id].type = "bare"
# Extract parameters for containers
def get_container_parameters(self, name, val):
matchobj = re.match(r"(CONFIG_CONT){1}([0-9]){1}(\w+)", name)
if not matchobj:
return None
prefix, idstr, param = matchobj.groups()
id = int(idstr)
# Create and add new container if this id was not seen
self.check_add_container(id)
# Get rid of '_' in front
param = param[1:]
# Check and store info on this parameter
self.get_container_parameter(id, param, val)
def check_add_container(self, id):
for cont in self.containers:
if id == cont.id:
return
# New container created. TODO: Pass id to constructor
container = Container()
container.id = id
self.containers.append(container)
# Make sure elements in order for indexed accessing
self.containers.sort()
def configuration_save(config):
if not os.path.exists(CONFIG_SHELVE_DIR):
os.mkdir(CONFIG_SHELVE_DIR)
config_shelve = shelve.open(CONFIG_SHELVE)
config_shelve["configuration"] = config
# Save containers explicitly
for i, c in zip(range(len(config.containers)), config.containers):
config_shelve["container" + str(i)] = c
# config_shelve["arch"] = configuration.arch
# config_shelve["subarch"] = configuration.subarch
# config_shelve["platform"] = configuration.platform
# config_shelve["all_symbols"] = configuration.all
config_shelve.close()
def configuration_retrieve():
# Get configuration information
config_shelve = shelve.open(CONFIG_SHELVE)
config = config_shelve["configuration"]
# Retrieve and append containers explicitly
for i in range(int(config.ncontainers)):
config.containers.append(config_shelve["container" + str(i)])
config.containers.sort()
return config