2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-12 00:06:36 +00:00

Merge pull request #998 from gavindsouza/drop-dead-code

chore: drop dead code
This commit is contained in:
gavin 2020-05-21 10:45:07 +05:30 committed by GitHub
commit 119b08f531
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1 additions and 147 deletions

View File

@ -58,18 +58,6 @@ def write_appstxt(apps, bench_path='.'):
with open(os.path.join(bench_path, 'sites', 'apps.txt'), 'w') as f: with open(os.path.join(bench_path, 'sites', 'apps.txt'), 'w') as f:
return f.write('\n'.join(apps)) return f.write('\n'.join(apps))
def check_url(url, raise_err=True):
from six.moves.urllib.parse import urlparse
parsed = urlparse(url)
if not parsed.scheme:
if raise_err:
raise TypeError('{url} Not a valid URL'.format(url=url))
else:
return False
return True
def is_git_url(url): def is_git_url(url):
# modified to allow without the tailing .git from https://github.com/jonschlinkert/is-git-url.git # modified to allow without the tailing .git from https://github.com/jonschlinkert/is-git-url.git
pattern = r"(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\.git)?(\/?|\#[-\d\w._]+?)$" pattern = r"(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\.git)?(\/?|\#[-\d\w._]+?)$"
@ -364,10 +352,6 @@ def get_upstream_version(app, branch=None, bench_path='.'):
raise raise
return get_version_from_string(contents) return get_version_from_string(contents)
def get_upstream_url(app, bench_path='.'):
repo_dir = get_repo_dir(app, bench_path=bench_path)
return subprocess.check_output(['git', 'config', '--get', 'remote.upstream.url'], cwd=repo_dir).strip()
def get_repo_dir(app, bench_path='.'): def get_repo_dir(app, bench_path='.'):
return os.path.join(bench_path, 'apps', app) return os.path.join(bench_path, 'apps', app)

View File

@ -80,6 +80,7 @@ def remove_common_config(keys):
config.add_command(config_restart_supervisor_on_update) config.add_command(config_restart_supervisor_on_update)
config.add_command(config_restart_systemd_on_update) config.add_command(config_restart_systemd_on_update)
config.add_command(config_dns_multitenant) config.add_command(config_dns_multitenant)
config.add_command(config_rebase_on_pull)
config.add_command(config_serve_default_site) config.add_command(config_serve_default_site)
config.add_command(config_http_timeout) config.add_command(config_http_timeout)
config.add_command(set_common_config) config.add_command(set_common_config)

View File

@ -4,7 +4,6 @@ import sys
# imports - third party imports # imports - third party imports
import click import click
from six import PY3
# imports - module imports # imports - module imports
import bench.config.lets_encrypt import bench.config.lets_encrypt

View File

@ -172,9 +172,7 @@ def prepare_sites(config, bench_path):
if not dns_multitenant: if not dns_multitenant:
message = "Port configuration list:" message = "Port configuration list:"
port_config_index = 0
for site in sites_configs: for site in sites_configs:
port_config_index += 1
message += "\n\nSite {0} assigned port: {1}".format(site["name"], site["port"]) message += "\n\nSite {0} assigned port: {1}".format(site["name"], site["port"])
print(message) print(message)

View File

@ -10,7 +10,6 @@ import json
import logging import logging
import multiprocessing import multiprocessing
import os import os
import platform
import pwd import pwd
import re import re
import select import select
@ -486,14 +485,6 @@ def start(no_dev=False, concurrency=None, procfile=None):
os.execv(program, command) os.execv(program, command)
def check_cmd(cmd, cwd='.'):
try:
subprocess.check_call(cmd, cwd=cwd, shell=True)
return True
except subprocess.CalledProcessError:
return False
def get_git_version(): def get_git_version():
'''returns git version from `git --version` '''returns git version from `git --version`
extracts version number from string `get version 1.9.1` etc''' extracts version number from string `get version 1.9.1` etc'''
@ -532,15 +523,6 @@ def get_cmd_output(cmd, cwd='.', _raise=True):
return safe_decode(output) return safe_decode(output)
def safe_encode(what, encoding = 'utf-8'):
try:
what = what.encode(encoding)
except Exception:
pass
return what
def restart_supervisor_processes(bench_path='.', web_workers=False): def restart_supervisor_processes(bench_path='.', web_workers=False):
from .config.common_site_config import get_config from .config.common_site_config import get_config
conf = get_config(bench_path=bench_path) conf = get_config(bench_path=bench_path)
@ -672,21 +654,6 @@ def update_npm_packages(bench_path='.'):
exec_cmd('npm install', cwd=bench_path) exec_cmd('npm install', cwd=bench_path)
def install_requirements(req_file, user=False):
if os.path.exists(req_file):
if user:
python = sys.executable
else:
python = os.path.join("env", "bin", "python")
if in_virtual_env():
user = False
user_flag = "--user" if user else ""
exec_cmd("{python} -m pip install {user_flag} -q -U -r {req_file}".format(python=python, user_flag=user_flag, req_file=req_file))
def backup_site(site, bench_path='.'): def backup_site(site, bench_path='.'):
bench.set_frappe_version(bench_path=bench_path) bench.set_frappe_version(bench_path=bench_path)
@ -780,19 +747,6 @@ def fix_prod_setup_perms(bench_path='.', frappe_user=None):
os.chown(path, uid, gid) os.chown(path, uid, gid)
def fix_file_perms():
for dir_path, dirs, files in os.walk('.'):
for _dir in dirs:
os.chmod(os.path.join(dir_path, _dir), 0o755)
for _file in files:
os.chmod(os.path.join(dir_path, _file), 0o644)
bin_dir = './env/bin'
if os.path.exists(bin_dir):
for _file in os.listdir(bin_dir):
if not _file.startswith('activate'):
os.chmod(os.path.join(bin_dir, _file), 0o755)
def get_current_frappe_version(bench_path='.'): def get_current_frappe_version(bench_path='.'):
from .app import get_current_frappe_version as fv from .app import get_current_frappe_version as fv
return fv(bench_path=bench_path) return fv(bench_path=bench_path)
@ -823,13 +777,6 @@ def run_frappe_cmd(*args, **kwargs):
sys.exit(return_code) sys.exit(return_code)
def get_frappe_cmd_output(*args, **kwargs):
bench_path = kwargs.get('bench_path', '.')
f = get_env_cmd('python', bench_path=bench_path)
sites_dir = os.path.join(bench_path, 'sites')
return subprocess.check_output((f, '-m', 'frappe.utils.bench_helper', 'frappe') + args, cwd=sites_dir)
def validate_upgrade(from_ver, to_ver, bench_path='.'): def validate_upgrade(from_ver, to_ver, bench_path='.'):
if to_ver >= 6: if to_ver >= 6:
if not find_executable('npm') and not (find_executable('node') or find_executable('nodejs')): if not find_executable('npm') and not (find_executable('node') or find_executable('nodejs')):
@ -939,13 +886,6 @@ def log_line(data, stream):
return sys.stdout.write(data) return sys.stdout.write(data)
def get_output(*cmd):
s = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
out = s.stdout.read()
s.stdout.close()
return out
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))
@ -1022,78 +962,10 @@ def find_benches(directory=None):
return benches return benches
def in_virtual_env():
# type: () -> bool
"""Returns a boolean, whether running in venv with no system site-packages.
pip really does the best job at this: virtualenv_no_global at https://raw.githubusercontent.com/pypa/pip/master/src/pip/_internal/utils/virtualenv.py
"""
def running_under_venv():
# handles PEP 405 compliant virtual environments.
return sys.prefix != getattr(sys, "base_prefix", sys.prefix)
def running_under_regular_virtualenv():
# pypa/virtualenv case
return hasattr(sys, 'real_prefix')
def _no_global_under_venv():
# type: () -> bool
"""Check `{sys.prefix}/pyvenv.cfg` for system site-packages inclusion
PEP 405 specifies that when system site-packages are not supposed to be
visible from a virtual environment, `pyvenv.cfg` must contain the following
line:
include-system-site-packages = false
Additionally, log a warning if accessing the file fails.
"""
def _get_pyvenv_cfg_lines():
pyvenv_cfg_file = os.path.join(sys.prefix, 'pyvenv.cfg')
try:
with open(pyvenv_cfg_file) as f:
return f.read().splitlines() # avoids trailing newlines
except IOError:
return None
_INCLUDE_SYSTEM_SITE_PACKAGES_REGEX = re.compile(
r"include-system-site-packages\s*=\s*(?P<value>true|false)"
)
cfg_lines = _get_pyvenv_cfg_lines()
if cfg_lines is None:
# We're not in a "sane" venv, so assume there is no system
# site-packages access (since that's PEP 405's default state).
return True
for line in cfg_lines:
match = _INCLUDE_SYSTEM_SITE_PACKAGES_REGEX.match(line)
if match is not None and match.group('value') == 'false':
return True
return False
def _no_global_under_regular_virtualenv():
# type: () -> bool
"""Check if "no-global-site-packages.txt" exists beside site.py
This mirrors logic in pypa/virtualenv for determining whether system
site-packages are visible in the virtual environment.
"""
site_mod_dir = os.path.dirname(os.path.abspath(site.__file__))
no_global_site_packages_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt')
return os.path.exists(no_global_site_packages_file)
if running_under_regular_virtualenv():
return _no_global_under_regular_virtualenv()
if running_under_venv():
return _no_global_under_venv()
return False
def migrate_env(python, backup=False): def migrate_env(python, backup=False):
from bench.config.common_site_config import get_config from bench.config.common_site_config import get_config
from bench.app import get_apps from bench.app import get_apps
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
nvenv = 'env' nvenv = 'env'
path = os.getcwd() path = os.getcwd()
python = which(python) python = which(python)