diff --git a/bin/cheat b/bin/cheat index 65dada2..c1ff5a6 100755 --- a/bin/cheat +++ b/bin/cheat @@ -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']: diff --git a/cheat/sheets.py b/cheat/sheets.py index 82cdb3d..bbcc373 100644 --- a/cheat/sheets.py +++ b/cheat/sheets.py @@ -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 diff --git a/setup.py b/setup.py index 20ab22d..b6def97 100644 --- a/setup.py +++ b/setup.py @@ -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',