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


Python filecmp.cmp方法代碼示例

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


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

示例1: SyncShadowHash

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmp [as 別名]
def SyncShadowHash(username, shadow_name):
  """Sync the password hash for the shadow admin account with the user's."""
  shadow_guid = UserAttribute(shadow_name, 'GeneratedUID')
  user_hash = '/var/db/shadow/hash/%s' % username
  if not os.path.exists(user_hash):
    user_guid = UserAttribute(username, 'GeneratedUID')[0]
    user_hash = '/var/db/shadow/hash/%s' % user_guid
  shadow_hash = '/var/db/shadow/hash/%s' % shadow_guid[0]

  try:
    if (os.path.exists(shadow_hash)
        and os.path.isfile(shadow_hash)
        and filecmp.cmp(user_hash, shadow_hash, shallow=False)):
      # everything is as should be
      pass
    else:
      shutil.copy2(user_hash, shadow_hash)
  except (IOError, OSError), err:
    raise DSException('Error creating the shadow admin hash for '
                      '%s-admin: %s' % (username, err)) 
開發者ID:google,項目名稱:macops,代碼行數:22,代碼來源:ds.py

示例2: main

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmp [as 別名]
def main():
    files = [os.path.join(root, file) for root, dir, files in os.walk('.') for file in files]
    no_symlink = 'You cannot use symlinks in typeshed, please copy {} to its link.'
    for file in files:
        _, ext = os.path.splitext(file)
        if ext == '.pyi' and os.path.islink(file):
            raise ValueError(no_symlink.format(file))
    for file1, *others in consistent_files:
        f1 = os.path.join(os.getcwd(), file1)
        for file2 in others:
            f2 = os.path.join(os.getcwd(), file2)
            if not filecmp.cmp(f1, f2):
                raise ValueError(
                    "File {f1} does not match file {f2}. Please copy it to {f2}\n"
                    "Run either:\ncp {f1} {f2}\nOr:\ncp {f2} {f1}".format(f1=file1, f2=file2)
                ) 
開發者ID:python,項目名稱:typeshed,代碼行數:18,代碼來源:check_consistent.py

示例3: test_auto_compress_off_gcp

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmp [as 別名]
def test_auto_compress_off_gcp(tmpdir, conn_cnx, db_parameters):
    """[gcp] Puts and Gets a small text using gcp with no auto compression."""
    fname = str(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'example.json'))
    with conn_cnx(
            user=db_parameters['gcp_user'],
            account=db_parameters['gcp_account'],
            password=db_parameters['gcp_password'],
    ) as cnx:
        with cnx.cursor() as cursor:
            try:
                cursor.execute("create or replace stage teststage")
                cursor.execute("put file://{} @teststage auto_compress=false".format(fname))
                cursor.execute("get @teststage file://{}".format(str(tmpdir)))
                downloaded_file = os.path.join(str(tmpdir), 'example.json')
                assert cmp(fname, downloaded_file)
            finally:
                cursor.execute("drop stage teststage") 
開發者ID:snowflakedb,項目名稱:snowflake-connector-python,代碼行數:19,代碼來源:test_put_get_for_gcp_account.py

示例4: test_contour_to_geojson_extra_properties

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmp [as 別名]
def test_contour_to_geojson_extra_properties(self):
        contour = self.create_contour()
        ndigits = 3
        geojson_properties = {
            'description': 'A description',
            'stroke-opacity': 1.0
        }
        geojsoncontour.contour_to_geojson(
            contour=contour,
            geojson_filepath=self.geojson_properties_file,
            min_angle_deg=self.config.min_angle_between_segments,
            ndigits=ndigits,
            unit=self.config.unit,
            stroke_width=5,
            geojson_properties=geojson_properties
        )
        self.assertTrue(os.path.exists(self.geojson_properties_file))
        self.assertTrue(filecmp.cmp(self.benchmark_geojson_properties_file, self.geojson_properties_file))
        os.remove(self.geojson_properties_file) 
開發者ID:bartromgens,項目名稱:geojsoncontour,代碼行數:21,代碼來源:test.py

示例5: test_file_contents

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmp [as 別名]
def test_file_contents(downloader):
    dl, dl_path = downloader

    filing_type = "8-K"
    ticker = "AAPL"
    before_date = "20191115"

    num_downloaded = dl.get(filing_type, ticker, 1, before_date=before_date)
    assert num_downloaded == 1

    downloaded_file_path = dl_path / "sec_edgar_filings" / ticker / filing_type
    downloaded_filings = list(downloaded_file_path.glob("*"))
    assert len(downloaded_filings) == 1
    downloaded_file_path = downloaded_file_path / downloaded_filings[0]

    # https://stackoverflow.com/q/1072569
    expected_data_path = Path(f"tests/sample_filings/apple_8k_{before_date}.txt")
    if expected_data_path.exists():
        # Only run this check if the sample filing exists
        # This check is required since the distributed python package will not
        # contain the sample filings test data due to size constraints
        assert filecmp.cmp(expected_data_path, downloaded_file_path, shallow=False) 
開發者ID:jadchaar,項目名稱:sec-edgar-downloader,代碼行數:24,代碼來源:test_file_structure_and_content.py

示例6: _binarycmp

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmp [as 別名]
def _binarycmp(filelist, onerror):
    file0, file1 = filelist

    try:
        if filecmp(file0.path, file1.path, shallow=False):
            dupdict = {True: filelist}
        else:
            dupdict = {}
        errlist = []

    except (IOError, OSError) as exc:
        if onerror is not None:
            onerror(exc, abspath(exc.filename))
        dupdict = {}
        errlist = filelist

    return dupdict, errlist 
開發者ID:deplicate,項目名稱:deplicate,代碼行數:19,代碼來源:core.py

示例7: sorter

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmp [as 別名]
def sorter(user_directory, api_type, location, metadata):
    legacy_directory = os.path.join(user_directory, api_type, location)
    if not os.path.isdir(legacy_directory):
        return
    legacy_files = os.listdir(legacy_directory)
    metadata_directory = os.path.join(
        user_directory, "Metadata", api_type+".json")
    results = list(chain(*metadata["valid"]))
    for result in results:
        legacy_filepath = os.path.join(legacy_directory, result["filename"])
        filepath = os.path.join(result["directory"], result["filename"])
        if result["filename"] in legacy_files:
            if os.path.isfile(filepath):
                same_file = filecmp.cmp(
                    legacy_filepath, filepath, shallow=False)
                if same_file:
                    os.remove(filepath)
                else:
                    os.remove(legacy_filepath)
                    continue
            shutil.move(legacy_filepath, filepath)
    if not os.listdir(legacy_directory):
        os.removedirs(legacy_directory) 
開發者ID:DIGITALCRIMINAL,項目名稱:OnlyFans,代碼行數:25,代碼來源:ofsorter.py

示例8: _config_changed

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmp [as 別名]
def _config_changed(self):
        secrets_file = os.path.join(
            self.etc_dir, 'ipsec.secrets')
        config_file = os.path.join(
            self.etc_dir, 'ipsec.conf')

        if not os.path.isfile(secrets_file + '.old'):
            return True
        if not os.path.isfile(config_file + '.old'):
            return True

        if not filecmp.cmp(secrets_file, secrets_file + '.old'):
            return True
        if not filecmp.cmp(config_file, config_file + '.old'):
            return True

        return False 
開發者ID:openstack,項目名稱:neutron-vpnaas,代碼行數:19,代碼來源:ipsec.py

示例9: test_uncompress_file

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmp [as 別名]
def test_uncompress_file(self):
        # Testing txt file type
        self.assertRaisesRegex(NotImplementedError,
                               "^Received .txt format. Only gz and bz2.*",
                               compression.uncompress_file,
                               **{'input_file_name': None,
                                  'file_extension': '.txt',
                                  'dest_dir': None
                                  })
        # Testing gz file type
        fn_txt = self._get_fn('.txt')
        fn_gz = self._get_fn('.gz')
        txt_gz = compression.uncompress_file(fn_gz, '.gz', self.tmp_dir)
        self.assertTrue(filecmp.cmp(txt_gz, fn_txt, shallow=False),
                        msg="Uncompressed file doest match original")
        # Testing bz2 file type
        fn_bz2 = self._get_fn('.bz2')
        txt_bz2 = compression.uncompress_file(fn_bz2, '.bz2', self.tmp_dir)
        self.assertTrue(filecmp.cmp(txt_bz2, fn_txt, shallow=False),
                        msg="Uncompressed file doest match original") 
開發者ID:apache,項目名稱:airflow,代碼行數:22,代碼來源:test_compression.py

示例10: helper

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmp [as 別名]
def helper(Sender, f, h0):
    fcopy = f + "copy.mp4"
    fstream = f + "stream.bin"

    sender = Sender(path=f, buffersize=1024)
    sender.write_file(path=fstream)
    computed_h0 = sender.get_first_hash()

    assert h0 == computed_h0

    receiver = StreamReceiver(path=fstream, h=computed_h0, buffersize=1024)
    receiver.write_file(path=fcopy)

    assert filecmp.cmp(fcopy, f)

    subprocess.run(["rm", fcopy])
    subprocess.run(["rm", fstream]) 
開發者ID:mithi,項目名稱:simple-cryptography,代碼行數:19,代碼來源:authentication_test.py

示例11: test_convert_file

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmp [as 別名]
def test_convert_file(self):
        """ Tests conversion of a single DICOM file """
        curr_path = os.path.dirname(os.path.realpath(__file__))
        sample_path = os.path.join(curr_path, 'data', 'samples', 'dicom1')
        expected_path = os.path.join(curr_path, 'data', 'expected', 'dicom1.png')
        actual_path = os.path.join(test_out_path, 'dicom1.png')

        print('Actual File Path: %s' % actual_path)

        # Try the file conversion
        try:
            mritopng.convert_file(sample_path, actual_path)
        except Exception as err:
            self.fail('%s' % err)

        self.assertTrue(filecmp.cmp(actual_path, expected_path),
                        'PNG generated from dicom1 does not match the expected version') 
開發者ID:danishm,項目名稱:mritopng,代碼行數:19,代碼來源:test_mritopng.py

示例12: test_convert_file_with_negative_values

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmp [as 別名]
def test_convert_file_with_negative_values(self):
        """ Tests DICOM files with negative values, which are clipped to 0 """

        cases = ['000012.dcm', '000017.dcm']
        curr_path = os.path.dirname(os.path.realpath(__file__))

        for case in cases:
            
            sample_path = os.path.join(curr_path, 'data', 'samples', case)
            expected_path = os.path.join(curr_path, 'data', 'expected', case + '.png')
            actual_path = os.path.join(test_out_path, case + '.png')

            print('Actual File Path: %s' % actual_path)

            # Try the file conversion
            try:
                mritopng.convert_file(sample_path, actual_path)
            except Exception as err:
                self.fail('%s' % err)
            
            self.assertTrue(filecmp.cmp(actual_path, expected_path),
                            'PNG generated from dicom1 does not match the expected version') 
開發者ID:danishm,項目名稱:mritopng,代碼行數:24,代碼來源:test_mritopng.py

示例13: test_convert_file_auto_contrast

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmp [as 別名]
def test_convert_file_auto_contrast(self):
        cases = ['dicom1', '000012.dcm', '000017.dcm']
        curr_path = os.path.dirname(os.path.realpath(__file__))
        os.makedirs(os.path.join(test_out_path, 'auto-contrast'))

        for case in cases:
            
            sample_path = os.path.join(curr_path, 'data', 'samples', case)
            expected_path = os.path.join(curr_path, 'data', 'expected', 'auto-contrast', case + '.png')
            actual_path = os.path.join(test_out_path, 'auto-contrast', case + '.png')

            print('Actual File Path: %s' % actual_path)

            # Try the file conversion
            try:
                print('>>> Here')
                mritopng.convert_file(sample_path, actual_path, auto_contrast=True)
                print('<<<')
            except Exception as err:
                traceback.print_exc(file=sys.stdout)
                self.fail('%s' % err)

            self.assertTrue(filecmp.cmp(actual_path, expected_path),
                            'PNG generated from dicom1 does not match the expected version') 
開發者ID:danishm,項目名稱:mritopng,代碼行數:26,代碼來源:test_mritopng.py

示例14: verify_defs_integrity

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmp [as 別名]
def verify_defs_integrity(source_dir, build_dir):
        """Verifies integrity of defs/ folder in __py_build__

        File contents under src/defs are compared against __py_build__/defs; a
        file update will only be triggered by modifications to files under
        src/defs.

        :rtype: None
        """

        defs_source_files = [f.absolute() for f in source_dir.glob('**/*.py')]

        for file in defs_source_files:
            slice_index = file.parts.index('src') + 1
            partner = build_dir.joinpath(*file.parts[slice_index:])

            if not partner.is_file() or not filecmp.cmp(str(file), str(partner)):
                shutil.copy2(str(file), str(partner)) 
開發者ID:daboross,項目名稱:screeps-starter-python,代碼行數:20,代碼來源:file_expander.py

示例15: expand_files

# 需要導入模塊: import filecmp [as 別名]
# 或者: from filecmp import cmp [as 別名]
def expand_files(self):
        """Creates a flattened file structure of all user-defined screeps code

        Copies all modified or new .py files found directly under src/, or in
        subdirectories under src/, to __py_build__.

        :return: total number of files copied to __py_build__
        :rtype: int
        """

        target_files = self.find_target_file_paths()

        copied_files = 0
        for target in target_files:
            partner = self.build_dir.joinpath(target.name)

            target_path, partner_path = str(target.absolute()), str(partner.absolute())

            if not (partner.is_file() and filecmp.cmp(target_path, partner_path)):
                shutil.copy2(target_path, partner_path)
                copied_files += 1

        return copied_files 
開發者ID:daboross,項目名稱:screeps-starter-python,代碼行數:25,代碼來源:file_expander.py


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