You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

686 lines
21 KiB

  1. #!/usr/bin/env python
  2. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
  3. # MIT License. See license.txt
  4. from __future__ import unicode_literals
  5. import sys
  6. if __name__=="__main__":
  7. sys.path = [".", "lib", "app"] + sys.path
  8. import webnotes
  9. def main():
  10. parsed_args = webnotes._dict(vars(setup_parser()))
  11. fn = get_function(parsed_args)
  12. if parsed_args.get("site")=="all":
  13. for site in get_sites():
  14. args = parsed_args.copy()
  15. args["site"] = site
  16. run(fn, args)
  17. else:
  18. run(fn, parsed_args)
  19. def cmd(fn):
  20. def new_fn(*args, **kwargs):
  21. import inspect
  22. fnargs, varargs, varkw, defaults = inspect.getargspec(fn)
  23. new_kwargs = {}
  24. for a in fnargs:
  25. if a in kwargs:
  26. new_kwargs[a] = kwargs.get(a)
  27. return fn(*args, **new_kwargs)
  28. return new_fn
  29. def run(fn, args):
  30. if isinstance(args.get(fn), (list, tuple)):
  31. out = globals().get(fn)(*args.get(fn), **args)
  32. else:
  33. out = globals().get(fn)(**args)
  34. return out
  35. def get_function(args):
  36. for fn, val in args.items():
  37. if (val or isinstance(val, list)) and globals().get(fn):
  38. return fn
  39. def get_sites():
  40. import os
  41. import conf
  42. return [site for site in os.listdir(conf.sites_dir)
  43. if not os.path.islink(os.path.join(conf.sites_dir, site))]
  44. def setup_parser():
  45. import argparse
  46. parser = argparse.ArgumentParser(description="Run webnotes utility functions")
  47. setup_install(parser)
  48. setup_utilities(parser)
  49. setup_translation(parser)
  50. setup_git(parser)
  51. # common
  52. parser.add_argument("-f", "--force", default=False, action="store_true",
  53. help="Force execution where applicable (look for [-f] in help)")
  54. parser.add_argument("--quiet", default=True, action="store_false", dest="verbose",
  55. help="Show verbose output where applicable")
  56. parser.add_argument("--site", nargs="?", metavar="SITE-NAME or all",
  57. help="Run for a particular site")
  58. return parser.parse_args()
  59. def setup_install(parser):
  60. parser.add_argument("--install", metavar="DB-NAME", nargs=1,
  61. help="Install a new app")
  62. parser.add_argument("--root-password", nargs=1,
  63. help="Root password for new app")
  64. parser.add_argument("--reinstall", default=False, action="store_true",
  65. help="Install a fresh app in db_name specified in conf.py")
  66. parser.add_argument("--restore", metavar=("DB-NAME", "SQL-FILE"), nargs=2,
  67. help="Restore from an sql file")
  68. parser.add_argument("--install_fixtures", default=False, action="store_true",
  69. help="(Re)Install install-fixtures from app/startup/install_fixtures")
  70. parser.add_argument("--make_demo", default=False, action="store_true",
  71. help="Install demo in demo_db_name specified in conf.py")
  72. parser.add_argument("--make_demo_fresh", default=False, action="store_true",
  73. help="(Re)Install demo in demo_db_name specified in conf.py")
  74. parser.add_argument("--add_system_manager", nargs="+",
  75. metavar=("EMAIL", "[FIRST-NAME] [LAST-NAME]"), help="Add a user with all roles")
  76. def setup_utilities(parser):
  77. # update
  78. parser.add_argument("-u", "--update", nargs="*", metavar=("REMOTE", "BRANCH"),
  79. help="Perform git pull, run patches, sync schema and rebuild files/translations")
  80. parser.add_argument("--patch", nargs=1, metavar="PATCH-MODULE",
  81. help="Run a particular patch [-f]")
  82. parser.add_argument("-l", "--latest", default=False, action="store_true",
  83. help="Run patches, sync schema and rebuild files/translations")
  84. parser.add_argument("--sync_all", default=False, action="store_true",
  85. help="Reload all doctypes, pages, etc. using txt files [-f]")
  86. parser.add_argument("--update_all_sites", nargs="*", metavar=("REMOTE", "BRANCH"),
  87. help="Perform git pull, run patches, sync schema and rebuild files/translations")
  88. parser.add_argument("--reload_doc", nargs=3,
  89. metavar=('"MODULE"', '"DOCTYPE"', '"DOCNAME"'))
  90. # build
  91. parser.add_argument("-b", "--build", default=False, action="store_true",
  92. help="Minify + concatenate JS and CSS files, build translations")
  93. parser.add_argument("-w", "--watch", default=False, action="store_true",
  94. help="Watch and concatenate JS and CSS files as and when they change")
  95. # misc
  96. parser.add_argument("--backup", default=False, action="store_true",
  97. help="Take backup of database in backup folder [--with_files]")
  98. parser.add_argument("--move", default=False, action="store_true",
  99. help="Move site to different directory defined by --dest_dir")
  100. parser.add_argument("--dest_dir", nargs=1, metavar="DEST-DIR",
  101. help="Move site to different directory")
  102. parser.add_argument("--with_files", default=False, action="store_true",
  103. help="Also take backup of files")
  104. parser.add_argument("--docs", default=False, action="store_true",
  105. help="Build docs")
  106. parser.add_argument("--domain", nargs="*",
  107. help="Get or set domain in Website Settings")
  108. parser.add_argument("--make_conf", nargs="*", metavar=("DB-NAME", "DB-PASSWORD"),
  109. help="Create new conf.py file")
  110. parser.add_argument("--make_custom_server_script", nargs=1, metavar="DOCTYPE",
  111. help="Create new conf.py file")
  112. parser.add_argument("--set_admin_password", metavar='ADMIN-PASSWORD', nargs=1,
  113. help="Set administrator password")
  114. parser.add_argument("--mysql", action="store_true", help="get mysql shell for a site")
  115. parser.add_argument("--serve", action="store_true", help="Run development server")
  116. parser.add_argument("--smtp", action="store_true", help="Run smtp debug server",
  117. dest="smtp_debug_server")
  118. parser.add_argument("--get_site_status", action="store_true", help="Get site details")
  119. parser.add_argument("--update_site_config", nargs=1,
  120. metavar="SITE-CONFIG-JSON",
  121. help="Update site_config.json for a given --site")
  122. parser.add_argument("--port", default=8000, type=int, help="port for development server")
  123. # clear
  124. parser.add_argument("--clear_web", default=False, action="store_true",
  125. help="Clear website cache")
  126. parser.add_argument("--clear_cache", default=False, action="store_true",
  127. help="Clear cache, doctype cache and defaults")
  128. parser.add_argument("--reset_perms", default=False, action="store_true",
  129. help="Reset permissions for all doctypes")
  130. # scheduler
  131. parser.add_argument("--run_scheduler", default=False, action="store_true",
  132. help="Trigger scheduler")
  133. parser.add_argument("--run_scheduler_event", nargs=1,
  134. metavar="all | daily | weekly | monthly",
  135. help="Run a scheduler event")
  136. # replace
  137. parser.add_argument("--replace", nargs=3,
  138. metavar=("SEARCH-REGEX", "REPLACE-BY", "FILE-EXTN"),
  139. help="Multi-file search-replace [-f]")
  140. # import/export
  141. parser.add_argument("--export_doc", nargs=2, metavar=('"DOCTYPE"', '"DOCNAME"'))
  142. parser.add_argument("--export_doclist", nargs=3, metavar=("DOCTYPE", "NAME", "PATH"),
  143. help="""Export doclist as json to the given path, use '-' as name for Singles.""")
  144. parser.add_argument("--export_csv", nargs=2, metavar=("DOCTYPE", "PATH"),
  145. help="""Dump DocType as csv""")
  146. parser.add_argument("--import_doclist", nargs=1, metavar="PATH",
  147. help="""Import (insert/update) doclist. If the argument is a directory, all files ending with .json are imported""")
  148. def setup_git(parser):
  149. parser.add_argument("--pull", nargs="*", metavar=("REMOTE", "BRANCH"),
  150. help="Run git pull for both repositories")
  151. parser.add_argument("-p", "--push", nargs="*", metavar=("REMOTE", "BRANCH"),
  152. help="Run git push for both repositories")
  153. parser.add_argument("--status", default=False, action="store_true",
  154. help="Run git status for both repositories")
  155. parser.add_argument("--commit", nargs=1, metavar="COMMIT-MSG",
  156. help="Run git commit COMMIT-MSG for both repositories")
  157. parser.add_argument("--checkout", nargs=1, metavar="BRANCH",
  158. help="Run git checkout BRANCH for both repositories")
  159. parser.add_argument("--git", nargs="*", metavar="OPTIONS",
  160. help="Run git command for both repositories")
  161. def setup_translation(parser):
  162. parser.add_argument("--build_message_files", default=False, action="store_true",
  163. help="Build message files for translation")
  164. parser.add_argument("--export_messages", nargs=2, metavar=("LANG-CODE", "FILENAME"),
  165. help="""Export all messages for a language to translation in a csv file.
  166. Example, lib/wnf.py --export_messages hi hindi.csv""")
  167. parser.add_argument("--import_messages", nargs=2, metavar=("LANG-CODE", "FILENAME"),
  168. help="""Import messages for a language and make language files.
  169. Example, lib/wnf.py --import_messages hi hindi.csv""")
  170. parser.add_argument("--google_translate", nargs=3,
  171. metavar=("LANG-CODE", "INFILE", "OUTFILE"),
  172. help="Auto translate using Google Translate API")
  173. parser.add_argument("--translate", nargs=1, metavar="LANG-CODE",
  174. help="""Rebuild translation for the given langauge and
  175. use Google Translate to tranlate untranslated messages. use "all" """)
  176. # methods
  177. # install
  178. @cmd
  179. def install(db_name, source_sql=None, site=None, verbose=True, force=False, root_password=None, site_config=None, admin_password='admin'):
  180. from webnotes.install_lib.install import Installer
  181. inst = Installer('root', db_name=db_name, site=site, root_password=root_password, site_config=site_config)
  182. inst.install(db_name, source_sql=source_sql, verbose=verbose, force=force, admin_password=admin_password)
  183. webnotes.destroy()
  184. @cmd
  185. def reinstall(site=None, verbose=True):
  186. webnotes.init(site=site)
  187. install(webnotes.conf.db_name, site=site, verbose=verbose, force=True)
  188. @cmd
  189. def restore(db_name, source_sql, site=None, verbose=True, force=False):
  190. install(db_name, source_sql, site=site, verbose=verbose, force=force)
  191. @cmd
  192. def install_fixtures(site=None):
  193. webnotes.init(site=site)
  194. from webnotes.install_lib.install import install_fixtures
  195. install_fixtures()
  196. webnotes.destroy()
  197. @cmd
  198. def add_system_manager(email, first_name=None, last_name=None, site=None):
  199. webnotes.connect(site=site)
  200. webnotes.profile.add_system_manager(email, first_name, last_name)
  201. webnotes.conn.commit()
  202. webnotes.destroy()
  203. @cmd
  204. def make_demo(site=None):
  205. import utilities.demo.make_demo
  206. webnotes.init(site=site)
  207. utilities.demo.make_demo.make()
  208. webnotes.destroy()
  209. @cmd
  210. def make_demo_fresh(site=None):
  211. import utilities.demo.make_demo
  212. webnotes.init(site=site)
  213. utilities.demo.make_demo.make(reset=True)
  214. webnotes.destroy()
  215. # utilities
  216. @cmd
  217. def update(remote=None, branch=None, site=None):
  218. pull(remote=remote, branch=branch, site=site)
  219. # maybe there are new framework changes, any consequences?
  220. reload(webnotes)
  221. if not site: build()
  222. latest(site=site)
  223. @cmd
  224. def latest(site=None, verbose=True):
  225. import webnotes.modules.patch_handler
  226. import webnotes.model.sync
  227. import webnotes.plugins
  228. webnotes.connect(site=site)
  229. try:
  230. # run patches
  231. webnotes.local.patch_log_list = []
  232. webnotes.modules.patch_handler.run_all()
  233. if verbose:
  234. print "\n".join(webnotes.local.patch_log_list)
  235. # sync
  236. webnotes.model.sync.sync_all()
  237. # remove __init__.py from plugins
  238. webnotes.plugins.remove_init_files()
  239. except webnotes.modules.patch_handler.PatchError, e:
  240. print "\n".join(webnotes.local.patch_log_list)
  241. raise e
  242. finally:
  243. webnotes.destroy()
  244. @cmd
  245. def sync_all(site=None, force=False):
  246. import webnotes.model.sync
  247. webnotes.connect(site=site)
  248. webnotes.model.sync.sync_all(force=force)
  249. webnotes.destroy()
  250. @cmd
  251. def patch(patch_module, site=None, force=False):
  252. import webnotes.modules.patch_handler
  253. webnotes.connect(site=site)
  254. webnotes.local.patch_log_list = []
  255. webnotes.modules.patch_handler.run_single(patch_module, force=force)
  256. print "\n".join(webnotes.local.patch_log_list)
  257. webnotes.destroy()
  258. @cmd
  259. def update_all_sites(remote=None, branch=None, verbose=True):
  260. pull(remote, branch)
  261. # maybe there are new framework changes, any consequences?
  262. reload(webnotes)
  263. build()
  264. for site in get_sites():
  265. latest(site=site, verbose=verbose)
  266. @cmd
  267. def reload_doc(module, doctype, docname, site=None, force=False):
  268. webnotes.connect(site=site)
  269. webnotes.reload_doc(module, doctype, docname, force=force)
  270. webnotes.destroy()
  271. @cmd
  272. def build():
  273. import webnotes.build
  274. webnotes.build.bundle(False)
  275. @cmd
  276. def watch():
  277. import webnotes.build
  278. webnotes.build.watch(True)
  279. @cmd
  280. def backup(site=None, with_files=False, verbose=True, backup_path_db=None, backup_path_files=None):
  281. from webnotes.utils.backups import scheduled_backup
  282. webnotes.connect(site=site)
  283. odb = scheduled_backup(ignore_files=not with_files, backup_path_db=backup_path_db, backup_path_files=backup_path_files)
  284. if verbose:
  285. from webnotes.utils import now
  286. print "database backup taken -", odb.backup_path_db, "- on", now()
  287. if with_files:
  288. print "files backup taken -", odb.backup_path_files, "- on", now()
  289. return odb
  290. @cmd
  291. def move(site=None, dest_dir=None):
  292. import os
  293. if not dest_dir:
  294. raise Exception, "--dest_dir is required for --move"
  295. dest_dir = dest_dir[0]
  296. if not os.path.isdir(dest_dir):
  297. raise Exception, "destination is not a directory or does not exist"
  298. webnotes.init(site=site)
  299. old_path = webnotes.utils.get_site_path()
  300. new_path = os.path.join(dest_dir, site)
  301. # check if site dump of same name already exists
  302. site_dump_exists = True
  303. count = 0
  304. while site_dump_exists:
  305. final_new_path = new_path + (count and str(count) or "")
  306. site_dump_exists = os.path.exists(final_new_path)
  307. count = int(count or 0) + 1
  308. os.rename(old_path, final_new_path)
  309. webnotes.destroy()
  310. return os.path.basename(final_new_path)
  311. @cmd
  312. def docs():
  313. from core.doctype.documentation_tool.documentation_tool import write_static
  314. write_static()
  315. @cmd
  316. def domain(host_url=None, site=None):
  317. webnotes.connect(site=site)
  318. if host_url:
  319. webnotes.conn.set_value("Website Settings", None, "subdomain", host_url)
  320. webnotes.conn.commit()
  321. else:
  322. print webnotes.conn.get_value("Website Settings", None, "subdomain")
  323. webnotes.destroy()
  324. @cmd
  325. def make_conf(db_name=None, db_password=None, site=None, site_config=None):
  326. from webnotes.install_lib.install import make_conf
  327. make_conf(db_name=db_name, db_password=db_password, site=site, site_config=site_config)
  328. @cmd
  329. def make_custom_server_script(doctype, site=None):
  330. from core.doctype.custom_script.custom_script import make_custom_server_script_file
  331. webnotes.connect(site=site)
  332. make_custom_server_script_file(doctype)
  333. webnotes.destroy()
  334. # clear
  335. @cmd
  336. def clear_cache(site=None):
  337. import webnotes.sessions
  338. webnotes.connect(site=site)
  339. webnotes.sessions.clear_cache()
  340. webnotes.destroy()
  341. @cmd
  342. def clear_web(site=None):
  343. import webnotes.webutils
  344. webnotes.connect(site=site)
  345. webnotes.webutils.clear_cache()
  346. webnotes.destroy()
  347. @cmd
  348. def reset_perms(site=None):
  349. webnotes.connect(site=site)
  350. for d in webnotes.conn.sql_list("""select name from `tabDocType`
  351. where ifnull(istable, 0)=0 and ifnull(custom, 0)=0"""):
  352. webnotes.clear_cache(doctype=d)
  353. webnotes.reset_perms(d)
  354. webnotes.destroy()
  355. # scheduler
  356. @cmd
  357. def run_scheduler(site=None):
  358. import webnotes.utils.scheduler
  359. webnotes.connect(site=site)
  360. print webnotes.utils.scheduler.execute()
  361. webnotes.destroy()
  362. @cmd
  363. def run_scheduler_event(event, site=None):
  364. import webnotes.utils.scheduler
  365. webnotes.connect(site=site)
  366. print webnotes.utils.scheduler.trigger("execute_" + event)
  367. webnotes.destroy()
  368. # replace
  369. @cmd
  370. def replace(search_regex, replacement, extn, force=False):
  371. print search_regex, replacement, extn
  372. replace_code('.', search_regex, replacement, extn, force=force)
  373. # import/export
  374. @cmd
  375. def export_doc(doctype, docname, site=None):
  376. import webnotes.modules
  377. webnotes.connect(site=site)
  378. webnotes.modules.export_doc(doctype, docname)
  379. webnotes.destroy()
  380. @cmd
  381. def export_doclist(doctype, name, path, site=None):
  382. from core.page.data_import_tool import data_import_tool
  383. webnotes.connect(site=site)
  384. data_import_tool.export_json(doctype, name, path)
  385. webnotes.destroy()
  386. @cmd
  387. def export_csv(doctype, path, site=None):
  388. from core.page.data_import_tool import data_import_tool
  389. webnotes.connect(site=site)
  390. data_import_tool.export_csv(doctype, path)
  391. webnotes.destroy()
  392. @cmd
  393. def import_doclist(path, site=None, force=False):
  394. from core.page.data_import_tool import data_import_tool
  395. webnotes.connect(site=site)
  396. data_import_tool.import_doclist(path, overwrite=force)
  397. webnotes.destroy()
  398. # translation
  399. @cmd
  400. def build_message_files(site=None):
  401. import webnotes.translate
  402. webnotes.connect(site=site)
  403. webnotes.translate.build_message_files()
  404. webnotes.destroy()
  405. @cmd
  406. def export_messages(lang, outfile, site=None):
  407. import webnotes.translate
  408. webnotes.connect(site=site)
  409. webnotes.translate.export_messages(lang, outfile)
  410. webnotes.destroy()
  411. @cmd
  412. def import_messages(lang, infile, site=None):
  413. import webnotes.translate
  414. webnotes.connect(site=site)
  415. webnotes.translate.import_messages(lang, infile)
  416. webnotes.destroy()
  417. @cmd
  418. def google_translate(lang, infile, outfile, site=None):
  419. import webnotes.translate
  420. webnotes.connect(site=site)
  421. webnotes.translate.google_translate(lang, infile, outfile)
  422. webnotes.destroy()
  423. @cmd
  424. def translate(lang, site=None):
  425. import webnotes.translate
  426. webnotes.connect(site=site)
  427. webnotes.translate.translate(lang)
  428. webnotes.destroy()
  429. # git
  430. @cmd
  431. def git(param):
  432. if isinstance(param, (list, tuple)):
  433. param = " ".join(param)
  434. import os
  435. os.system("""cd lib && git %s""" % param)
  436. os.system("""cd app && git %s""" % param)
  437. def get_remote_and_branch(remote=None, branch=None):
  438. if not (remote and branch):
  439. webnotes.init()
  440. if not webnotes.conf.branch:
  441. raise Exception("Please specify remote and branch")
  442. remote = remote or "origin"
  443. branch = branch or webnotes.conf.branch
  444. webnotes.destroy()
  445. return remote, branch
  446. @cmd
  447. def pull(remote=None, branch=None):
  448. remote, branch = get_remote_and_branch(remote, branch)
  449. git(("pull", remote, branch))
  450. @cmd
  451. def push(remote=None, branch=None):
  452. remote, branch = get_remote_and_branch(remote, branch)
  453. git(("push", remote, branch))
  454. @cmd
  455. def status():
  456. git("status")
  457. @cmd
  458. def commit(message):
  459. git("""commit -a -m "%s" """ % message.replace('"', '\"'))
  460. @cmd
  461. def checkout(branch):
  462. git(("checkout", branch))
  463. @cmd
  464. def set_admin_password(admin_password, site=None):
  465. import webnotes
  466. webnotes.connect(site=site)
  467. webnotes.conn.sql("""update __Auth set `password`=password(%s)
  468. where user='Administrator'""", (admin_password,))
  469. webnotes.conn.commit()
  470. webnotes.destroy()
  471. @cmd
  472. def mysql(site=None):
  473. import webnotes
  474. import commands, os
  475. msq = commands.getoutput('which mysql')
  476. webnotes.init(site=site)
  477. os.execv(msq, [msq, '-u', webnotes.conf.db_name, '-p'+webnotes.conf.db_password, webnotes.conf.db_name, webnotes.conf.db_host or "localhost"])
  478. webnotes.destroy()
  479. @cmd
  480. def smtp_debug_server():
  481. import commands, os
  482. python = commands.getoutput('which python')
  483. os.execv(python, [python, '-m', "smtpd", "-n", "-c", "DebuggingServer", "localhost:25"])
  484. @cmd
  485. def serve(port=8000):
  486. import webnotes.app
  487. webnotes.app.serve(port=port)
  488. def replace_code(start, txt1, txt2, extn, search=None, force=False):
  489. """replace all txt1 by txt2 in files with extension (extn)"""
  490. import webnotes.utils
  491. import os, re
  492. esc = webnotes.utils.make_esc('[]')
  493. if not search: search = esc(txt1)
  494. for wt in os.walk(start, followlinks=1):
  495. for fn in wt[2]:
  496. if fn.split('.')[-1]==extn:
  497. fpath = os.path.join(wt[0], fn)
  498. with open(fpath, 'r') as f:
  499. content = f.read()
  500. if re.search(search, content):
  501. res = search_replace_with_prompt(fpath, txt1, txt2, force)
  502. if res == 'skip':
  503. return 'skip'
  504. def search_replace_with_prompt(fpath, txt1, txt2, force=False):
  505. """ Search and replace all txt1 by txt2 in the file with confirmation"""
  506. from termcolor import colored
  507. with open(fpath, 'r') as f:
  508. content = f.readlines()
  509. tmp = []
  510. for c in content:
  511. if c.find(txt1) != -1:
  512. print fpath
  513. print colored(txt1, 'red').join(c[:-1].split(txt1))
  514. a = ''
  515. if force:
  516. c = c.replace(txt1, txt2)
  517. else:
  518. while a.lower() not in ['y', 'n', 'skip']:
  519. a = raw_input('Do you want to Change [y/n/skip]?')
  520. if a.lower() == 'y':
  521. c = c.replace(txt1, txt2)
  522. elif a.lower() == 'skip':
  523. return 'skip'
  524. tmp.append(c)
  525. with open(fpath, 'w') as f:
  526. f.write(''.join(tmp))
  527. print colored('Updated', 'green')
  528. @cmd
  529. def get_site_status(site=None, verbose=False):
  530. import webnotes
  531. import webnotes.utils
  532. from webnotes.profile import get_system_managers
  533. from core.doctype.profile.profile import get_total_users, get_active_users, \
  534. get_website_users, get_active_website_users
  535. import json
  536. webnotes.connect(site=site)
  537. ret = {
  538. 'last_backup_on': webnotes.local.conf.last_backup_on,
  539. 'active_users': get_active_users(),
  540. 'total_users': get_total_users(),
  541. 'active_website_users': get_active_website_users(),
  542. 'website_users': get_website_users(),
  543. 'system_managers': "\n".join(get_system_managers()),
  544. 'default_company': webnotes.conn.get_default("company"),
  545. 'disk_usage': webnotes.utils.get_disk_usage(),
  546. 'working_directory': webnotes.utils.get_base_path()
  547. }
  548. # country, timezone, industry
  549. control_panel_details = webnotes.conn.get_value("Control Panel", "Control Panel",
  550. ["country", "time_zone", "industry"], as_dict=True)
  551. if control_panel_details:
  552. ret.update(control_panel_details)
  553. # basic usage/progress analytics
  554. for doctype in ("Company", "Customer", "Item", "Quotation", "Sales Invoice",
  555. "Journal Voucher", "Stock Ledger Entry"):
  556. key = doctype.lower().replace(" ", "_") + "_exists"
  557. ret[key] = 1 if webnotes.conn.count(doctype) else 0
  558. webnotes.destroy()
  559. if verbose:
  560. print json.dumps(ret, indent=1, sort_keys=True)
  561. return ret
  562. @cmd
  563. def update_site_config(site_config, site, verbose=False):
  564. import json
  565. if isinstance(site_config, basestring):
  566. site_config = json.loads(site_config)
  567. webnotes.init(site=site)
  568. webnotes.conf.site_config.update(site_config)
  569. site_config_path = webnotes.get_conf_path(webnotes.conf.sites_dir, site)
  570. with open(site_config_path, "w") as f:
  571. json.dump(webnotes.conf.site_config, f, indent=1, sort_keys=True)
  572. webnotes.destroy()
  573. if __name__=="__main__":
  574. main()