当前位置: 首页>>代码示例>>Python>>正文


Python Dotfiles.add方法代码示例

本文整理汇总了Python中dotfiles.core.Dotfiles.add方法的典型用法代码示例。如果您正苦于以下问题:Python Dotfiles.add方法的具体用法?Python Dotfiles.add怎么用?Python Dotfiles.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dotfiles.core.Dotfiles的用法示例。


在下文中一共展示了Dotfiles.add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_packages

# 需要导入模块: from dotfiles.core import Dotfiles [as 别名]
# 或者: from dotfiles.core.Dotfiles import add [as 别名]
    def test_packages(self):
        """
        Test packages.
        """
        files = ['foo', 'package/bar', 'package2/foo/bar']
        symlinks = ['.foo', '.package/bar', '.package2/foo/bar']
        join = os.path.join

        # Create files
        for filename in files:
            path = join(self.repository, filename)
            dirname = os.path.dirname(path)
            if not os.path.exists(dirname):
                os.makedirs(dirname)
            touch(path)

        # Create Dotfiles object
        dotfiles = Dotfiles(
                homedir=self.homedir, path=self.repository,
                prefix='', ignore=[], externals={},
                packages=set(['package', 'package2/foo']), dry_run=False)

        # Create symlinks in homedir
        dotfiles.sync()

        # Verify it created what we expect
        for folder in ['.package', '.package2', '.package2/foo']:
            self.assertTrue(os.path.isdir(join(self.homedir, folder)))
        def check_all(files, symlinks):
            for src, dst in zip(files, symlinks):
                self.assertTrue(is_link_to(join(self.homedir, dst),
                    join(self.repository, src)))
        check_all(files, symlinks)

        # Add files to the repository
        new_files = [join(self.homedir, f) for f in 
                ['.bar', '.package/foo', '.package2/foo/bar2']]
        for filename in new_files:
            path = join(self.homedir, filename)
            touch(path)
        new_repo_files = ['bar', 'package/foo', 'package2/foo/bar2']
        dotfiles.add(new_files)
        check_all(files + new_repo_files, symlinks + new_files)

        # Remove them from the repository
        dotfiles.remove(new_files)
        check_all(files, symlinks)

        # Move the repository
        self.repository = join(self.homedir, 'Dotfiles2')
        dotfiles.move(self.repository)
        check_all(files, symlinks)
开发者ID:jeffrey4l,项目名称:dotfiles,代码行数:54,代码来源:test_basic.py

示例2: test_hosts_mode

# 需要导入模块: from dotfiles.core import Dotfiles [as 别名]
# 或者: from dotfiles.core.Dotfiles import add [as 别名]
    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')))
开发者ID:niol,项目名称:dotfiles,代码行数:47,代码来源:test_basic.py

示例3: test_missing_package

# 需要导入模块: from dotfiles.core import Dotfiles [as 别名]
# 或者: from dotfiles.core.Dotfiles import add [as 别名]
    def test_missing_package(self):
        """
        Test a non-existent package.
        """

        package_file = '.package/bar'

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

        path = os.path.join(self.homedir, package_file)
        dirname = os.path.dirname(path)
        if not os.path.exists(dirname):
            os.makedirs(dirname)
        touch(path)

        dotfiles.add([os.path.join(self.homedir, package_file)])
开发者ID:niol,项目名称:dotfiles,代码行数:21,代码来源:test_basic.py

示例4: test_add_package

# 需要导入模块: from dotfiles.core import Dotfiles [as 别名]
# 或者: from dotfiles.core.Dotfiles import add [as 别名]
    def test_add_package(self):
        """
        Test adding a package that isn't already in the repository

        """

        package_dir = os.path.join(self.homedir,
            '.%s/%s' % ('config', 'gtk-3.0'))

        os.makedirs(package_dir)
        touch('%s/testfile' % package_dir)

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

        # This should fail, you should not be able to add dotfiles that are
        # defined to be packages.
        dotfiles.add(['.config'])
        self.assertFalse(os.path.islink(os.path.join(self.homedir, '.config')))
开发者ID:IvanMalison,项目名称:dotfiles-1,代码行数:23,代码来源:test_basic.py

示例5: test_add_package_file

# 需要导入模块: from dotfiles.core import Dotfiles [as 别名]
# 或者: from dotfiles.core.Dotfiles import add [as 别名]
    def test_add_package_file(self):
        """
        Test adding a package that isn't already in the repository

        """

        package_dir = os.path.join(self.homedir,
                                   '.%s/%s' % ('config', 'gtk-3.0'))

        os.makedirs(package_dir)
        touch('%s/testfile' % package_dir)

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

        # This should succeed and the directory structure in the repository
        # should be created since it didn't already exist.
        df = os.path.join(self.homedir, '.config/gtk-3.0')
        dotfiles.add([df])
        self.assertTrue(os.path.islink(df))
开发者ID:niol,项目名称:dotfiles,代码行数:23,代码来源:test_basic.py

示例6: test_dotdir_file_add_sync_remove

# 需要导入模块: from dotfiles.core import Dotfiles [as 别名]
# 或者: from dotfiles.core.Dotfiles import add [as 别名]
    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')))
开发者ID:niol,项目名称:dotfiles,代码行数:68,代码来源:test_basic.py


注:本文中的dotfiles.core.Dotfiles.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。