mirror of https://github.com/cheat/cheat.git
Bug fix
Previously, cheat would crash if the DEFAULT_CHEAT_DIR was not set. This should resolve that issue by creating the directory if it does not exist.
This commit is contained in:
parent
f46698b656
commit
bb6f1018a6
|
@ -38,7 +38,7 @@ from docopt import docopt
|
|||
|
||||
if __name__ == '__main__':
|
||||
# parse the command-line options
|
||||
options = docopt(__doc__, version='cheat 2.0.0')
|
||||
options = docopt(__doc__, version='cheat 2.0.1')
|
||||
|
||||
# list directories
|
||||
if options['--directories']:
|
||||
|
|
|
@ -12,7 +12,27 @@ def default_path():
|
|||
if os.geteuid() == 0:
|
||||
die('Please do not run this application as root.');
|
||||
|
||||
return os.environ.get('DEFAULT_CHEAT_DIR') or os.path.join(os.path.expanduser('~'), '.cheat')
|
||||
# determine the default cheatsheet dir
|
||||
default_sheets_dir = os.environ.get('DEFAULT_CHEAT_DIR') or os.path.join(os.path.expanduser('~'), '.cheat')
|
||||
|
||||
# create the DEFAULT_CHEAT_DIR if it does not exist
|
||||
if not os.path.isdir(default_sheets_dir):
|
||||
try:
|
||||
# @kludge: unclear on why this is necessary
|
||||
os.umask(0000)
|
||||
os.mkdir(default_sheets_dir)
|
||||
|
||||
except OSError:
|
||||
die('Could not create DEFAULT_CHEAT_DIR')
|
||||
|
||||
# assert that the DEFAULT_CHEAT_DIR is readable and writable
|
||||
if not os.access(default_sheets_dir, os.R_OK):
|
||||
die('The DEFAULT_CHEAT_DIR (' + default_sheets_dir +') is not readable.')
|
||||
if not os.access(default_sheets_dir, os.W_OK):
|
||||
die('The DEFAULT_CHEAT_DIR (' + default_sheets_dir +') is not writeable.')
|
||||
|
||||
# return the default dir
|
||||
return default_sheets_dir
|
||||
|
||||
|
||||
# @todo: memoize result
|
||||
|
|
Loading…
Reference in New Issue