def cli(): global from_command_line from_command_line = True check_uid() change_dir() change_uid() if len(sys.argv) > 2 and sys.argv[1] == "frappe": return old_frappe_cli() elif len(sys.argv) > 1 and sys.argv[1] in get_frappe_commands(): return frappe_cmd() elif len(sys.argv) > 1 and sys.argv[1] in ("--site", "--verbose", "--force", "--profile"): return frappe_cmd() elif len(sys.argv) > 1 and sys.argv[1]=="--help": print click.Context(bench_command).get_help() print print get_frappe_help() return elif len(sys.argv) > 1 and sys.argv[1] in get_apps(): return app_cmd() else: try: # NOTE: this is the main bench command bench_command() except PatchError: sys.exit(1)
def update_requirements(bench_path='.'): from bench.app import get_apps, install_app print('Installing applications...') update_env_pip(bench_path) for app in get_apps():
def migrate_env(python, backup=False): from bench.config.common_site_config import get_config from bench.app import get_apps log = logging.getLogger(__name__) log.setLevel(logging.DEBUG) nvenv = 'env' path = os.getcwd() python = which(python) virtualenv = which('virtualenv') pvenv = os.path.join(path, nvenv) pip = os.path.join(pvenv, 'bin', 'pip') # Clear Cache before Bench Dies. try: config = get_config(bench_path=os.getcwd()) rredis = urlparse(config['redis_cache']) redis = '{redis} -p {port}'.format(redis=which('redis-cli'), port=rredis.port) log.debug('Clearing Redis Cache...') exec_cmd('{redis} FLUSHALL'.format(redis=redis)) log.debug('Clearing Redis DataBase...') exec_cmd('{redis} FLUSHDB'.format(redis=redis)) except: log.warn('Please ensure Redis Connections are running or Daemonized.') # Backup venv: restore using `virtualenv --relocatable` if needed if backup: parch = os.path.join(path, 'archived_envs') if not os.path.exists(parch): os.mkdir(parch) source = os.path.join(path, 'env') target = parch log.debug('Backing up Virtual Environment') stamp = datetime.now().strftime('%Y%m%d_%H%M%S') dest = os.path.join(path, str(stamp)) os.rename(source, dest) shutil.move(dest, target) # Create virtualenv using specified python try: log.debug('Setting up a New Virtual {} Environment'.format(python)) exec_cmd('{virtualenv} --python {python} {pvenv}'.format( virtualenv=virtualenv, python=python, pvenv=pvenv)) apps = ' '.join( ["-e {}".format(os.path.join("apps", app)) for app in get_apps()]) exec_cmd('{0} install -q -U {1}'.format(pip, apps)) log.debug('Migration Successful to {}'.format(python)) except: log.debug('Migration Error') raise
def update_requirements(bench_path='.'): from bench.app import get_apps, install_app print('Updating Python libraries...') # update env pip update_env_pip(bench_path) for app in get_apps(): install_app(app, bench_path=bench_path, skip_assets=True)
def remote_urls(): "Show apps remote url" for app in get_apps(): repo_dir = get_repo_dir(app) if os.path.exists(os.path.join(repo_dir, '.git')): remote = get_remote(app) remote_url = subprocess.check_output(['git', 'config', '--get', 'remote.{}.url'.format(remote)], cwd=repo_dir).strip() print "{app} {remote_url}".format(app=app, remote_url=remote_url)
def remote_urls(): "Show apps remote url" for app in get_apps(): repo_dir = get_repo_dir(app) if os.path.exists(os.path.join(repo_dir, '.git')): remote = get_remote(app) remote_url = subprocess.check_output(['git', 'config', '--get', 'remote.{}.url'.format(remote)], cwd=repo_dir).strip() print("{app} {remote_url}".format(app=app, remote_url=remote_url))
def update_python_packages(bench_path='.'): from bench.app import get_apps pip_path = os.path.join(bench_path, "env", "bin", "pip") print('Updating Python libraries...') update_env_pip(bench_path) for app in get_apps(): print('\n{0}Installing python dependencies for {1}{2}'.format(color.yellow, app, color.nc)) app_path = os.path.join(bench_path, "apps", app) exec_cmd("{0} install -q -U -e {1}".format(pip_path, app_path), cwd=bench_path)
def update_requirements(bench_path='.'): from bench.app import get_apps, install_app print('Installing applications...') update_env_pip(bench_path) for app in get_apps(): install_app(app, bench_path=bench_path, skip_assets=True, restart_bench=False)
def remote_urls(): "Show apps remote url" for app in get_apps(): repo_dir = get_repo_dir(app) if os.path.exists(os.path.join(repo_dir, ".git")): remote = get_remote(app) remote_url = subprocess.check_output( ["git", "config", "--get", "remote.{}.url".format(remote)], cwd=repo_dir ).strip() print "{app} {remote_url}".format(app=app, remote_url=remote_url)
def update_requirements(bench_path='.'): from bench.app import get_apps, install_app print('Updating Python libraries...') # update env pip update_env_pip(bench_path) # Update bench requirements (at user level) update_bench_requirements() for app in get_apps(): install_app(app, bench_path=bench_path)
def cli(): global from_command_line from_command_line = True command = " ".join(sys.argv) change_working_directory() logger = setup_logging() logger.info(command) if len(sys.argv) > 1 and sys.argv[1] not in ("src", ): check_uid() change_uid() change_dir() if is_dist_editable(bench.PROJECT_NAME) and len( sys.argv) > 1 and sys.argv[1] != "src" and not get_config(".").get( "developer_mode"): log("bench is installed in editable mode!\n\nThis is not the recommended mode of installation for production. Instead, install the package from PyPI with: `pip install frappe-bench`\n", level=3) if not is_bench_directory() and not cmd_requires_root() and len( sys.argv) > 1 and sys.argv[1] not in ("init", "find", "src"): log("Command not being executed in bench directory", level=3) if len(sys.argv) > 2 and sys.argv[1] == "frappe": return old_frappe_cli() elif len(sys.argv) > 1: if sys.argv[1] in get_frappe_commands() + [ "--site", "--verbose", "--force", "--profile" ]: return frappe_cmd() elif sys.argv[1] == "--help": print(click.Context(bench_command).get_help()) print(get_frappe_help()) return elif sys.argv[1] in get_apps(): return app_cmd() if not (len(sys.argv) > 1 and sys.argv[1] == "src"): atexit.register(check_latest_version) try: bench_command() except BaseException as e: return_code = getattr(e, "code", 0) if return_code: logger.warning("{0} executed with exit code {1}".format( command, return_code)) sys.exit(return_code)
def update_requirements(bench_path='.'): print('Updating Python libraries...') pip = os.path.join(bench_path, 'env', 'bin', 'pip') exec_cmd("{pip} install --upgrade pip".format(pip=pip)) # Update bench requirements bench_req_file = os.path.join(os.path.dirname(bench.__path__[0]), 'requirements.txt') install_requirements(pip, bench_req_file) from bench.app import get_apps, install_app for app in get_apps(): install_app(app, bench_path=bench_path)
def update_requirements(bench_path='.'): print('Updating Python libraries...') pip = os.path.join(bench_path, 'env', 'bin', 'pip') exec_cmd("{pip} install --upgrade pip".format(pip=pip)) apps_dir = os.path.join(bench_path, 'apps') # Update bench requirements bench_req_file = os.path.join(os.path.dirname(bench.__path__[0]), 'requirements.txt') install_requirements(pip, bench_req_file) from bench.app import get_apps, install_app for app in get_apps(): install_app(app, bench_path=bench_path)
def update_requirements(bench_path='.'): print('Updating Python libraries...') # update env pip env_pip = os.path.join(bench_path, 'env', 'bin', 'pip') exec_cmd("{pip} install -q -U pip".format(pip=env_pip)) # Update bench requirements (at user level) bench_req_file = os.path.join(os.path.dirname(bench.__path__[0]), 'requirements.txt') user_pip = which("pip" if PY2 else "pip3") install_requirements(user_pip, bench_req_file, user=True) from bench.app import get_apps, install_app for app in get_apps(): install_app(app, bench_path=bench_path)
def update_requirements(bench_path='.'): print('Updating Python libraries...') pip = os.path.join(bench_path, 'env', 'bin', 'pip') cmd_str = "{pip} --version".format(pip=pip) pip_version = str(subprocess.check_output(cmd_str, shell=True)) #if pip version is 9.0.3 (for old versions of frappe/erpnext, DO NOT UPDATE pip if pip_version.split(' ')[1] != "9.0.3": exec_cmd("{pip} install --upgrade pip".format(pip=pip)) apps_dir = os.path.join(bench_path, 'apps') # Update bench requirements bench_req_file = os.path.join(os.path.dirname(bench.__path__[0]), 'requirements.txt') install_requirements(pip, bench_req_file) from bench.app import get_apps, install_app for app in get_apps(): install_app(app, bench_path=bench_path)