Example #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)
Example #2
0
def set_theme(name: str):
    '''Set the theme to NAME and redeploy.'''
    host_cfg = hostconfig.from_file(ACTIVE_HOST_PATH)
    templater = Templater(MODOT_PATH, host_cfg)
    if name not in templater.list_themes():
        sys.exit(f'Could not find specified theme {name}')
    templater.set_theme(name)
    _check_and_deploy(host_cfg, templater, dryrun=False)
Example #3
0
 def test_set_theme(self):
     '''Test setting the active theme.'''
     host_config = HostConfig(Path(self.theme_dir.name), None)
     templater = Templater(Path(self.link_dir.name), host_config)
     templater.set_theme('cooltheme')
     active_theme_path = Path(self.link_dir.name) / 'theme.yaml'
     self.assertEqual(  # this is maybe questionable
         Path(os.readlink(active_theme_path)),
         Path(self.theme_dir.name) / 'cooltheme.yaml')
Example #4
0
 def test_template_after_set_theme(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_theme_path = self.theme_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_theme_path.write_text('theme: newtheme')
     host_cfg = HostConfig(self.theme_dir, self.color_dir)
     templater = Templater(self.link_dir, host_cfg)
     templater.template('theme: {{theme}}\ncolor: {{color}}')
     templater.set_theme('new')
     out_str = templater.template('theme: {{theme}}\ncolor: {{color}}')
     self.assertEqual(out_str, 'theme: newtheme\ncolor: coolcolor')