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))
, i.e. "native", locations with the help of the appdirs utility. For example, shared data files on Linux are placed in "/usr/local/share/openvisualizer". We use the site-level data and config directories because we expect the superuser to run OpenVisualizer, so user-level directories like "/home/<user>/.config" are not available. For native file storage to work, the installer *must not* modify the location of these files at install time. Use of the legacy distutils package also accommodates existing Linux packaging tools. ''' VERSION = '.'.join([str(v) for v in ovVersion.VERSION]) datadir = appdirs.site_data_dir('openvisualizer', 'OpenWSN') confdir = appdirs.site_config_dir('openvisualizer', 'OpenWSN') webstatic = 'web_files/static' webtmpl = 'web_files/templates' simdata = 'sim_files' with open('README.txt') as f: LONG_DESCRIPTION = f.read() def appdirGlob(globstr, subdir=''): appdir = 'bin/openVisualizerApp' if subdir == '': return glob.glob('/'.join([appdir, globstr])) else: return glob.glob('/'.join([appdir, subdir, globstr]))
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))