def clean_catalog(self, args): """ Removes all expired entries from catalog. If optional [-t] used, removes listed tags from entire catalog. """ if not self.old_files: print "There are no expired entries in the catalog" else: choice = raw_input("Delete all expired entries in the catalog?" "Press 'Y' to continue.") if choice.lower() == 'y': for file_name in self.old_files: # These are the tags currently associated with # the to-be-deleted file name file_name_tags = catalog.get_tags(file_name) # Deletes file-tag relationships first. Needed to ensure # that database remains clean and that when # viewing tags sorted by count, the numbers are accurate. for tag_name in file_name_tags: catalog.delete_entry('tag', tag_name.lower().strip(), file_name) # Now officially delete the entry from the database catalog.delete_entry('files', file_name) else: pass # delete specified tags from entire catalog if args.tags: for tag in args.tags: catalog.delete_entry('tag', tag.strip()) else: pass
def delete_entry(self, args): """ Removes specified file from catalog. If optional [-t] used, removes tags from their association with specified file (file remains in catalog). """ file_name = args.file.strip() if not args.tags: choice = raw_input("Remove '%s' from catalog entirely?\n" "Press 'Y' to continue: " % args.file.strip()) if choice.lower() == 'y': # These are the tags currently associated with # the to-be-deleted file name file_name_tags = catalog.get_tags(file_name) # Deletes file-tag relationships first. # Needed to ensure that database remains clean and that # when viewing tags sorted by count, the numbers are accurate. for tag_name in file_name_tags: catalog.delete_entry('tag', tag_name.lower().strip(), file_name) # Now delete the officially delete the entry from the database catalog.delete_entry('files', file_name) else: # delete specified tag(s) association from specified file for tag in args.tags: catalog.delete_entry('tag', tag.strip(), file_name)