def delete_entry(kind, entry, from_file=None): """Deletes a file name entry or tag entry from the catalog""" if kind == 'files': to_delete = File.get(File.file_name == entry) to_delete.delete_instance() print "'%s' deleted from catalog!" % entry elif kind == 'tag' and from_file: try: existing_file = File.get(File.file_name == from_file) if existing_file: try: association = FileTag.get(FileTag.file_id == existing_file, FileTag.tag_id == Tag.get(Tag.tag_name == entry)) association.delete_instance() print "Deleted '%s' from '%s'" % (entry, from_file) except: print "'%s' no longer tagged to %s" % (entry, from_file) except: print "'%s' not in catalog" % from_file elif kind == 'tag': tag_item = Tag.get(Tag.tag_name == entry) tag_item.delete_instance() print "'%s' deleted from catalog" % entry else: pass