#!/usr/bin/env python # -*- coding: utf-8 -*- """ overlay.py ~~~~~~~~~~ This module implements a function to create an overlay to host the ebuilds generated by g-octave. :copyright: (c) 2009-2010 by Rafael Goncalves Martins :license: GPL-2, see LICENSE for more details. """ __all__ = ['create_overlay'] import os import sys import shutil import portage.output from config import Config from exception import ConfigException out = portage.output.EOutput() def create_overlay(force=False, conf=None, quiet=False): # the function parameter conf is used by the tests if conf is None: conf = Config() if force and os.path.exists(conf.overlay): shutil.rmtree(conf.overlay) if not os.path.exists(os.path.join(conf.overlay, 'profiles', 'repo_name')): if not quiet: out.ebegin('Creating overlay: %s' % conf.overlay) try: # creating dirs for _dir in ['profiles', 'eclass']: dir = os.path.join(conf.overlay, _dir) if not os.path.exists(dir) or force: os.makedirs(dir, 0755) # creating files files = { os.path.join(conf.overlay, 'profiles', 'repo_name'): 'g-octave', os.path.join(conf.overlay, 'profiles', 'categories'): 'g-octave', } # stuff to run tests :( aux = os.path.join(conf.overlay, 'eclass', 'octave-forge.eclass') try: files[aux] = open(os.path.join(conf.db, conf.cache['octave-forge.eclass'])) except ConfigException: files[aux] = '' for _file in files: if not os.path.exists(_file) or force: with open(_file, 'w', 0644) as fp: content = files[_file] if isinstance(content, file): content = content.read() fp.write(content) except Exception, error: if not quiet: out.eend(1) sys.exit(1) else: if not quiet: out.eend(0)