def change_note(args, current_note, data_file): filename = '~/.quicknote/.notes/.' note_name = hf.parse_unary_args(args) filename += note_name filename = path.expanduser(filename) # stop if the note to be changed to is the current note if current_note == filename: print('The note you are trying to change to is already the current note.') return # stop if the user is trying to change to the default note if note_name == 'default': print_default_error() return if not path.isfile(filename): print('Hmmm. The note you entered doesn\'t seem to exist. Please try again.') return if current_note[-7:] == 'default': new_name = input('The current note must be named before changing notes. Please enter a name (ENTER to delete the current note): ') if new_name != '': dot_name = path.expanduser('~/.quicknote/.notes/.' + new_name) return_value = hf.make_note(dot_name, new_name) if return_value == None: return shutil.copyfile(current_note, dot_name) open(current_note, 'w').close() hf.write_to_data_file(data_file, filename) print('Changed current note to \'' + note_name + '\'')
def archive_note(args, current_note, data_file): note_to_archive = hf.parse_unary_args(args) note_path = path.expanduser('~/.quicknote/.notes/.' + note_to_archive) if not path.isfile(note_path): print( 'The note you are trying to archive does not exist. Please try again.' ) return # prevent the user from archiving 'archive' or 'default' if note_to_archive == 'archive' or note_to_archive == 'default': print( '\'archive\' and \'default\' may not be archived. Please try again.' ) return new_path = path.expanduser('~/.quicknote/.archive_notes/.' + note_to_archive) if path.isfile(new_path): print('You already have an archived note named \'' + note_to_archive + '\'. Please try again. (hint: rename something)') return os.rename(note_path, new_path) print('Archived \'' + note_to_archive + '\'') if current_note != 'default': hf.write_to_data_file(data_file, path.expanduser('~/.quicknote/.notes/.default'))
def remove_note(args, current_note, data_file): note_to_remove = hf.parse_unary_args(args) if note_to_remove.lower() == 'archive' or note_to_remove.lower( ) == 'default': print( 'Sorry. The \'default\' and \'archive\' notes cannot be removed. However, they can be cleared of their contents.' ) return prompt = 'Are you sure you want to remove \'' + note_to_remove + '\'?' + BOLD + ' There is no going back (y/n): ' + RESET decision = hf.request_user_permission(prompt) if decision == 'n': print('Note removal aborted') elif decision == 'y': # this probably isn't necessary (i.e. don't need to check, could be an else) note_path_to_remove = path.expanduser('~/.quicknote/.notes/.' + note_to_remove) if path.isfile(note_path_to_remove): os.remove(note_path_to_remove) if current_note == note_to_remove: hf.write_to_data_file( data_file, path.expanduser('~/.quicknote/.notes/.default')) print('Removed note \'' + note_to_remove + '\'') else: print( 'The note you are trying to remove does not exist. Please try again.' )
def make_background_files(): prefix = path.expanduser('~/.quicknote/') data_file = prefix + '.background/data_file.json' default_file = prefix + '.notes/.default' data = {'current_note': ''} with open(data_file, 'w') as initial_open: json.dump(data, initial_open) hf.write_to_data_file(data_file, default_file)
def clear_notes(notes, current_note, data_file): prompt = 'Are you sure you want to clear all of your notes?' + BOLD + ' There is no going back (y/n): ' + RESET decision = hf.request_user_permission(prompt) if decision == 'n': print('Clearing of notes aborted') elif decision == 'y': for note in notes: note_path = path.expanduser('~/.quicknote/.notes/.' + note) if path.isfile(note_path) and note != 'default': os.remove(note_path) if current_note != 'default': hf.write_to_data_file(data_file, path.expanduser('~/.quicknote/.notes/.default')) print('Cleared all user notes from Quick Note cache')
def change_note(args, current_note, data_file): filename = '~/.quicknote/.notes/.' note_name = hf.parse_unary_args(args) filename += note_name filename = path.expanduser(filename) # stop if the note to be changed to is the current note if current_note == filename: print( 'The note you are trying to change to is already the current note.' ) return if not path.isfile(filename): print( 'Hmmm. The note you entered doesn\'t seem to exist. Please try again.' ) return hf.write_to_data_file(data_file, filename) print('Changed current note to \'' + note_name + '\'')
def rename_note(args, current_note, data_file): prefix = '~/.quicknote/.notes/.' pair = hf.parse_binary_args(args) if pair == None: return old_name = pair[0] new_name = pair[1] old_path = path.expanduser(prefix + old_name) new_path = path.expanduser(prefix + new_name) # confirm that the note to change actually exists if not path.isfile(old_path): print('The note you are trying to rename does not exist. Please try again.') return # prevent the user from renaming 'default' if old_name == 'default': print_default_error() return os.rename(old_path, new_path) if old_path == current_note: hf.write_to_data_file(data_file, new_path) print('Renamed \'' + old_name + '\' to \'' + new_name + '\'')