Merge pull request #210 from chrisallenlane/issue-180

Issue #180
This commit is contained in:
Chris Lane 2015-02-11 21:05:12 -05:00
commit d14c759a48
3 changed files with 11 additions and 9 deletions

View File

@ -38,7 +38,7 @@ from docopt import docopt
if __name__ == '__main__': if __name__ == '__main__':
# parse the command-line options # parse the command-line options
options = docopt(__doc__, version='cheat 2.1.5') options = docopt(__doc__, version='cheat 2.1.6')
# list directories # list directories
if options['--directories']: if options['--directories']:

View File

@ -26,13 +26,9 @@ def create_or_edit(sheet):
if not exists(sheet): if not exists(sheet):
create(sheet) create(sheet)
# if the cheatsheet exists and is writeable... # if the cheatsheet exists but not in the default_path, copy it to the
elif exists(sheet) and is_writable(sheet): # default path before editing
edit(sheet) elif exists(sheet) and not exists_in_default_path(sheet):
# if the cheatsheet exists but is not writable...
elif exists(sheet) and not is_writable(sheet):
# copy the cheatsheet to the home directory before editing
copy(path(sheet), os.path.join(sheets.default_path(), sheet)) copy(path(sheet), os.path.join(sheets.default_path(), sheet))
edit(sheet) edit(sheet)
@ -63,6 +59,12 @@ def exists(sheet):
return sheet in sheets.get() and os.access(path(sheet), os.R_OK) return sheet in sheets.get() and os.access(path(sheet), os.R_OK)
def exists_in_default_path(sheet):
""" Predicate that returns true if the sheet exists in default_path"""
default_path_sheet = os.path.join(sheets.default_path(), sheet)
return sheet in sheets.get() and os.access(default_path_sheet, os.R_OK)
def is_writable(sheet): def is_writable(sheet):
""" Predicate that returns true if the sheet is writeable """ """ Predicate that returns true if the sheet is writeable """
return sheet in sheets.get() and os.access(path(sheet), os.W_OK) return sheet in sheets.get() and os.access(path(sheet), os.W_OK)

View File

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