Created
September 5, 2016 17:07
-
-
Save ledjon/76aabde614225a71f6a681fda3baa879 to your computer and use it in GitHub Desktop.
remove an entry from couchpotato's "release" index (when corrupted)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# note: you must set this to the path to your couchpotato base installation dir: | |
# export PYTHONPATH=./CouchPotatoServer | |
from CodernityDB.database import Database | |
import sys | |
import pprint | |
def main(): | |
# TODO: make this something that we can input pass as an input | |
#bad_entry='2d34e5d1a2f640c9942ad8095a8d125e' | |
#bad_entry='2dda88207c594c3b91f3f6c1b86a5218' | |
bad_entry='ddca09df9bf341f7a88e50392de4f1f7' | |
bad_index='release' | |
db_path='database' | |
if len(sys.argv) > 1: | |
bad_entry = sys.argv[1] | |
print "changing entry to {0}".format(bad_entry) | |
pp = pprint.PrettyPrinter(indent=4) | |
db = Database(db_path) | |
#db.open() | |
# todo: make this more dynamic based on the index name to clean up | |
index=db._read_index_single(db_path + '/_indexes', '14release.py') | |
index.open_index() | |
found = False | |
all_index_items = index.all() | |
for i in all_index_items: | |
id = i[0] | |
key = i[1] | |
if id == bad_entry: | |
found = True | |
print "found and deleting id={0} k={1}".format(id, key) | |
index.delete(id, key) | |
# for curr in db.all(bad_index, with_doc=False, with_storage=False): | |
# id = curr.get('_id') | |
# key = curr.get('key') | |
# | |
# if id == bad_entry: | |
# found=True | |
# print "Found entry to delete! id={0} key={1}".format(id, key) | |
# pp.pprint(curr) | |
# | |
# print "running direct index delete:" | |
# # index.delete(id, key) | |
# | |
# print "done with delete!" | |
if found == True: | |
print "Found entry and (hopefully) cleaned it up" | |
else: | |
print "WARNING: Unable to find entry for index={0} key={1}".format(bad_index, bad_entry) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment