Пример #1
0
    def test_hosts_mode(self):
        """Test that host mode behaves correctly."""

        all_repo_files = (
            ('.vimrc', 'all'),
            ('.mozilla', 'guiworkstation'),
        )

        for homefile, host in all_repo_files:
            touch(os.path.join(self.homedir, homefile))

        os.makedirs(os.path.join(self.repository, 'all.host'))

        dotfiles = Dotfiles(homedir=self.homedir,
                            path=self.repository,
                            prefix='', ignore=[],
                            externals={}, packages=[], dry_run=False)
        self.assertTrue(dotfiles.hosts_mode())

        for homefile, host in all_repo_files:
            dotfiles.add([os.path.join(self.homedir, homefile)], host)
            self.verifyFileStatus(homefile, host)

        for homefile, host in all_repo_files:
            os.unlink(os.path.join(self.homedir, homefile))

        dotfiles._load()
        dotfiles.sync()
        self.verifyFileStatus('.vimrc', 'all')
        self.assertTrue(not os.path.exists(os.path.join(self.homedir,
                                           '.mozilla')))

        dotfiles._load()
        dotfiles.sync(hostname='guiworkstation')
        self.assertTrue(os.path.exists(os.path.join(self.homedir, '.mozilla')))

        dotfiles._load()
        dotfiles.remove([os.path.join(self.homedir, '.mozilla')],
                        'guiworkstation')

        dotfiles._load()
        dotfiles.sync(hostname='guiworkstation')
        self.verifyFileStatus('.vimrc', 'all')
        self.assertTrue(not os.path.islink(os.path.join(self.homedir,
                                                        '.mozilla')))
Пример #2
0
    def test_dotdir_file_add_sync_remove(self):
        """Test that is is possible to add files in dot-directories
        and that they are managed correctly.

        This is especially usefull for applications that mix state files and
        configuration files in their dot-directory, for instance :
            - .unison which contains *prf and state files
            - .lftp which contains rc (conf file) and log, cwd_history.
        """
        os.mkdir(os.path.join(self.homedir, '.unison'))
        os.mkdir(os.path.join(self.homedir, '.lftp'))
        all_repo_files = (
            ('.vimrc', True),
            ('.unison/home.prf', True),
            ('.unison/are8d491ed362b0a4cf3e8d77ef3e08a1c', False),
            ('.unison/fpe8d491ed362b0a4cf3e8d77ef3e08a1c', False),
            ('.lftp/log', False),
            ('.lftp/rc', True),
            ('.lftp/cwd_history', False),
        )
        repo_dir = '.ikiwiki'

        for homefile, in_repository in all_repo_files:
            touch(os.path.join(self.homedir, homefile))
        os.mkdir(os.path.join(self.homedir, repo_dir))

        dotfiles = Dotfiles(homedir=self.homedir,
                            path=self.repository,
                            prefix='', ignore=[],
                            externals={}, packages=[], dry_run=False)

        dotfiles.add([os.path.join(self.homedir, homefile)
                      for homefile, in_repo in all_repo_files
                      if in_repo])
        for homefile, in_repository in all_repo_files:
            if in_repository:
                self.verifyFileStatus(homefile)

            for dotdir in ('.unison', '.lftp'):
                homepath = os.path.join(self.homedir, dotdir)
                self.assertTrue(not os.path.islink(homepath))
                self.assertTrue(os.path.isdir(homepath))

        os.unlink(os.path.join(self.homedir, '.vimrc'))
        os.unlink(os.path.join(self.homedir, '.lftp/rc'))

        os.unlink(os.path.join(self.homedir, '.unison/home.prf'))
        touch(os.path.join(self.homedir, '.unison/home.prf'))

        dotfiles._load()  # refresh file states
        dotfiles.sync()
        for homefile in ('.vimrc', '.lftp/rc'):
            self.verifyFileStatus(homefile)
        self.assertTrue(not os.path.islink(os.path.join(self.homedir,
                                                        '.unison/home.prf')))
        self.assertTrue(os.path.isfile(os.path.join(self.homedir,
                                       '.unison/home.prf')))

        dotfiles._load()  # refresh file states
        dotfiles.sync(force=True)
        self.verifyFileStatus('.unison/home.prf')

        dotfiles.remove([os.path.join(self.homedir, '.lftp/rc')])
        self.assertTrue(not os.path.islink(os.path.join(self.homedir,
                                                        '.lftp/rc')))
        self.assertTrue(os.path.isfile(os.path.join(self.homedir, '.lftp/rc')))