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:
Chris Lane 2014-04-27 00:28:28 -04:00
parent f46698b656
commit bb6f1018a6
3 changed files with 23 additions and 3 deletions

View File

@ -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']:

View File

@ -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

View File

@ -3,7 +3,7 @@ import os
setup(
name = 'cheat',
version = '2.0.0',
version = '2.0.1',
author = 'Chris Lane',
author_email = 'chris@chris-allen-lane.com',
license = 'GPL3',