mirror of
https://github.com/frappe/bench.git
synced 2025-02-03 11:28:24 +00:00
chore: bench.utils format, imports sort, spaces
This commit is contained in:
parent
63128a21bf
commit
3ea19e9533
@ -1,9 +1,12 @@
|
|||||||
import os, sys, shutil, subprocess, logging, itertools, requests, json, platform, select, pwd, grp, multiprocessing, hashlib, glob, re, site, errno
|
import errno, glob, grp, itertools, json, logging, multiprocessing, os, platform, pwd, re, select, shutil, site, subprocess, sys
|
||||||
from distutils.spawn import find_executable
|
from distutils.spawn import find_executable
|
||||||
import bench
|
|
||||||
|
import requests
|
||||||
import semantic_version
|
import semantic_version
|
||||||
|
from six import iteritems
|
||||||
|
|
||||||
|
import bench
|
||||||
from bench import env
|
from bench import env
|
||||||
from six import iteritems, PY2
|
|
||||||
|
|
||||||
|
|
||||||
class PatchError(Exception):
|
class PatchError(Exception):
|
||||||
@ -718,11 +721,13 @@ def post_upgrade(from_ver, to_ver, bench_path='.'):
|
|||||||
if from_ver <= 5 and to_ver == 6:
|
if from_ver <= 5 and to_ver == 6:
|
||||||
setup_socketio(bench_path=bench_path)
|
setup_socketio(bench_path=bench_path)
|
||||||
|
|
||||||
print("As you have setup your bench for production, you will have to reload configuration for nginx and supervisor")
|
message = """
|
||||||
print("To complete the migration, please run the following commands")
|
As you have setup your bench for production, you will have to reload configuration for nginx and supervisor. To complete the migration, please run the following commands
|
||||||
print()
|
sudo service nginx restart
|
||||||
print("sudo service nginx restart")
|
sudo supervisorctl reload
|
||||||
print("sudo supervisorctl reload")
|
""".strip()
|
||||||
|
print(message)
|
||||||
|
|
||||||
|
|
||||||
def update_translations_p(args):
|
def update_translations_p(args):
|
||||||
try:
|
try:
|
||||||
@ -730,6 +735,7 @@ def update_translations_p(args):
|
|||||||
except requests.exceptions.HTTPError:
|
except requests.exceptions.HTTPError:
|
||||||
print('Download failed for', args[0], args[1])
|
print('Download failed for', args[0], args[1])
|
||||||
|
|
||||||
|
|
||||||
def download_translations_p():
|
def download_translations_p():
|
||||||
pool = multiprocessing.Pool(4)
|
pool = multiprocessing.Pool(4)
|
||||||
|
|
||||||
@ -739,18 +745,21 @@ def download_translations_p():
|
|||||||
|
|
||||||
pool.map(update_translations_p, args)
|
pool.map(update_translations_p, args)
|
||||||
|
|
||||||
|
|
||||||
def download_translations():
|
def download_translations():
|
||||||
langs = get_langs()
|
langs = get_langs()
|
||||||
apps = ('frappe', 'erpnext')
|
apps = ('frappe', 'erpnext')
|
||||||
for app, lang in itertools.product(apps, langs):
|
for app, lang in itertools.product(apps, langs):
|
||||||
update_translations(app, lang)
|
update_translations(app, lang)
|
||||||
|
|
||||||
|
|
||||||
def get_langs():
|
def get_langs():
|
||||||
lang_file = 'apps/frappe/frappe/geo/languages.json'
|
lang_file = 'apps/frappe/frappe/geo/languages.json'
|
||||||
with open(lang_file) as f:
|
with open(lang_file) as f:
|
||||||
langs = json.loads(f.read())
|
langs = json.loads(f.read())
|
||||||
return [d['code'] for d in langs]
|
return [d['code'] for d in langs]
|
||||||
|
|
||||||
|
|
||||||
def update_translations(app, lang):
|
def update_translations(app, lang):
|
||||||
translations_dir = os.path.join('apps', app, app, 'translations')
|
translations_dir = os.path.join('apps', app, app, 'translations')
|
||||||
csv_file = os.path.join(translations_dir, lang + '.csv')
|
csv_file = os.path.join(translations_dir, lang + '.csv')
|
||||||
@ -795,15 +804,18 @@ def log_line(data, stream):
|
|||||||
return sys.stderr.write(data)
|
return sys.stderr.write(data)
|
||||||
return sys.stdout.write(data)
|
return sys.stdout.write(data)
|
||||||
|
|
||||||
|
|
||||||
def get_output(*cmd):
|
def get_output(*cmd):
|
||||||
s = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
s = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
out = s.stdout.read()
|
out = s.stdout.read()
|
||||||
s.stdout.close()
|
s.stdout.close()
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
def before_update(bench_path, requirements):
|
def before_update(bench_path, requirements):
|
||||||
validate_pillow_dependencies(bench_path, requirements)
|
validate_pillow_dependencies(bench_path, requirements)
|
||||||
|
|
||||||
|
|
||||||
def validate_pillow_dependencies(bench_path, requirements):
|
def validate_pillow_dependencies(bench_path, requirements):
|
||||||
if not requirements:
|
if not requirements:
|
||||||
return
|
return
|
||||||
@ -831,9 +843,11 @@ def validate_pillow_dependencies(bench_path, requirements):
|
|||||||
|
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def get_bench_name(bench_path):
|
def get_bench_name(bench_path):
|
||||||
return os.path.basename(os.path.abspath(bench_path))
|
return os.path.basename(os.path.abspath(bench_path))
|
||||||
|
|
||||||
|
|
||||||
def setup_fonts():
|
def setup_fonts():
|
||||||
fonts_path = os.path.join('/tmp', 'fonts')
|
fonts_path = os.path.join('/tmp', 'fonts')
|
||||||
|
|
||||||
@ -848,6 +862,7 @@ def setup_fonts():
|
|||||||
shutil.rmtree(fonts_path)
|
shutil.rmtree(fonts_path)
|
||||||
exec_cmd("fc-cache -fv")
|
exec_cmd("fc-cache -fv")
|
||||||
|
|
||||||
|
|
||||||
def set_git_remote_url(git_url, bench_path='.'):
|
def set_git_remote_url(git_url, bench_path='.'):
|
||||||
"Set app remote git url"
|
"Set app remote git url"
|
||||||
app = git_url.rsplit('/', 1)[1].rsplit('.', 1)[0]
|
app = git_url.rsplit('/', 1)[1].rsplit('.', 1)[0]
|
||||||
@ -860,6 +875,7 @@ def set_git_remote_url(git_url, bench_path='.'):
|
|||||||
if os.path.exists(os.path.join(app_dir, '.git')):
|
if os.path.exists(os.path.join(app_dir, '.git')):
|
||||||
exec_cmd("git remote set-url upstream {}".format(git_url), cwd=app_dir)
|
exec_cmd("git remote set-url upstream {}".format(git_url), cwd=app_dir)
|
||||||
|
|
||||||
|
|
||||||
def run_playbook(playbook_name, extra_vars=None, tag=None):
|
def run_playbook(playbook_name, extra_vars=None, tag=None):
|
||||||
if not find_executable('ansible'):
|
if not find_executable('ansible'):
|
||||||
print("Ansible is needed to run this command, please install it using 'pip install ansible'")
|
print("Ansible is needed to run this command, please install it using 'pip install ansible'")
|
||||||
@ -874,6 +890,7 @@ def run_playbook(playbook_name, extra_vars=None, tag=None):
|
|||||||
|
|
||||||
subprocess.check_call(args, cwd=os.path.join(os.path.dirname(bench.__path__[0]), 'playbooks'))
|
subprocess.check_call(args, cwd=os.path.join(os.path.dirname(bench.__path__[0]), 'playbooks'))
|
||||||
|
|
||||||
|
|
||||||
def find_benches(directory=None):
|
def find_benches(directory=None):
|
||||||
if not directory:
|
if not directory:
|
||||||
directory = os.path.expanduser("~")
|
directory = os.path.expanduser("~")
|
||||||
@ -902,6 +919,7 @@ def find_benches(directory=None):
|
|||||||
|
|
||||||
return benches
|
return benches
|
||||||
|
|
||||||
|
|
||||||
def in_virtual_env():
|
def in_virtual_env():
|
||||||
# type: () -> bool
|
# type: () -> bool
|
||||||
"""Returns a boolean, whether running in venv with no system site-packages.
|
"""Returns a boolean, whether running in venv with no system site-packages.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user