コード例 #1
0
def _initExternalDirs(appdir, debug):    
    '''
    Find and define confdir for config files and datadir for static data. Also
    return logdir for logs. There are several possiblities, searched in the order
    described below.

    1. Provided from command line, appdir parameter
    2. In the directory containing openVisualizerApp.py
    3. In native OS site-wide config and data directories
    4. In the openvisualizer package directory

    The directories differ only when using a native OS site-wide setup.
    
    :param debug: If true, print extra logging info
    :returns: 3-Tuple with config dir, data dir, and log dir
    :raises: RuntimeError if files/directories not found as expected
    '''
    if not appdir == '.':
        if not _verifyConfpath(appdir):
            raise RuntimeError('Config file not in expected directory: {0}'.format(appdir))
        if debug:
            print 'App data found via appdir'
        return appdir, appdir, appdir
    
    filedir = os.path.dirname(__file__)
    if _verifyConfpath(filedir):
        if debug:
            print 'App data found via openVisualizerApp.py'
        return filedir, filedir, filedir
        
    confdir      = appdirs.site_config_dir('openvisualizer', 'OpenWSN')
    # Must use system log dir on Linux since running as superuser.
    linuxLogdir  = '/var/log/openvisualizer'
    if _verifyConfpath(confdir):
        if not sys.platform.startswith('linux'):
            raise RuntimeError('Native OS external directories supported only on Linux')
            
        datadir = appdirs.site_data_dir('openvisualizer', 'OpenWSN')
        logdir  = linuxLogdir
        if os.path.exists(datadir):
            if not os.path.exists(logdir):
                os.mkdir(logdir)
            if debug:
                print 'App data found via native OS'
            return confdir, datadir, logdir
        else:
            raise RuntimeError('Cannot find expected data directory: {0}'.format(datadir))

    datadir = os.path.join(os.path.dirname(u.__file__), 'data')
    if _verifyConfpath(datadir):
        if sys.platform == 'win32':
            logdir = appdirs.user_log_dir('openvisualizer', 'OpenWSN', opinion=False)
        else:
            logdir = linuxLogdir
        if not os.path.exists(logdir):
            # Must make intermediate directories on Windows
            os.makedirs(logdir)
        if debug:
            print 'App data found via openvisualizer package'
            
        return datadir, datadir, logdir
    else:
        raise RuntimeError('Cannot find expected data directory: {0}'.format(datadir))
コード例 #2
0
def _initExternalDirs(appdir, debug):
    '''
    Find and define confdir for config files and datadir for static data. Also
    return logdir for logs. There are several possiblities, searched in the order
    described below.

    1. Provided from command line, appdir parameter
    2. In the directory containing openVisualizerApp.py
    3. In native OS site-wide config and data directories
    4. In the openvisualizer package directory

    The directories differ only when using a native OS site-wide setup.
    
    :param debug: If true, print extra logging info
    :returns: 3-Tuple with config dir, data dir, and log dir
    :raises: RuntimeError if files/directories not found as expected
    '''
    if not appdir == '.':
        if not _verifyConfpath(appdir):
            raise RuntimeError(
                'Config file not in expected directory: {0}'.format(appdir))
        if debug:
            print 'App data found via appdir'
        return appdir, appdir, appdir

    filedir = os.path.dirname(__file__)
    if _verifyConfpath(filedir):
        if debug:
            print 'App data found via openVisualizerApp.py'
        return filedir, filedir, filedir

    confdir = appdirs.site_config_dir('openvisualizer', 'OpenWSN')
    # Must use system log dir on Linux since running as superuser.
    linuxLogdir = '/var/log/openvisualizer'
    if _verifyConfpath(confdir):
        if not sys.platform.startswith('linux'):
            raise RuntimeError(
                'Native OS external directories supported only on Linux')

        datadir = appdirs.site_data_dir('openvisualizer', 'OpenWSN')
        logdir = linuxLogdir
        if os.path.exists(datadir):
            if not os.path.exists(logdir):
                os.mkdir(logdir)
            if debug:
                print 'App data found via native OS'
            return confdir, datadir, logdir
        else:
            raise RuntimeError(
                'Cannot find expected data directory: {0}'.format(datadir))

    datadir = os.path.join(os.path.dirname(u.__file__), 'data')
    if _verifyConfpath(datadir):
        if sys.platform == 'win32':
            logdir = appdirs.user_log_dir('openvisualizer',
                                          'OpenWSN',
                                          opinion=False)
        else:
            logdir = linuxLogdir
        if not os.path.exists(logdir):
            # Must make intermediate directories on Windows
            os.makedirs(logdir)
        if debug:
            print 'App data found via openvisualizer package'

        return datadir, datadir, logdir
    else:
        raise RuntimeError(
            'Cannot find expected data directory: {0}'.format(datadir))