mirror of
https://github.com/Erreur32/cheat.git
synced 2024-12-23 06:02:12 +01:00
Merge pull request #209 from chrisallenlane/edit-after-copy
Resolves #207
This commit is contained in:
commit
ff8ba4e717
5 changed files with 7 additions and 29 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
*.pyc
|
*.pyc
|
||||||
MANIFEST
|
MANIFEST
|
||||||
build
|
build
|
||||||
|
cheat.egg-info
|
||||||
dist
|
dist
|
||||||
|
|
|
@ -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.4')
|
options = docopt(__doc__, version='cheat 2.1.5')
|
||||||
|
|
||||||
# list directories
|
# list directories
|
||||||
if options['--directories']:
|
if options['--directories']:
|
||||||
|
|
|
@ -32,22 +32,10 @@ def create_or_edit(sheet):
|
||||||
|
|
||||||
# if the cheatsheet exists but is not writable...
|
# if the cheatsheet exists but is not writable...
|
||||||
elif exists(sheet) and not is_writable(sheet):
|
elif exists(sheet) and not is_writable(sheet):
|
||||||
# ... ask the user if we should copy the cheatsheet to her home directory for editing
|
# copy the cheatsheet to the home directory before editing
|
||||||
yes = prompt_yes_or_no(
|
|
||||||
'The ' + sheet + ' sheet is not editable. Do you want to copy it to '
|
|
||||||
'your user cheatsheets directory before editing? Keep in mind that '
|
|
||||||
'your sheet will always be used before system-wide one.'
|
|
||||||
)
|
|
||||||
|
|
||||||
# if yes, copy the cheatsheet to the home directory before editing
|
|
||||||
if yes:
|
|
||||||
copy(path(sheet), os.path.join(sheets.default_path(), sheet))
|
copy(path(sheet), os.path.join(sheets.default_path(), sheet))
|
||||||
edit(sheet)
|
edit(sheet)
|
||||||
|
|
||||||
# if no, just abort
|
|
||||||
else:
|
|
||||||
die('Aborting.')
|
|
||||||
|
|
||||||
|
|
||||||
def create(sheet):
|
def create(sheet):
|
||||||
""" Creates a cheatsheet """
|
""" Creates a cheatsheet """
|
||||||
|
|
|
@ -2,13 +2,6 @@ from cheat import cheatsheets
|
||||||
from cheat.utils import *
|
from cheat.utils import *
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# @kludge: it breaks the functional paradigm to a degree, but declaring this
|
|
||||||
# var here (versus within get()) gives us a "poor man's" memoization on the
|
|
||||||
# call to get(). This, in turn, spares us from having to call out to the
|
|
||||||
# filesystem more than once.
|
|
||||||
cheats = {}
|
|
||||||
|
|
||||||
|
|
||||||
def default_path():
|
def default_path():
|
||||||
""" Returns the default cheatsheet path """
|
""" Returns the default cheatsheet path """
|
||||||
|
|
||||||
|
@ -37,11 +30,7 @@ def default_path():
|
||||||
|
|
||||||
def get():
|
def get():
|
||||||
""" Assembles a dictionary of cheatsheets as name => file-path """
|
""" Assembles a dictionary of cheatsheets as name => file-path """
|
||||||
|
cheats = {}
|
||||||
# if we've already reached out to the filesystem, just return the result
|
|
||||||
# from memory
|
|
||||||
if cheats:
|
|
||||||
return cheats
|
|
||||||
|
|
||||||
# otherwise, scan the filesystem
|
# otherwise, scan the filesystem
|
||||||
for cheat_dir in reversed(paths()):
|
for cheat_dir in reversed(paths()):
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -3,7 +3,7 @@ import os
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name = 'cheat',
|
name = 'cheat',
|
||||||
version = '2.1.4',
|
version = '2.1.5',
|
||||||
author = 'Chris Lane',
|
author = 'Chris Lane',
|
||||||
author_email = 'chris@chris-allen-lane.com',
|
author_email = 'chris@chris-allen-lane.com',
|
||||||
license = 'GPL3',
|
license = 'GPL3',
|
||||||
|
|
Loading…
Reference in a new issue