def print_deploy_deprecation(): print(color_summary('Hi. Things have changed.')) print() print( 'The `commcare-cloud <env> fab deploy` command has been deprecated.' ) print('Instead, please use') print() print(color_highlight(' commcare-cloud <env> deploy')) print() print("For info on how you can use the new command, please see") print( color_link( "https://dimagi.github.io/commcare-cloud/commcare-cloud/commands/#deploy" )) print("or run") print() print(color_highlight(' commcare-cloud <env> deploy -h')) print() print("For more information on this change, please see") print( color_link( "https://dimagi.github.io/commcare-cloud/changelog/0029-add-deploy-command.html" )) print() print(color_summary('Thank you for using commcare-cloud.')) print()
def run(self, args, unknown_args): check_branch(args) environment = get_environment(args.env_name) deploy_revs = self._confirm_deploy_revs(environment, args, quiet=args.quiet) deploy_component = args.component if deploy_component == None: deploy_component = 'both' if environment.meta_config.always_deploy_formplayer else 'commcare' if deploy_component in ['commcare', 'both']: print(color_summary("You are about to deploy the following code:")) with indent(): for name, rev in deploy_revs: print(color_summary("{}: {}".format(name, rev))) if ask('Continue with deploy?', quiet=args.quiet): if deploy_component != 'both': _warn_no_formplayer() self.deploy_commcare(environment, deploy_revs, args, unknown_args) if deploy_component in ['formplayer', 'both']: if deploy_component != 'both': if args.commcare_rev: print(color_warning('--commcare-rev does not apply to a formplayer deploy and will be ignored')) if args.fab_settings: print(color_warning('--set does not apply to a formplayer deploy and will be ignored')) self._announce_formplayer_deploy_start(environment) self.deploy_formplayer(environment, args, unknown_args)
def send_email(environment, subject, message='', to_admins=True, recipients=None): """ Call a Django management command to send an email. :param environment: The Environement object :param subject: Email subject :param message: Email message :param to_admins: True if mail should be sent to Django admins :param recipients: List of additional addresses to send mail to """ if environment.fab_settings_config.email_enabled: print(color_summary(f">> Sending email: {subject}")) args = [ message, '--subject', subject, '--html', ] if to_admins: args.append('--to-admins') if recipients: if isinstance(recipients, list): recipients = ','.join(recipients) args.extend(['--recipients', recipients]) commcare_cloud( environment.name, 'django-manage', '--quiet', 'send_email', *args, show_command=False )
def _write_load_config_sh(self, environments_dir, quiet): puts(color_summary("Let's get you set up to run commcare-cloud.")) if not environments_dir: environments_dir = self._determine_environments_dir(quiet=quiet) commcare_cloud_dir = os.path.expanduser("~/.commcare-cloud") if not os.path.exists(commcare_cloud_dir): os.makedirs(commcare_cloud_dir) load_config_file = os.path.expanduser( "~/.commcare-cloud/load_config.sh") if not os.path.exists(load_config_file) or \ ask("Overwrite your ~/.commcare-cloud/load_config.sh?", quiet=quiet): with open(load_config_file, 'w') as f: f.write( textwrap.dedent(""" # auto-generated with `manage-commcare-cloud configure`: export COMMCARE_CLOUD_ENVIRONMENTS={COMMCARE_CLOUD_ENVIRONMENTS} export PATH=$PATH:{virtualenv_path} source {PACKAGE_BASE}/.bash_completion """.format( COMMCARE_CLOUD_ENVIRONMENTS=shlex_quote( environments_dir), virtualenv_path=get_virtualenv_bin_path(), PACKAGE_BASE=PACKAGE_BASE, )).strip()) puts(color_notice("Add the following to your ~/.bash_profile:")) puts(color_code("source ~/.commcare-cloud/load_config.sh")) puts( color_notice( "and then open a new shell. " "You should be able to run `commcare-cloud` without entering your virtualenv." ))
def commit(migration, ansible_context): print_allocation(migration) alloc_docs_by_db = {plan.db_name: plan for plan in migration.shard_plan} puts(color_summary("Checking shards on disk vs plan. Please wait.")) if not assert_files(migration, alloc_docs_by_db, ansible_context): puts(color_error("Some shard files are not where we expect. Have you run 'migrate'?")) puts(color_error("Aborting")) return 1 else: puts(color_success("All shards appear to be where we expect according to the plan.")) if ask("Are you sure you want to update the Couch Database config?"): commit_migration(migration) diff_with_db = diff_plan(migration) if diff_with_db: puts(color_error('DB allocation differs from expected:\n')) puts("{}\n\n".format(diff_with_db)) puts("Check the DB state and logs and maybe try running 'commit' again?") return 1 puts(color_highlight("New shard allocation:\n")) print_shard_table([ get_shard_allocation(migration.target_couch_config, db_name) for db_name in sorted(get_db_list(migration.target_couch_config.get_control_node())) ]) return 0
def run(self, args, unknown_args): check_branch(args) environment = get_environment(args.env_name) commcare_rev = self._confirm_commcare_rev(environment, args.commcare_rev, quiet=args.quiet) deploy_component = args.component if deploy_component == None: deploy_component = 'both' if environment.meta_config.always_deploy_formplayer else 'commcare' if deploy_component in ['commcare', 'both']: print(color_summary("You are about to deploy commcare from {}".format(commcare_rev))) if ask('Deploy commcare?', quiet=args.quiet): if deploy_component != 'both': _warn_no_formplayer() self.deploy_commcare(environment, commcare_rev, args, unknown_args) if deploy_component in ['formplayer', 'both']: if deploy_component != 'both': if args.commcare_rev: print(color_warning('--commcare-rev does not apply to a formplayer deploy and will be ignored')) if args.fab_settings: print(color_warning('--set does not apply to a formplayer deploy and will be ignored')) self._announce_formplayer_deploy_start(environment) self.deploy_formplayer(environment, args, unknown_args)