Example #1
0
def create_or_edit(sheet):
    """ Creates or edits a cheatsheet """

    # if the cheatsheet does not exist
    if not exists(sheet):
        create(sheet)
    
    # if the cheatsheet exists and is writeable...
    elif exists(sheet) and is_writable(sheet):
        edit(sheet)

    # if the cheatsheet exists but is not writable...
    elif exists(sheet) and not is_writable(sheet):
        # ... ask the user if we should copy the cheatsheet to her home directory for 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))
            edit(sheet)

        # if no, just abort
        else:
            die('Aborting.')
Example #2
0
def create_or_edit(sheet):
    """ Creates or edits a cheatsheet """

    # if the cheatsheet does not exist
    if not exists(sheet):
        create(sheet)
    
    # if the cheatsheet exists and is writeable...
    elif exists(sheet) and is_writable(sheet):
        edit(sheet)

    # if the cheatsheet exists but is not writable...
    elif exists(sheet) and not is_writable(sheet):
        # ... ask the user if we should copy the cheatsheet to her home directory for 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))
            edit(sheet)

        # if no, just abort
        else:
            die('Aborting.')
Example #3
0
def create(sheet):
    """ Creates a cheatsheet """
    new_sheet_path = os.path.join(sheets.default_path(), sheet)

    try:
        subprocess.call([editor(), new_sheet_path])

    except OSError:
        die('Could not launch ' + editor())
Example #4
0
def create(sheet):
    """ Creates a cheatsheet """
    new_sheet_path = os.path.join(sheets.default_path(), sheet)

    try:
        subprocess.call([editor(), new_sheet_path])

    except OSError:
        die('Could not launch ' + editor())
Example #5
0
def create_or_edit(sheet):
    """ Creates or edits a cheatsheet """

    # if the cheatsheet does not exist
    if not exists(sheet):
        create(sheet)

    # if the cheatsheet exists but not in the default_path, copy it to the
    # default path before editing
    elif exists(sheet) and not exists_in_default_path(sheet):
        copy(path(sheet), os.path.join(sheets.default_path(), sheet))
        edit(sheet)

    # if it exists and is in the default path, then just open it
    else:
        edit(sheet)
Example #6
0
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)
Example #7
0
def create(sheet):
    """ Creates a cheatsheet """
    new_sheet_path = os.path.join(sheets.default_path(), sheet)
    open_with_editor(new_sheet_path)