def forge(category, post, comment, url): """Generates the fake categories, posts, and comments. 生成假数据用于展示效果。 Args: category:生成分类数量,默认为10 post:生成文章数量,默认为50 comment:生成评论数量,默认为500 url:生成链接数量,默认为5 """ from bluelog.fakes import (fake_admin, fake_categories, fake_posts, fake_comments, fake_url) db.drop_all() db.create_all() click.echo('Generating the administrator...') fake_admin() click.echo('Generating %d categories..' % category) fake_categories(category) click.echo('Generating %d posts...' % post) fake_posts(post) click.echo('Gemerating %d comments..' % comment) fake_comments(comment) click.echo('Generating %d urls..' % url) fake_url(url) click.echo('Done.')
def initdb(drop): if drop: click.confirm('这会删除数据库,确定继续吗?', abort=True) db.drop_all() click.echo('删除数据库') db.create_all() click.echo("数据库初始化完成")
def forge(category, post, comment): """Generate fake data.""" from bluelog.fakes import fake_admin, fake_categories, fake_posts, fake_comments, fake_links click.echo('dropping old database...') db.drop_all() click.echo('creating new database...') db.create_all() click.echo('Generating the administrator...') fake_admin() click.echo('Generating %d categories...' % category) fake_categories(category) click.echo('Generating %d posts...' % post) fake_posts(post) click.echo('Generating %d comments...' % comment) fake_comments(comment) click.echo('Generating links...') fake_links() click.echo('Done.')
def initdb(drop): if drop: click.confirm('删除存在的数据库和数据?', abort=True) db.drop_all() click.echo('数据库数据删除完成') db.create_all() click.echo("数据库创建完成")
def init(username, password): '''初始化博客''' click.echo('初始化数据库...') db.drop_all() db.create_all() click.echo('创建管理员账户...') admin = Admin(username=username, blog_title=f'{username.capitalize()}的博客', blog_sub_title='天涯路远 | 见字如面', name=username.capitalize(), about=username.capitalize() + '...') admin.set_password(password) db.session.add(admin) click.echo('创建默认分类...') category = Category(name='默认分类') db.session.add(category) db.session.commit() if not os.path.exists(config['base'].CKEDITOR_UPLOAD_PATH): click.echo('图像上传路径不存在,创建中...') os.mkdir(config['base'].CKEDITOR_UPLOAD_PATH) click.echo('完成')
def forge(category, tag, post, comment): """Generate fake data.""" from bluelog.fakes import fake_admin, fake_categories, fake_tags, fake_posts, fake_comments, fake_links db.drop_all() db.create_all() click.echo('Generating the administrator...') fake_admin() click.echo('Generating %d categories...' % category) fake_categories(category) click.echo('Generating %d tags...' % tag) fake_tags(tag) click.echo('Generating %d posts...' % post) fake_posts(post) click.echo('Generating %d comments...' % comment) fake_comments(comment) click.echo('Generating links...') fake_links() click.echo('Done.')
def initdb(drop): if drop: click.confirm('This operation will delete the database, do you want to continue?', abort=True) db.drop_all() click.echo('Drop tables.') db.create_all() click.echo('Initialized database.')
def forge(category, post, comment): '''生成虚拟数据''' from bluelog.fakes import fake_admin, fake_categories, fake_posts, fake_comments, fake_links db.drop_all() db.create_all() click.echo('生成管理员...') fake_admin() click.echo(f'生成 {category} 个分类...') fake_categories(category) click.echo(f'生成 {post} 篇文章...') fake_posts(post) click.echo(f'生成 {comment} 条评论...') fake_comments(comment) click.echo('生成链接...') fake_links() if not os.path.exists(config['base'].CKEDITOR_UPLOAD_PATH): click.echo('图像上传路径不存在,创建中...') os.mkdir(config['base'].CKEDITOR_UPLOAD_PATH) click.echo('完成')
def forge(): # 下面的这两句代码是必须的 db.drop_all() db.create_all() from tests.datas import companys from tests.datas import phones for key, value in companys.items(): company = Company(name=key, location=value) db.session.add(company) try: db.session.commit() except IntegrityError: db.session.rollback() click.echo('写入公司信息成功...') for phone in phones: phone = Phone(id=phone[0], model=phone[1], price=phone[3], company_name=phone[2]) db.session.add(phone) try: db.session.commit() except IntegrityError: db.session.rollback() click.echo('写入电话信息成功...') phone = Phone(id=7, model='Blackberry', price=5987, company_name='RIM') db.session.add(phone) db.session.commit()
def forge(category, post, comment, channel, website): """Generate fake data.""" from bluelog.fakes import fake_admin, fake_categories, fake_posts, fake_comments, fake_links, fake_channels, fake_websites db.drop_all() db.create_all() click.echo('Generating the administrator...') fake_admin() click.echo('Generating %d categories...' % category) fake_categories(category) click.echo('Generating %d posts...' % post) fake_posts(post) #lsc click.echo('Generating %d channels...' % channel) fake_channels(channel) #lsc click.echo('Generating %d websites...' % website) fake_websites(website) click.echo('Generating %d comments...' % comment) fake_comments(comment) click.echo('Generating links...') fake_links() click.echo('Done.')
def initdb(drop): if drop: click.confirm('Confirm to delete the database?', abort=True) db.drop_all() click.echo('Deleted database') db.create_all() click.echo('Initialized database')
def init(username, password): """Building Bluelog, just for you.""" click.echo('Initializing the database...') # 注意是否删除全部数据,此处需要格外注意 db.drop_all() db.create_all() admin = Admin.query.first() if admin is not None: click.echo('The administrator already exists, updating...') admin.username = username admin.set_password(password) else: click.echo('Creating the temporary administrator account...') admin = Admin(username=username, blog_title='Bluelog', blog_sub_title="No, I'm the real thing.", name='Admin', about='Anything about you.') admin.set_password(password) db.session.add(admin) category = Category.query.first() if category is None: click.echo('Creating the default category...') category = Category(name='资源分享') db.session.add(category) db.session.commit() click.echo('Done.')
def initdb(drop): """Initialize the database.""" if drop: click.confirm('此操作将删除数据库, 你确定要继续吗?', abort=True) db.drop_all() click.echo('删除表.') db.create_all() click.echo('初始化数据库.')
def forge(category, post, comment): """Generate the fake categories,posts,comments.""" db.drop_all() db.create_all() click.echo('Generating the administrator...') fake_admin() click.echo(f'Generating {category} categories...') fake_categories(category) click.echo(f'Generating {post} posts...') fake_post(post) click.echo(f'Generating {comment} comment...') fake_comments(comment) click.echo('Done.')
def forge(category, post, comment): """Generates the fake categories, posts, and comments.""" from bluelog.fakes import fake_categories,fake_posts,fake_comments, fake_admim db.drop_all() db.create_all() click.echo('Generating the administrator...') fake_admim() click.echo('Generating %d categories...'% category) fake_categories() click.echo('Generating %d posts...' % post) fake_posts() click.echo('Generating %d comments...' % comment) fake_comments() click.echo('Done.')
def initdb(drop): """Initialize the database. Args: drop: 可选参数,如果为True,则删除数据库中的数据 """ if drop: click.confirm( 'This operation will delete the database, ' 'do you want to continue?', abort=True) db.drop_all() click.echo('Drop tables.') db.create_all() click.echo('Initialized database.')
def forge(category, post): """Generate fake data.""" from bluelog.fakes import fake_admin, fake_categories, fake_posts db.drop_all() db.create_all() click.echo('Generating the administrator...') fake_admin() click.echo('Generating %d categories...' % category) fake_categories(category) click.echo('Generating %d posts...' % post) fake_posts(post) click.echo('Done.')
def forge(article, comment): """Generate fake data.""" from bluelog.fakes import fake_blogger, fake_articles, fake_comments db.drop_all() db.create_all() click.echo('Generating the blogger...') fake_blogger() click.echo('Generating %d categories...' % article) fake_articles(article) click.echo('Generating %d comments...' % comment) fake_comments(comment) click.echo('Done.')
def forge(category, post, comment): from bluelog.fakes import fake_admin, fake_categories, fake_comments, fake_posts # 删除所有表 db.drop_all() # 创建所有表 db.create_all() click.echo('Generating the administrator...') fake_admin() click.echo('Generating %d categories...' % category) fake_categories(category) click.echo('Generating %d categories...' % post) fake_posts(post) click.echo('Generating %d comments...' % comment) fake_comments(comment) click.echo('Done.')
def forge(category, post, comment): from bluelog.fakes import fake_admin, fake_comments, fake_categories, fake_posts db.drop_all() db.create_all() click.echo('Generating the administrator...') fake_admin() click.echo('Generating {} categories...'.format(category)) fake_categories() click.echo('Generating {} posts...'.format(post)) fake_posts() click.echo('Generating {} comments...'.format(comment)) fake_comments() click.echo('done')
def forge(category, post, comment): """生成虚拟分类、文章、评论数据""" from bluelog.fakes import fake_admin, fake_categories, fake_posts, fake_comments db.drop_all() db.create_all() click.echo('Generating the administrator...') fake_admin() click.echo(f'Generating {category} categories...') fake_categories(category) click.echo(f'Generating {post} posts...') fake_posts(post) click.echo(f'Generating {comment} comments...') fake_comments(comment) click.echo('Done.')
def forge(category, post, comment): """Generates the fake categories, posts, comments.""" from bluelog.fakes import fake_admin, fake_categories, fake_comments, fake_posts db.drop_all() db.create_all() click.echo('正在生成管理员数据...') fake_admin() click.echo('正在生成 %d 条分类...' % category) fake_categories(category) click.echo('正在生成 %d 篇文章...' % post) fake_posts(post) click.echo('正在生成 %d 条评论...' % comment) fake_comments(comment) click.echo('完成')
def forge(category, post, comment): from bluelog.fakes import fake_admin, fake_categories, fake_posts, fake_comments db.drop_all() db.create_all() click.echo('正在生成管理员数据') fake_admin() click.echo('正在生成%s条分类数据' % category) fake_categories(category) click.echo('正在生成%s条文章数据' % post) fake_posts(post) click.echo('正在生成%s条评论数据' % comment) fake_comments(comment) click.echo("数据生成完毕!!!")
def forge(category, post, comment): """Generate fake information""" from bluelog.fakes import fake_admin, fake_category, fake_post, fake_comments db.drop_all() db.create_all() click.echo('Generating fake admin...') fake_admin() click.echo('Generating %d fake categories...' % category) fake_category(category) click.echo('Generating %d fake posts...' % post) fake_post(post) click.echo('Generating %d fake comments...' % comment) fake_comments(comment) click.echo('Done.')
def forge_new(category, post, comment): db.drop_all() db.create_all() click.echo('Generating the administrator...') fake_admin() click.echo('Generating %d categories...' % category) fake_categories() click.echo('Generating %d posts...' % post) fake_posts() click.echo('Generating %d comments...' % comment) fake_comments() click.echo('Generating links...') fake_links() click.echo('Done.')
def forge(category, post, comment, tag): """Generate fake data""" from bluelog.fakes import fake_admin, fake_categories, fake_posts, \ fake_comments db.drop_all() db.create_all() click.echo('Working...') click.echo('Generating the administrator...') fake_admin() click.echo(f'Generating {category} categories...') fake_categories(category) click.echo(f'Generating {post} posts...') fake_posts(post) click.echo(f'Generating {comment} comments...') fake_comments(comment) click.echo(f'Done!!!')
def forge(category, post, comment): """Generates the fake categories, posts and comments""" db.drop_all() db.create_all() click.echo('Generating the administrator...') fake_admin() click.echo('Generating %d categories...' % category) fake_categories(category) click.echo('Generating %d posts...' % post) fake_posts(post) click.echo('Generating %d comments...' % comment) fake_comments(comment) click.echo('Generating links...') fake_links() click.echo('Done!')
def forge(category, post, comment): """构造虚拟数据""" from bluelog.fakes import fake_admin, fake_categories, fake_posts, fake_comments, fake_links db.drop_all() db.create_all() click.echo('生成管理员...') fake_admin() click.echo('生成 %d 分类...' % category) fake_categories(category) click.echo('生成 %d 文章...' % post) fake_posts(post) click.echo('生成 %d 评论...' % comment) fake_comments(comment) click.echo('生成链接...') fake_links() click.echo('构造完成...')
def forge(category, post, comment): """Generates the fake categories, post, and comments""" from bluelog.fakes import fake_admin, fake_categories, fake_posts, fake_comments, fake_links db.drop_all() db.create_all() click.echo('Generating the administrator...') fake_admin() click.echo('Generating {} categories...'.format(category)) fake_categories() click.echo('Generating {} posts...'.format(post)) fake_posts() click.echo('Generating {} comments...'.format(comment)) fake_comments() click.echo('Generating links...') fake_links() click.echo('Done.')
def setUp(self): super(CLITestCase, self).setUp() db.drop_all()