Ejemplo n.º 1
0
def initialize():
    ''' Initialize the local project directory for boss. '''
    files_written = []
    fabfile = FABFILE_PATH
    config_file = DEFAULT_CONFIG_FILE

    # If config file doesn't exist create it.
    if not fs.exists(config_file):
        config_tmpl = fs.read(BASE_PATH + '/misc/boss.yml_template')
        config_tmpl = config_tmpl.format(
            project_name=DEFAULT_CONFIG['project_name'],
            user=DEFAULT_CONFIG['user'],
            deployment_preset=DEFAULT_CONFIG['deployment']['preset'],
            deployment_base_dir=DEFAULT_CONFIG['deployment']['base_dir']
        )
        fs.write(config_file, config_tmpl)
        files_written.append(config_file)

    # If fabfile doesn't exist create it.
    if not fs.exists(fabfile):
        fabfile_tmpl = fs.read(BASE_PATH + '/misc/fabfile.py_template')
        fs.write(fabfile, fabfile_tmpl)
        files_written.append(fabfile)

    return files_written
Ejemplo n.º 2
0
def initialize_config(interactive):
    '''
    Initialize a new boss.yml file.
    If the file already exists return None, else return the file.
    '''
    config_file = DEFAULT_CONFIG_FILE

    # If config already exists, return None
    if fs.exists(config_file):
        return None

    config_tmpl = fs.read(BASE_PATH + '/misc/boss.yml_template')

    if not interactive:
        tmpl_params = {
            'project_name': DEFAULT_CONFIG['project_name'],
            'user': DEFAULT_CONFIG['user'],
            'ssh_port': DEFAULT_CONFIG['port'],
            'deployment_preset': DEFAULT_CONFIG['deployment']['preset'],
            'deployment_base_dir': DEFAULT_CONFIG['deployment']['base_dir']
        }
    else:
        tmpl_params = get_initial_config_params()

    fs.write(config_file, config_tmpl.format(**tmpl_params))

    return config_file
Ejemplo n.º 3
0
def test_read():
    ''' Test fs.read() works. '''
    filename = 'somefile'
    data = 'somedata'

    with patch('__builtin__.open', mock_open(read_data=data)) as mock_file:
        assert fs.read(filename) == data
        mock_file.assert_called_with(filename, 'r')
Ejemplo n.º 4
0
def initialize_fabfile():
    '''
    Initialize a new fabfile.
    If the file already exists return None, else return the file.
    '''
    fabfile = FABFILE_PATH

    if not fs.exists(fabfile):
        fabfile_tmpl = fs.read(BASE_PATH + '/misc/fabfile.py_template')
        fs.write(fabfile, fabfile_tmpl)

        return fabfile
Ejemplo n.º 5
0
def test_get(server):
    ''' Test get() transfers remote file to the local. '''
    for uid in server.users:
        target_dir = tempfile.mkdtemp()
        source_file = os.path.join(target_dir, 'foo_src')
        target_file = os.path.join(target_dir, 'foo_dest')

        fs.write(source_file, 'Test get operation')
        assert not fs.exists(target_file)

        with server.client(uid) as client:
            sftp = client.open_sftp()
            remote.get(
                sftp,
                remote_path=source_file,
                local_path=target_file
            )
            assert fs.read(target_file) == 'Test get operation'