Beispiel #1
0
def deploy(host: str, theme_flag: str, color_flag: str, interactive: bool,
           dryrun: bool):
    '''Configure and deploy dotfiles using configuration from HOST.'''
    host_path = Path(host)
    deployed_host_tgt = hostconfig.get_deployed_host(ACTIVE_HOST_PATH)
    if deployed_host_tgt:
        if deployed_host_tgt == host_path:
            print(f'Redeploying same host: {str(deployed_host_tgt)}')
        else:
            ACTIVE_HOST_PATH.unlink()
            ACTIVE_HOST_PATH.symlink_to(host_path)
            print(f'Deploying over old host: {str(deployed_host_tgt)}')
    else:
        print('Deploying host config: ' + str(host_path))
        ACTIVE_HOST_PATH.symlink_to(host_path)
    host_cfg = hostconfig.from_file(ACTIVE_HOST_PATH)
    templater = Templater(MODOT_PATH, host_cfg)
    if interactive:
        theme_name = _pick_theme_interactive(templater, host_cfg, theme_flag)
        color_name = _pick_color_interactive(templater, host_cfg, color_flag)
    else:
        theme_name = _pick_theme_noninteractive(templater, host_cfg,
                                                theme_flag)
        color_name = _pick_color_noninteractive(templater, host_cfg,
                                                color_flag)
    templater.set_theme(theme_name)
    templater.set_color(color_name)
    _check_and_deploy(host_cfg, templater, dryrun)
Beispiel #2
0
def set_color(name: str):
    '''Set the color to NAME and redeploy.'''
    host_cfg = hostconfig.from_file(ACTIVE_HOST_PATH)
    templater = Templater(MODOT_PATH, host_cfg)
    if name not in templater.list_colors():
        sys.exit(f'Could not find specified color {name}')
    templater.set_color(name)
    _check_and_deploy(host_cfg, templater, dryrun=False)
Beispiel #3
0
 def test_set_color(self):
     '''Test setting the active color.'''
     host_config = HostConfig(Path(self.color_dir.name),
                              Path(self.color_dir.name))
     templater = Templater(Path(self.link_dir.name), host_config)
     templater.set_color('coolcolor')
     active_color_path = Path(self.link_dir.name) / 'color.yaml'
     self.assertEqual(  # this is maybe questionable
         Path(os.readlink(active_color_path)),
         Path(self.color_dir.name) / 'coolcolor.yaml')
Beispiel #4
0
 def test_template_after_set_color(self):
     '''Test that set_color changes the output even after first use.'''
     theme_path = self.theme_dir / 'main.yaml'
     color_path = self.color_dir / 'main.yaml'
     new_color_path = self.color_dir / 'new.yaml'
     (self.link_dir / 'theme.yaml').symlink_to(theme_path)
     (self.link_dir / 'color.yaml').symlink_to(color_path)
     theme_path.write_text('theme: cooltheme')
     color_path.write_text('color: coolcolor')
     new_color_path.write_text('color: newcolor')
     host_cfg = HostConfig(self.theme_dir, self.color_dir)
     templater = Templater(self.link_dir, host_cfg)
     templater.template('theme: {{theme}}\ncolor: {{color}}')
     templater.set_color('new')
     out_str = templater.template('theme: {{theme}}\ncolor: {{color}}')
     self.assertEqual(out_str, 'theme: cooltheme\ncolor: newcolor')