Rushabh Mehta | 4f8f9c1 | 2017-06-12 09:18:06 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Web Notes Technologies Pvt. Ltd. and Contributors |
| 2 | # MIT License. See license.txt |
| 3 | |
| 4 | from __future__ import unicode_literals, absolute_import, print_function |
| 5 | import click |
| 6 | import frappe |
| 7 | from frappe.commands import pass_context, get_site |
| 8 | |
| 9 | def call_command(cmd, context): |
| 10 | return click.Context(cmd, obj=context).forward(cmd) |
| 11 | |
| 12 | @click.command('make-demo') |
| 13 | @click.option('--site', help='site name') |
| 14 | @click.option('--domain', default='Manufacturing') |
| 15 | @click.option('--days', default=100, |
| 16 | help='Run the demo for so many days. Default 100') |
| 17 | @click.option('--resume', default=False, is_flag=True, |
| 18 | help='Continue running the demo for given days') |
Rushabh Mehta | 73167ea | 2017-06-16 16:55:32 +0530 | [diff] [blame] | 19 | @click.option('--reinstall', default=False, is_flag=True, |
| 20 | help='Reinstall site before demo') |
Rushabh Mehta | 4f8f9c1 | 2017-06-12 09:18:06 +0530 | [diff] [blame] | 21 | @pass_context |
Rushabh Mehta | 73167ea | 2017-06-16 16:55:32 +0530 | [diff] [blame] | 22 | def make_demo(context, site, domain='Manufacturing', days=100, |
| 23 | resume=False, reinstall=False): |
Rushabh Mehta | 4f8f9c1 | 2017-06-12 09:18:06 +0530 | [diff] [blame] | 24 | "Reinstall site and setup demo" |
| 25 | from frappe.commands.site import _reinstall |
| 26 | from frappe.installer import install_app |
| 27 | |
| 28 | site = get_site(context) |
| 29 | |
| 30 | if resume: |
| 31 | with frappe.init_site(site): |
| 32 | frappe.connect() |
| 33 | from erpnext.demo import demo |
| 34 | demo.simulate(days=days) |
| 35 | else: |
Rushabh Mehta | 73167ea | 2017-06-16 16:55:32 +0530 | [diff] [blame] | 36 | if reinstall: |
| 37 | _reinstall(site, yes=True) |
Rushabh Mehta | 4f8f9c1 | 2017-06-12 09:18:06 +0530 | [diff] [blame] | 38 | with frappe.init_site(site=site): |
| 39 | frappe.connect() |
| 40 | if not 'erpnext' in frappe.get_installed_apps(): |
| 41 | install_app('erpnext') |
| 42 | |
| 43 | # import needs site |
| 44 | from erpnext.demo import demo |
| 45 | demo.make(domain, days) |
| 46 | |
| 47 | commands = [ |
| 48 | make_demo |
| 49 | ] |