def handle(self, *args, **options):
        try:
            database, ids_file = args
        except ValueError:
            print "Usage: './manage.py undelete_docs [database] [ids_file]'"
            return

        # figure out db to use
        slugs = ['commcarehq'] + sorted(filter(None, couch_config.all_dbs_by_slug))
        if database not in slugs:
            print ("Did not recognize a database called '{}'.  "
                   "Options are: {}".format(database, ", ".join(slugs)))
            return
        slug = None if database == 'commcarehq' else database
        db = couch_config.all_dbs_by_slug[slug]

        # get list of doc_ids
        try:
            with open(ids_file) as f:
                doc_ids = [doc_id.strip() for doc_id in f.readlines()]
        except IOError:
            print "Couldn't find a file called '{}'".format(ids_file)
            return

        # confirm
        msg = ("Are you sure you want to undelete {} docs from {}? (y/n)\n"
               .format(len(doc_ids), db.dbname))
        if raw_input(msg) != "y":
            return

        # actually do the work
        results, iter_db = undelete_docs(db, doc_ids)

        # Now, what happened?
        print "Restored {} docs".format(len(results.restored))
        print "Didn't find {} ids".format(len(results.not_found))
        print "{} docs weren't deleted".format(len(results.not_deleted))

        outfile = "delete_from_{}_{}.txt".format(iter_db.db.dbname, datetime.now())
        with open(outfile, 'w') as f:
            f.write('\n'.join(get_output_file(results, iter_db)))
        print "Full results can be found in {}".format(outfile)
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/cleanup/management/commands/undelete_docs.py/Command.handle/original