Exemple #1
0
def init(name):
    print_header()
    if os.path.exists(name):
        print('File already exists, exiting...')
        sys.exit(1)

    app_type = query_options('Type of application', 'python', 'javascript')
    dvcs = query_options('Source Control version', 'git', 'hg')

    profile_name = raw_input('AWS Profile to use: ')
    profile_exists = AWSProfile.exists(profile_name)

    if not profile_exists:
        should_create_profile = query_yes_no('Do you want to create this profile?: ')
        if not should_create_profile:
            sys.exit(1)

        access_key_id = raw_input('AWS Access Key Id: ')
        access_secret_key = raw_input('AWS Secret Access Key: ')

        AWSProfile.save(profile_name, access_key_id, access_secret_key)

    config_values = {}
    config_template = Config.load_from_template()

    for key, components in config_template.iteritems():
        if key in ['bifrost', 'application', 'dvcs']:
            continue
        if key == 'roles':
            print('Roles...')
            config_values['roles'] = {}
            number_of_roles = raw_input('Number required: ')
            for i in range(0, int(number_of_roles)):
                builder = ConfigBuilder('role {0}'.format(i), {'name': '', 'tag-key': 'my-role'})

                values = builder.prompt_user()
                role_name = values.pop('name')
                config_values['roles'][role_name] = values
        else:
            builder = ConfigBuilder(key, components)
            if key == 'connection':
                builder.change_question('aws_profile', skip=True)
            elif key == 'deployment':
                builder.change_question('base_dir', required=True)
            elif key == 'repository':
                builder.change_question('repository', required=True)

            config_values[key] = builder.prompt_user()
            if key == 'repository':
                config_values[key] = config_values[key][key]

    if config_values:
        Config.save(name=name, application_type=app_type, dvcs=dvcs, **config_values)
        if not os.path.exists(FABRIC_FILE_NAME):
            Fabric.save(FABRIC_FILE_NAME,
                        roles=list(config_values['roles'].iterkeys()))
    else:
        print('No configuration loaded')
    def test_can_generate_fab_file_with_deploy_role2_task(self):
        Fabric.save(self.file_name, roles=['role2'])

        signature = "@roles('role2')\ndef deploy_role2(branch, install_pkgs=False):"

        self.assertIn(signature, self.__read_file())
    def test_can_generate_fab_file_with_deploy_task(self):
        Fabric.save(self.file_name)

        signature = "def deploy(branch, install_pkgs=False):"

        self.assertIn(signature, self.__read_file())
 def test_can_generate_placeholder_fab_file(self):
     Fabric.save(self.file_name)
     self.assertTrue(os.path.exists(self.file_name))