Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

690 Zeilen
22 KiB

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