Loading sbws/core/init.py +2 −1 Original line number Diff line number Diff line from sbws.globals import (is_initted, fail_hard) from sbws.globals import (is_initted, fail_hard, touch_file) from sbws.util.config import get_user_example_config from argparse import ArgumentDefaultsHelpFormatter import os Loading @@ -23,6 +23,7 @@ def main(args, conf): log.info('Creating %s', args.directory) os.makedirs(args.directory, exist_ok=False) touch_file(os.path.join(args.directory, 'config.log.ini')) config_fname = os.path.join(args.directory, 'config.ini') c = get_user_example_config() c['paths']['sbws_home'] = args.directory Loading sbws/globals.py +18 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,9 @@ def is_initted(d): if not os.path.isdir(d): return False conf_fname = os.path.join(d, 'config.ini') if not os.path.exists(conf_fname): return False conf_fname = os.path.join(d, 'config.log.ini') if not os.path.exists(conf_fname): return False return True Loading Loading @@ -90,3 +93,18 @@ def lock_directory(dname): ''' assert os.path.isdir(dname) return FileLock(os.path.join(dname, 'lockfile')) def touch_file(fname, times=None): ''' If **fname** exists, update its last access and modified times to now. If **fname** does not exist, create it. If **times** are specified, pass them to os.utime for use. :param str fname: Name of file to update or create :param tuple times: 2-tuple of floats for access time and modified time respectively ''' log.debug('Touching %s', fname) with open(fname, 'a') as fd: os.utime(fd.fileno(), times=times) Loading
sbws/core/init.py +2 −1 Original line number Diff line number Diff line from sbws.globals import (is_initted, fail_hard) from sbws.globals import (is_initted, fail_hard, touch_file) from sbws.util.config import get_user_example_config from argparse import ArgumentDefaultsHelpFormatter import os Loading @@ -23,6 +23,7 @@ def main(args, conf): log.info('Creating %s', args.directory) os.makedirs(args.directory, exist_ok=False) touch_file(os.path.join(args.directory, 'config.log.ini')) config_fname = os.path.join(args.directory, 'config.ini') c = get_user_example_config() c['paths']['sbws_home'] = args.directory Loading
sbws/globals.py +18 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,9 @@ def is_initted(d): if not os.path.isdir(d): return False conf_fname = os.path.join(d, 'config.ini') if not os.path.exists(conf_fname): return False conf_fname = os.path.join(d, 'config.log.ini') if not os.path.exists(conf_fname): return False return True Loading Loading @@ -90,3 +93,18 @@ def lock_directory(dname): ''' assert os.path.isdir(dname) return FileLock(os.path.join(dname, 'lockfile')) def touch_file(fname, times=None): ''' If **fname** exists, update its last access and modified times to now. If **fname** does not exist, create it. If **times** are specified, pass them to os.utime for use. :param str fname: Name of file to update or create :param tuple times: 2-tuple of floats for access time and modified time respectively ''' log.debug('Touching %s', fname) with open(fname, 'a') as fd: os.utime(fd.fileno(), times=times)