本文整理汇总了Python中win32con.FILE_SHARE_WRITE属性的典型用法代码示例。如果您正苦于以下问题:Python win32con.FILE_SHARE_WRITE属性的具体用法?Python win32con.FILE_SHARE_WRITE怎么用?Python win32con.FILE_SHARE_WRITE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类win32con
的用法示例。
在下文中一共展示了win32con.FILE_SHARE_WRITE属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _openHandle
# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import FILE_SHARE_WRITE [as 别名]
def _openHandle(path, bWriteAccess, bWriteShare,
logfunc = lambda s: None):
TIMEOUT, NUM_RETRIES = 10, 20
for retry_count in range(6):
try:
access_flag = win32con.GENERIC_READ | \
(bWriteAccess and win32con.GENERIC_WRITE or 0)
share_flag = win32con.FILE_SHARE_READ | \
(bWriteShare and win32con.FILE_SHARE_WRITE or 0)
handle = win32file.CreateFile(
path, access_flag, share_flag, None,
win32con.OPEN_EXISTING, win32con.FILE_ATTRIBUTE_NORMAL, None)
nth = { 0: 'first', 1:'second', 2:'third'}
logfunc("Opening [%s]: success at the %s iteration" %
(path, nth.get(retry_count, '%sth' % (retry_count+1))))
return handle
except pywintypes.error as e:
logfunc('Exception=>'+str(e))
if NUM_RETRIES/3 < retry_count:
bWriteShare = True
time.sleep(TIMEOUT / float(NUM_RETRIES))
else:
raise RuntimeError("Couldn't open handle for %s." % path)
示例2: __init__
# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import FILE_SHARE_WRITE [as 别名]
def __init__(self, filename):
self._hfile = win32file.CreateFile(filename,
win32con.GENERIC_READ | win32con.GENERIC_WRITE,
win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
win32security.SECURITY_ATTRIBUTES(),
win32con.OPEN_EXISTING,
win32con.FILE_FLAG_OVERLAPPED,
0)
self._read_ovrlpd = pywintypes.OVERLAPPED()
self._read_ovrlpd.hEvent = win32event.CreateEvent(None, True,
False, None)
self._write_ovrlpd = pywintypes.OVERLAPPED()
self._write_ovrlpd.hEvent = win32event.CreateEvent(None, True,
False, None)
self._bufs = []
self._n = 0
示例3: __init__
# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import FILE_SHARE_WRITE [as 别名]
def __init__(self, path):
if not isinstance(path, basestring):
raise TypeError("Path argument must be a basestring; instead"
" received %r" % (path,))
self.path = path
self.handle = win32file.CreateFile(
self.path,
0x0001, # FILE_LIST_DIRECTORY
win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
None,
win32con.OPEN_EXISTING,
win32con.FILE_FLAG_BACKUP_SEMANTICS | win32con.FILE_FLAG_OVERLAPPED,
None,
)
self.overlapped = win32file.OVERLAPPED()
self.overlapped.hEvent = win32event.CreateEvent(None, True, 0, None)
示例4: run
# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import FILE_SHARE_WRITE [as 别名]
def run(self):
#open file/device
try:
handle = win32file.CreateFile(
self.devicePath,
win32con.GENERIC_READ | win32con.GENERIC_WRITE,
win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
None, # no security
win32con.OPEN_EXISTING,
win32con.FILE_ATTRIBUTE_NORMAL | win32con.FILE_FLAG_OVERLAPPED,
0
)
except pywintypes.error as (errno, function, strerror):
self.lockObject.release()
eg.PrintError(self.text.errorOpen + self.deviceName + " (" + strerror + ")")
return
示例5: findVolumeGuids
# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import FILE_SHARE_WRITE [as 别名]
def findVolumeGuids():
DiskExtent = collections.namedtuple(
'DiskExtent', ['DiskNumber', 'StartingOffset', 'ExtentLength'])
Volume = collections.namedtuple(
'Volume', ['Guid', 'MediaType', 'DosDevice', 'Extents'])
found = []
h, guid = FindFirstVolume()
while h and guid:
#print (guid)
#print (guid, win32file.GetDriveType(guid),
# win32file.QueryDosDevice(guid[4:-1]))
hVolume = win32file.CreateFile(
guid[:-1], win32con.GENERIC_READ,
win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
None, win32con.OPEN_EXISTING, win32con.FILE_ATTRIBUTE_NORMAL, None)
extents = []
driveType = win32file.GetDriveType(guid)
if driveType in [win32con.DRIVE_REMOVABLE, win32con.DRIVE_FIXED]:
x = win32file.DeviceIoControl(
hVolume, winioctlcon.IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
None, 512, None)
instream = io.BytesIO(x)
numRecords = struct.unpack('<q', instream.read(8))[0]
fmt = '<qqq'
sz = struct.calcsize(fmt)
while 1:
b = instream.read(sz)
if len(b) < sz:
break
rec = struct.unpack(fmt, b)
extents.append( DiskExtent(*rec) )
vinfo = Volume(guid, driveType, win32file.QueryDosDevice(guid[4:-1]),
extents)
found.append(vinfo)
guid = FindNextVolume(h)
return found
示例6: windows_event_handler
# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import FILE_SHARE_WRITE [as 别名]
def windows_event_handler(logger, dir_watch, cond, tasks):
ACTIONS = {
1: "Created ", # test for printing results
2: "Deleted ",
3: "Updated ",
4: "Rename from",
5: "Rename to",
}
FILE_LIST_DIRECTORY = 0x0001
hDir = win32file.CreateFile(dir_watch['path'], # to directory
FILE_LIST_DIRECTORY, # access (read/write) mode
# share mode: FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE
win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE | win32con.FILE_SHARE_DELETE,
None, # security descriptor
win32con.OPEN_EXISTING, # how to create
# file attributes: FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED
win32con.FILE_FLAG_BACKUP_SEMANTICS,
None,
)
# detecting right events is not easy in windows :-(
# want to detect: new file, move, drop, rename, write/append to file
# only FILE_NOTIFY_CHANGE_LAST_WRITE: copy yes, no move
# for rec=True: event that subdirectory itself is updated (for file deletes in dir)
while True:
results = win32file.ReadDirectoryChangesW(hDir,
8192, # buffer size was 1024, do not want to miss anything
False, # recursive
win32con.FILE_NOTIFY_CHANGE_FILE_NAME |
# ~ win32con.FILE_NOTIFY_CHANGE_DIR_NAME |
# ~ win32con.FILE_NOTIFY_CHANGE_ATTRIBUTES |
# ~ win32con.FILE_NOTIFY_CHANGE_SIZE |
# ~ win32con.FILE_NOTIFY_CHANGE_SECURITY |
# ~ win32con.FILE_NOTIFY_CHANGE_CREATION |
# ~ win32con.FILE_NOTIFsY_CHANGE_LAST_ACCESS |
win32con.FILE_NOTIFY_CHANGE_LAST_WRITE,
None,
None
)
if results:
# for each incoming event: place route to run in a set. Main thread takes action.
for action, filename in results:
pyas2init.logger.debug(u'Event: %(action)s %(filename)s',
{'action': ACTIONS.get(action, "Unknown"), 'filename': filename})
for action, filename in results:
if action in [1, 3, 5]: # and fnmatch.fnmatch(filename, dir_watch['filemask']):
# ~ if dir_watch['rec'] and os.sep in filename:
# ~ continue
full_filename = os.path.join(dir_watch['path'], filename)
if os.path.isfile(full_filename):
cond.acquire()
tasks.add((dir_watch['organization'], dir_watch['partner'], full_filename))
cond.notify()
cond.release()
# break #the route is triggered, do not need to trigger more often
# end of windows-specific ##############################################
示例7: watchos
# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import FILE_SHARE_WRITE [as 别名]
def watchos():
#get path or maintain current path of app
FILE_LIST_DIRECTORY = 0x0001
try: path_to_watch = myos.get() or "."
except: path_to_watch = "."
path_to_watch = os.path.abspath(path_to_watch)
textbox.insert(END, "Watching %s at %s" % (path_to_watch, time.asctime()) + "\n\n")
# FindFirstChangeNotification sets up a handle for watching
# file changes.
while 1:
hDir = win32file.CreateFile (
path_to_watch,
FILE_LIST_DIRECTORY,
win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
None,
win32con.OPEN_EXISTING,
win32con.FILE_FLAG_BACKUP_SEMANTICS,
None
)
change_handle = win32file.ReadDirectoryChangesW (
hDir,
1024,
True,#Heap Size include_subdirectories,
win32con.FILE_NOTIFY_CHANGE_FILE_NAME |
win32con.FILE_NOTIFY_CHANGE_DIR_NAME |
win32con.FILE_NOTIFY_CHANGE_ATTRIBUTES |
win32con.FILE_NOTIFY_CHANGE_SIZE |
win32con.FILE_NOTIFY_CHANGE_LAST_WRITE |
win32con.FILE_NOTIFY_CHANGE_SECURITY,
None,
None
)
# Loop forever, listing any file changes. The WaitFor... will
# time out every half a second allowing for keyboard interrupts
# to terminate the loop.
ACTIONS = {
1 : "Created",
2 : "Deleted",
3 : "Updated",
4 : "Renamed from something",
5 : "Renamed to something"
}
results = change_handle
for action, files in results:
full_filename = os.path.join(path_to_watch, files)
theact = ACTIONS.get(action, "Unknown")
textbox.insert(END, str(full_filename) + "\t" + str(theact) +"\n")