def warn(self, db_name): """Print out a warning that we are about to wipe ``db_name``. Prompts the user to confirm this deletion. If the ``--force`` flag is used, this check is skipped. :param str db_name: The name of the database to delete. """ if not self.force: print CLIColor.underline( CLIColor.fail('WARNING!!! You are about wipe the ' '{} database!'.format(db_name))) cont = '' while cont == '': cont = raw_input('Do you want to continue? (yes/no): ') if cont[0] not in ('y', 'Y'): # if the answer doesn't start with y print ('Exiting...') exit(1)
def run(self): """Run the generation. Uses the configurations passed to func:`__init__`. """ # Setup: db connection, superuser, and printer. connect(config['MONGODB_SETTINGS']['DB']) try: superuser = User.objects().get(gplus_id='super') except DoesNotExist: print ('Failed to get superuser. Try running:\n' '\texport GOOGLE_AUTH_ENABLED=TRUE') printer = ProgressPrinter(self.quiet) # Images if self.should_gen_images: if self.wipe: self.warn('Image') print CLIColor.warning('Wiping Image database.') Image.drop_collection() create_images(12, superuser, printer) # Blog posts if self.should_gen_posts: if self.wipe: self.warn('BlogPost') print CLIColor.warning('Wiping BlogPost database.') BlogPost.drop_collection() create_posts(10, superuser, printer) # Events and event series if self.should_gen_events: if self.wipe: self.warn('Event and EventSeries') print CLIColor.warning('Wiping Event database.') Event.drop_collection() print CLIColor.warning('Wiping EventSeries database.') EventSeries.drop_collection() create_events(superuser, printer)