Python os.sync() Examples

The following are 17 code examples of os.sync(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module os , or try the search function .
Example #1
Source File: basePhashTestSetup.py    From IntraArchiveDeduplicator with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, tableName = None, load_database = True, *args, **kwargs):

		if tableName:
			self.tableName = self.tableName+"_"+tableName
		super().__init__(*args, **kwargs)

		self.hasher = TestHasher()

		if load_database:
			self.copy_zips()


			self.log.info("sync()ing")
			# You need an explicit sync call or the load_zips call can sometimes miss the new files.
			# Yes, this was actually an issue.
			os.sync()

			self.load_zips(TEST_ZIP_PATH)

			# Since the tree deliberately persists (it's a singleton), we have to /explicitly/ clobber it.
			self.unlocked_doLoad() 
Example #2
Source File: linux_dns_force_public_resolv_conf.py    From expressvpn_leak_testing with MIT License 6 votes vote down vote up
def disrupt(self):
        L.describe('Set the DNS servers in resolv.conf to public DNS servers')

        temp_resolv_conf = open(self._temp_resolv_conf_path, "w")
        # TODO: make configurable?
        dns_servers = ['37.235.1.174', '37.235.1.177']
        for nameserver in dns_servers:
            temp_resolv_conf.write("nameserver {}\n".format(nameserver))
        temp_resolv_conf.close()

        if os.path.islink(self._resolv_conf_path) and os.path.exists(self._resolv_conf_path):
            self._resolv_conf_target_path = os.readlink(self._resolv_conf_path)
            os.remove(self._resolv_conf_path)
            os.symlink(self._temp_resolv_conf_path, self._resolv_conf_path)
            os.sync()
        else:
            raise XVEx("Can't replace resolv.conf; not a symlink") 
Example #3
Source File: basePhashTestSetup.py    From IntraArchiveDeduplicator with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def delete_item(item_path):
	failed = 0
	while os.path.exists(item_path):
		try:
			shutil.rmtree(item_path)
		except Exception as e:
			print("TryDelete failed!")
			print("Item: ", item_path)
			print("Stat: ", os.stat(item_path))
			failed += 1
			if failed > 20:
				print("Deletion failed!")
				return

			# You need an explicit sync call or the load_zips call can sometimes miss the new files.
			# Yes, this was actually an issue.
			os.sync()
			time.sleep(0.1 * failed)

			# Force the destructors to run in case we have the handle open still, somehow.
			gc.collect()

			os.stat(item_path)
			if not os.path.exists(item_path):
				return 
Example #4
Source File: ftp.py    From cgat-core with MIT License 6 votes vote down vote up
def download(self, make_dest_dir=True):
        with self.ftpc() as ftpc:
            if self.exists():
                # if the dest path does not exist
                if make_dest_dirs:
                    os.makedirs(os.path.dirname(
                        self.local_path, exists_ok=True))
                try:
                    ftpc.syncronize_times()
                except:
                    pass

                ftpc.download(source=self.remote_path, target=self.local_path)
                os.sync()
            else:
                raise FTPFileException(
                    "The file does not exist remotely: %s" % self.local_file()) 
Example #5
Source File: linux.py    From zstack-utility with Apache License 2.0 5 votes vote down vote up
def sync():
        libc.sync() 
Example #6
Source File: usb.py    From multibootusb with GNU General Public License v2.0 5 votes vote down vote up
def __enter__(self):
        if not self.is_relevant:
            return
        self.assert_no_access()
        try:
            gen.log("Unmounting %s" % self.usb_disk)
            os.sync() # This is needed because UDISK.unmount() can timeout.
            UDISKS.unmount(self.usb_disk)
        except dbus.exceptions.DBusException as e:
            gen.log("Unmount of %s has failed." % self.usb_disk)
            # This may get the partition mounted. Don't call!
            # self.exit_callback(details(self.usb_disk))
            raise UnmountError(e)
        gen.log("Unmounted %s" % self.usb_disk)
        return self 
Example #7
Source File: test_gpu_prediction_pickledmodel.py    From h2o4gpu with Apache License 2.0 5 votes vote down vote up
def save_obj(obj, name):
    # print("Saving %s" % name)
    with open(name, 'wb') as f:
        pickle.dump(obj=obj, file=f)
        # os.sync() 
Example #8
Source File: Shutdown.py    From bcloud with GNU General Public License v3.0 5 votes vote down vote up
def shutdown(self):
        '''Call the dbus proxy to start the shutdown.'''
        if self._proxy:
            os.sync()
            self._proxy(*self._args) 
Example #9
Source File: google_cloud.py    From cgat-core with MIT License 5 votes vote down vote up
def download(self, bucket_name, key, file_dir):
        self._GCobject.remote_download(bucket_name, key, file_dir)
        os.sync()
        return file_dir 
Example #10
Source File: azure.py    From cgat-core with MIT License 5 votes vote down vote up
def download(self, container_name, blob_name, file_dir):
        self._Azureobject.remote_download(container_name, blob_name, file_dir)
        os.sync()  # ensure flush to disk
        return file_dir 
Example #11
Source File: sftp.py    From cgat-core with MIT License 5 votes vote down vote up
def download(self, make_dest_dir=True):
        with self.sftpc() as sftpc:
            if self.exists():
                # if the dest path does not exist
                if make_dest_dirs:
                    os.makedirs(os.path.dirname(
                        self.local_path, exists_ok=True))

                sftpc.get(remotepath=self.remote_path,
                          localpath=self.local_path, preserve_mtime=True)
                os.sync()
            else:
                raise SFTPFileException(
                    "The file cannot be parsed as an STFP path in "
                    "form 'host:port/path/to/file': %s" % self.local_file()) 
Example #12
Source File: aws.py    From cgat-core with MIT License 5 votes vote down vote up
def download(self, bucket_name, key, file_dir):
        self._S3object.remote_download(bucket_name, key, file_dir)
        os.sync()  # ensure flush to disk
        return file_dir 
Example #13
Source File: linux_dns_force_public_resolv_conf.py    From expressvpn_leak_testing with MIT License 5 votes vote down vote up
def _restore_dns_servers(self):
        os.remove(self._resolv_conf_path)
        os.symlink(self._resolv_conf_target_path, self._resolv_conf_path)
        os.sync() 
Example #14
Source File: platform.py    From specter-diy with MIT License 5 votes vote down vote up
def sync():
    try:
        os.sync()
    except:
        pass 
Example #15
Source File: platform.py    From specter-diy with MIT License 5 votes vote down vote up
def maybe_mkdir(path):
    try:
        os.mkdir(path)
    except:
        pass
    if not simulator:
        os.sync()

# path to store #reckless entropy 
Example #16
Source File: usb.py    From multibootusb with GNU General Public License v2.0 5 votes vote down vote up
def __exit__(self, type_, value, traceback_):
        if not self.is_relevant:
            return
        os.sync()     # This should not be strictly necessary
        time.sleep(1)  # Yikes, mount always fails without this sleep().
        try:
            mount_point = UDISKS.mount(self.usb_disk)
            config.add_remounted(self.usb_disk)
            self.exit_callback(details(self.usb_disk))
        except dbus.exceptions.DBusException as e:
            raise MountError(e)
        gen.log("Mounted %s" % (self.usb_disk)) 
Example #17
Source File: main.py    From rshell with MIT License 4 votes vote down vote up
def recv_file_from_host(src_file, dst_filename, filesize, dst_mode='wb'):
    """Function which runs on the pyboard. Matches up with send_file_to_remote."""
    import sys
    import ubinascii
    import os
    if HAS_BUFFER:
        try:
            import pyb
            usb = pyb.USB_VCP()
        except:
            try:
                import machine
                usb = machine.USB_VCP()
            except:
                usb = None
        if usb and usb.isconnected():
            # We don't want 0x03 bytes in the data to be interpreted as a Control-C
            # This gets reset each time the REPL runs a line, so we don't need to
            # worry about resetting it ourselves
            usb.setinterrupt(-1)
    try:
        with open(dst_filename, dst_mode) as dst_file:
            bytes_remaining = filesize
            if not HAS_BUFFER:
                bytes_remaining *= 2  # hexlify makes each byte into 2
            buf_size = BUFFER_SIZE
            write_buf = bytearray(buf_size)
            read_buf = bytearray(buf_size)
            while bytes_remaining > 0:
                # Send back an ack as a form of flow control
                sys.stdout.write('\x06')
                read_size = min(bytes_remaining, buf_size)
                buf_remaining = read_size
                buf_index = 0
                while buf_remaining > 0:
                    if HAS_BUFFER:
                        bytes_read = sys.stdin.buffer.readinto(read_buf, read_size)
                    else:
                        bytes_read = sys.stdin.readinto(read_buf, read_size)
                    if bytes_read > 0:
                        write_buf[buf_index:bytes_read] = read_buf[0:bytes_read]
                        buf_index += bytes_read
                        buf_remaining -= bytes_read
                if HAS_BUFFER:
                    dst_file.write(write_buf[0:read_size])
                else:
                    dst_file.write(ubinascii.unhexlify(write_buf[0:read_size]))
                if hasattr(os, 'sync'):
                    os.sync()
                bytes_remaining -= read_size
        return True
    except:
        return False