Exemplo n.º 1
0
def err(errmsg='',errcode=1):
    defaults = cct._util.Globals().getDefaults()
    use_colors = 'disabled'
    if defaults and defaults.has_option('Project','use_colors'): 
        use_colors = re.split('\W+',defaults.get('Project','use_colors'))[0]
    if use_colors == 'enabled':
        print >>sys.stderr, '\033[1;31m' + 'Bocca ERROR: ' + '\033[0m' + errmsg
    else: 
        print >>sys.stderr, 'Bocca ERROR: ' + errmsg
    if 'BOCCA_DEBUG' in os.environ.keys() and os.environ['BOCCA_DEBUG'] == '1': 
        traceback.print_stack()
    fm = BFileManager()
    fm.undo()   # Restore files to original state (created files deleted, modified files restored from backups
    fm.close()  # Just in case
    sys.exit(errcode)
Exemplo n.º 2
0
""" Various utilities that don't fit elsewhere
"""
import os, stat, shutil, re

from cct._debug import *
from cct._err import *

#---------------------------------------------------------------------------
# Global singleton variables:

# File manager (singleton) -- use this to open all files to make actions undoable
from cct._file import BFileManager
fileManager = BFileManager()

#----- end global singleton variables:

def Globals():
    '''Helper function to ensure exactly one instance of the Globals_singleton class exists'''
    myglobals = None
    try:
        myglobals = Globals_Singleton()
    except Globals_Singleton, s:
        myglobals = s
    return myglobals

class Globals_Singleton:
    '''A singleton class in which to stash various useful global variables for bocca.
    Do not instantiate this class directly, rather use the Globals helper function,
    e.g., myglobals = Globals().
    '''
    __single = None  # Used for ensuring singleton instance
Exemplo n.º 3
0
def exit(msg=''): 
    if msg != '': print >>sys.stdout, msg  
    fm = BFileManager()
    fm.close()
    sys.exit(0)