當前位置: 首頁>>代碼示例>>Python>>正文


Python filecmp.cmpfiles方法代碼示例

本文整理匯總了Python中filecmp.cmpfiles方法的典型用法代碼示例。如果您正苦於以下問題:Python filecmp.cmpfiles方法的具體用法?Python filecmp.cmpfiles怎麽用?Python filecmp.cmpfiles使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在filecmp的用法示例。


在下文中一共展示了filecmp.cmpfiles方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_cmpfiles

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmpfiles [as 別名]
def test_cmpfiles(self):
        self.assertTrue(filecmp.cmpfiles(self.dir, self.dir, ['file']) ==
                        (['file'], [], []),
                        "Comparing directory to itself fails")
        self.assertTrue(filecmp.cmpfiles(self.dir, self.dir_same, ['file']) ==
                        (['file'], [], []),
                        "Comparing directory to same fails")

        # Try it with shallow=False
        self.assertTrue(filecmp.cmpfiles(self.dir, self.dir, ['file'],
                                         shallow=False) ==
                        (['file'], [], []),
                        "Comparing directory to itself fails")
        self.assertTrue(filecmp.cmpfiles(self.dir, self.dir_same, ['file'],
                                         shallow=False),
                        "Comparing directory to same fails")

        # Add different file2
        with open(os.path.join(self.dir, 'file2'), 'w') as output:
            output.write('Different contents.\n')

        self.assertFalse(filecmp.cmpfiles(self.dir, self.dir_same,
                                     ['file', 'file2']) ==
                    (['file'], ['file2'], []),
                    "Comparing mismatched directories fails") 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:27,代碼來源:test_filecmp.py

示例2: test_all_migration_scripts_samesies

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmpfiles [as 別名]
def test_all_migration_scripts_samesies():
    base_dir = file_relative_path(__file__, '../../dagster_postgres/')

    def _get_migration_files(store):
        event_log_path = os.path.join(base_dir, store, 'alembic', 'versions')
        return list(filter(lambda p: p.endswith('.py'), os.listdir(event_log_path)))

    def _get_versions_path(store):
        return os.path.join(base_dir, store, 'alembic', 'versions')

    migration_files = _get_migration_files('event_log')

    other_stores = ['run_storage', 'schedule_storage']

    for other_store in other_stores:
        # check that same set of files exists in each store
        assert set(_get_migration_files(other_store)) == set(migration_files)

    for other_store in other_stores:
        match, _mismatch, _errors = cmpfiles(
            _get_versions_path('event_log'), _get_versions_path(other_store), migration_files,
        )

        assert set(match) == set(migration_files) 
開發者ID:dagster-io,項目名稱:dagster,代碼行數:26,代碼來源:test_migration_scripts.py

示例3: test_cmpfiles

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmpfiles [as 別名]
def test_cmpfiles(self):
        self.assertTrue(filecmp.cmpfiles(self.dir, self.dir, ['file']) ==
                        (['file'], [], []),
                        "Comparing directory to itself fails")
        self.assertTrue(filecmp.cmpfiles(self.dir, self.dir_same, ['file']) ==
                        (['file'], [], []),
                        "Comparing directory to same fails")

        # Try it with shallow=False
        self.assertTrue(filecmp.cmpfiles(self.dir, self.dir, ['file'],
                                         shallow=False) ==
                        (['file'], [], []),
                        "Comparing directory to itself fails")
        self.assertTrue(filecmp.cmpfiles(self.dir, self.dir_same, ['file'],
                                         shallow=False),
                        "Comparing directory to same fails")

        # Add different file2
        output = open(os.path.join(self.dir, 'file2'), 'w')
        output.write('Different contents.\n')
        output.close()

        self.assertFalse(filecmp.cmpfiles(self.dir, self.dir_same,
                                     ['file', 'file2']) ==
                    (['file'], ['file2'], []),
                    "Comparing mismatched directories fails") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:28,代碼來源:test_filecmp.py

示例4: phase3

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmpfiles [as 別名]
def phase3(self):  # Find out differences between common files
        xx = filecmp.cmpfiles(self.left, self.right, self.common_files, shallow=False)
        self.same_files, self.diff_files, self.funny_files = xx 
開發者ID:glotzerlab,項目名稱:signac,代碼行數:5,代碼來源:syncutil.py

示例5: phase3

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmpfiles [as 別名]
def phase3(self): # Find out differences between common files
        xx = filecmp.cmpfiles(self.left, self.right, self.common_files, shallow=0)
        self.same_files, self.diff_files, self.funny_files = xx 
開發者ID:im-tomu,項目名稱:valentyusb,代碼行數:5,代碼來源:sdiff.py

示例6: are_dir_trees_equal

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmpfiles [as 別名]
def are_dir_trees_equal(dir1, dir2):
    """
    Compare two directories recursively. Files in each directory are
    assumed to be equal if their names and contents are equal.

    @param dir1: First directory path
    @param dir2: Second directory path

    @return: True if the directory trees are the same and 
        there were no errors while accessing the directories or files, 
        False otherwise.
   """

    dirs_cmp = filecmp.dircmp(dir1, dir2)
    if len(dirs_cmp.left_only)>0 or len(dirs_cmp.right_only)>0 or \
        len(dirs_cmp.funny_files)>0:

        if '.git' in dirs_cmp.left_only and len(dirs_cmp.left_only) == 1:
            return True
        if '.git' in dirs_cmp.right_only and len(dirs_cmp.right_only) == 1:
            return True

        print "dir1: {} and dir2: {} are unequal".format(dir1, dir2)
        print "left_only: {}, right_only: {}, funny_files: {}".format(
                dirs_cmp.left_only, dirs_cmp.right_only, dirs_cmp.funny_files)
 
        return False
    (_, mismatch, errors) =  filecmp.cmpfiles(
        dir1, dir2, dirs_cmp.common_files, shallow=False)
    if len(mismatch)>0 or len(errors)>0:
        print "File mismatch: {}, errors: {}".format(mismatch, errors)
        return False
    for common_dir in dirs_cmp.common_dirs:
        new_dir1 = os.path.join(dir1, common_dir)
        new_dir2 = os.path.join(dir2, common_dir)
        if not are_dir_trees_equal(new_dir1, new_dir2):
            return False
    return True 
開發者ID:gosquadron,項目名稱:squadron,代碼行數:40,代碼來源:helper.py

示例7: test_cmpfiles

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmpfiles [as 別名]
def test_cmpfiles(self):
        self.failUnless(filecmp.cmpfiles(self.dir, self.dir, ['file']) ==
                        (['file'], [], []),
                        "Comparing directory to itself fails")
        self.failUnless(filecmp.cmpfiles(self.dir, self.dir_same, ['file']) ==
                        (['file'], [], []),
                        "Comparing directory to same fails")

        # Try it with shallow=False
        self.failUnless(filecmp.cmpfiles(self.dir, self.dir, ['file'],
                                         shallow=False) ==
                        (['file'], [], []),
                        "Comparing directory to itself fails")
        self.failUnless(filecmp.cmpfiles(self.dir, self.dir_same, ['file'],
                                         shallow=False),
                        "Comparing directory to same fails")

        # Add different file2
        output = open(os.path.join(self.dir, 'file2'), 'w')
        output.write('Different contents.\n')
        output.close()

        self.failIf(filecmp.cmpfiles(self.dir, self.dir_same,
                                     ['file', 'file2']) ==
                    (['file'], ['file2'], []),
                    "Comparing mismatched directories fails") 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:28,代碼來源:test_filecmp.py

示例8: dir_is_same

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmpfiles [as 別名]
def dir_is_same(dir1, dir2):
    """
        Compare two directories recursively. Files in each directory are
    assumed to be equal if their names and contents are equal.
    Args:
        dir1: First directory path
        dir2: Second directory path

    Returns:
        True if the directory trees are the same and
        there were no errors while accessing the directories or files,
        False otherwise.

    """
    dirs_cmp = filecmp.dircmp(dir1, dir2)
    if len(dirs_cmp.left_only) > 0 or len(dirs_cmp.right_only) > 0 or \
            len(dirs_cmp.funny_files) > 0:
        return False
    (_, mismatch, errors) = filecmp.cmpfiles(
        dir1, dir2, dirs_cmp.common_files, shallow=False)
    if len(mismatch) > 0 or len(errors) > 0:
        return False
    for common_dir in dirs_cmp.common_dirs:
        new_dir1 = os.path.join(dir1, common_dir)
        new_dir2 = os.path.join(dir2, common_dir)
        if not dir_is_same(new_dir1, new_dir2):
            return False
    return True 
開發者ID:asyml,項目名稱:forte,代碼行數:30,代碼來源:utils.py


注:本文中的filecmp.cmpfiles方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。