diff --git a/bench/app.py b/bench/app.py index 0710d65b..443156f3 100755 --- a/bench/app.py +++ b/bench/app.py @@ -215,7 +215,7 @@ def is_version_upgrade(app='frappe', bench_path='.', branch=None): local_version = get_major_version(get_current_version(app, bench_path=bench_path)) upstream_version = get_major_version(upstream_version) - + if upstream_version - local_version > 0: return (True, local_version, upstream_version) diff --git a/bench/commands/__init__.py b/bench/commands/__init__.py index e4ecb8c3..303e8149 100755 --- a/bench/commands/__init__.py +++ b/bench/commands/__init__.py @@ -9,7 +9,7 @@ from datetime import datetime from bench.utils import which, exec_cmd log = logging.getLogger(__name__) -log.setLevel(logging.ERROR) +log.setLevel(logging.DEBUG) def print_bench_version(ctx, param, value): """Prints current bench version""" @@ -82,6 +82,12 @@ bench_command.add_command(remote_urls) from bench.commands.install import install bench_command.add_command(install) +from bench.config.common_site_config import get_config +try: + from urlparse import urlparse +except ImportError: + from urllib.parse import urlparse + @click.command('migrate-env') @click.argument('python', type = str) @click.option('--no-backup', default = False, help = 'Do not backup the existing Virtual Environment') @@ -89,6 +95,23 @@ def migrate_env(python, no_backup = False): """ Migrate Virtual Environment to desired Python Version. """ + try: + # Clear Cache before Bench Dies. + 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 Exception: + log.warn('Please ensure Redis Connections are running or Daemonized.') + try: # This is with the assumption that a bench is set-up within path. path = os.getcwd() @@ -111,6 +134,7 @@ def migrate_env(python, no_backup = False): # WARNING: This is an archive, you might have to use virtualenv --relocate # That's because virtualenv creates symlinks with shebangs pointing to executables. + # shebangs, shebangs - ricky martin. # ...and shutil.copytree is a f*cking mess. os.rename(source, dest) diff --git a/bench/utils.py b/bench/utils.py index fd3db388..497bbb3f 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -16,6 +16,13 @@ logger = logging.getLogger(__name__) folders_in_bench = ('apps', 'sites', 'config', 'logs', 'config/pids') +def safe_decode(string, encoding = 'utf-8'): + try: + string = string.decode(encoding) + except Exception: + pass + return string + def get_frappe(bench_path='.'): frappe = get_env_cmd('frappe', bench_path=bench_path) if not os.path.exists(frappe): @@ -351,7 +358,7 @@ def get_git_version(): '''returns git version from `git --version` extracts version number from string `get version 1.9.1` etc''' version = get_cmd_output("git --version") - version = version.decode('utf-8') + version = safe_decode(version) version = version.strip().split()[2] version = '.'.join(version.split('.')[0:2]) return float(version) diff --git a/playbooks/install.py b/playbooks/install.py index fbced0d4..8abec392 100644 --- a/playbooks/install.py +++ b/playbooks/install.py @@ -59,7 +59,7 @@ def install_bench(args): }) success = run_os_command({ - 'pip': "sudo pip install ansible==2.4.1" + 'pip': "sudo pip install ansible==2.5.0" }) if not success: @@ -82,6 +82,14 @@ def install_bench(args): if args.user == 'root': raise Exception('Please run this script as a non-root user with sudo privileges, but without using sudo or pass --user=USER') + # Python executable + if not args.production: + dist_name, dist_version = get_distribution_info() + if dist_name=='centos': + args.python = 'python3.6' + else: + args.python = 'python3' + # create user if not exists extra_vars = vars(args) extra_vars.update(frappe_user=args.user) @@ -371,6 +379,11 @@ def parse_commandline_args(): parser.add_argument('--admin-password', dest='admin_password', help='Set admin password') parser.add_argument('--bench-name', dest='bench_name', help='Create bench with specified name. Default name is frappe-bench') + # Python interpreter to be used + parser.add_argument('--python', dest='python', default='python', + help=argparse.SUPPRESS + ) + args = parser.parse_args() return args diff --git a/playbooks/roles/bench/tasks/main.yml b/playbooks/roles/bench/tasks/main.yml index 0f2ed3c2..b6230e80 100644 --- a/playbooks/roles/bench/tasks/main.yml +++ b/playbooks/roles/bench/tasks/main.yml @@ -29,7 +29,7 @@ register: bench_stat - name: python3 bench init for develop - command: bench init {{ bench_path }} --frappe-branch {{ branch }} --python python3 + command: bench init {{ bench_path }} --frappe-branch {{ branch }} --python {{ python }} args: creates: "{{ bench_path }}" when: not bench_stat.stat.exists and not production diff --git a/playbooks/roles/common/tasks/redhat_family.yml b/playbooks/roles/common/tasks/redhat_family.yml index dfde2433..8604c0ae 100644 --- a/playbooks/roles/common/tasks/redhat_family.yml +++ b/playbooks/roles/common/tasks/redhat_family.yml @@ -1,5 +1,12 @@ --- +- name: Install IUS repo for python 3.6 + become: yes + become_user: root + yum: + name: https://centos7.iuscommunity.org/ius-release.rpm + state: present + - name: "Setup prerequisites using yum" become: yes become_user: root @@ -23,6 +30,7 @@ - ntp - openssl-devel - postfix + - python36u - python-devel - python-setuptools - python-pip