示例#1
0
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 + '\'')
示例#2
0
def add_note(args):
    note_name = hf.parse_unary_args(args)
    dot_name = path.expanduser('~/.quicknote/.notes/.' + note_name)
    return_value = hf.make_note(dot_name, note_name)
    if return_value == None:
        return
    print('Added new note \'' + note_name + '\'')
示例#3
0
def import_note(args):
	pair = hf.parse_binary_args(args)
	if pair == None:
		return
	import_name = pair[0]
	note_name = pair[1]
	# confirm that imported file is a '.txt'; return otherwise
	if import_name[-4:] != '.txt':
		print(BOLD + 'Quick Note' + RESET + ' only allows for the importation of \'.txt\' files as notes. Please try again.')
		return
	new_note = path.expanduser('~/.quicknote/.notes/.' + note_name)
	new_note_exists = hf.make_note(new_note, note_name)	
	if new_note_exists != 0: 
		shutil.copyfile(import_name, new_note)
		print('Successfully imported \'' + import_name + '\' as \'' + note_name + '\'')
	else:		
		print('Could not import \'' + import_name + '\'. Please try again.')
示例#4
0
def duplicate_note(args):
	pair = hf.parse_binary_args(args)
	if pair == None:
		return
	existing_note = pair[0]
	new_note = pair[1]
	existing_path = path.expanduser('~/.quicknote/.notes/.' + existing_note)
	new_path = path.expanduser('~/.quicknote/.notes/.' + new_note)
	# confirm that a note actually exists with the given name
	if not path.isfile(existing_path):
		print('There is no note called \'' + existing_note + '\'. Please try again.')
		return
	# prevent the user from duplicating default
	if existing_note == 'default':
		hf.print_default_error()
		return
	new_note_exists = hf.make_note(new_path, new_note)	
	if new_note_exists != None: 
		shutil.copyfile(existing_path, new_path)
		print('Successfully duplicated \'' + existing_note + '\' as \'' + new_note + '\'')
	else:		
		print('Could not duplicate \'' + existing_note + '\'. Please try again.')