Added lsof to check if file is locked
This commit is contained in:
parent
5b051aae32
commit
3dd5b2869d
|
@ -48,17 +48,11 @@ class BaseListener(object):
|
|||
class OrganizeListener(BaseListener, pyinotify.ProcessEvent, Loggable):
|
||||
def process_IN_CLOSE_WRITE(self, event):
|
||||
#self.logger.info("===> handling: '%s'" % str(event))
|
||||
#self.process_to_organize(event)
|
||||
pass
|
||||
# got cookie
|
||||
self.process_to_organize(event)
|
||||
|
||||
def process_IN_MOVED_TO(self, event):
|
||||
#self.logger.info("===> handling: '%s'" % str(event))
|
||||
#self.process_to_organize(event)
|
||||
pass
|
||||
|
||||
def process_default(self, event):
|
||||
pass
|
||||
#self.logger.info("===> Not handling: '%s'" % str(event))
|
||||
self.process_to_organize(event)
|
||||
|
||||
def flush_events(self, path):
|
||||
"""
|
||||
|
@ -69,8 +63,9 @@ class OrganizeListener(BaseListener, pyinotify.ProcessEvent, Loggable):
|
|||
for f in mmp.walk_supported(path, clean_empties=True):
|
||||
self.logger.info("Bootstrapping: File in 'organize' directory: \
|
||||
'%s'" % f)
|
||||
dispatcher.send(signal=self.signal, sender=self,
|
||||
event=OrganizeFile(f))
|
||||
if not mmp.file_locked(f):
|
||||
dispatcher.send(signal=self.signal, sender=self,
|
||||
event=OrganizeFile(f))
|
||||
flushed += 1
|
||||
#self.logger.info("Flushed organized directory with %d files" % flushed)
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class ManagerTimeout(threading.Thread,Loggable):
|
|||
self.interval = interval
|
||||
def run(self):
|
||||
while True:
|
||||
time.sleep(self.interval) # every 3 seconds
|
||||
time.sleep(self.interval)
|
||||
self.manager.flush_organize()
|
||||
|
||||
class Manager(Loggable):
|
||||
|
@ -178,7 +178,7 @@ class Manager(Loggable):
|
|||
# the OrganizeListener instance will walk path and dispatch an organize
|
||||
# event for every file in that directory
|
||||
self.organize['organize_listener'].flush_events(new_path)
|
||||
self.__add_watch(new_path, self.organize['organize_listener'])
|
||||
#self.__add_watch(new_path, self.organize['organize_listener'])
|
||||
|
||||
def flush_organize(self):
|
||||
path = self.organize['organize_path']
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
import media.monitor.pure as mmp
|
||||
import media.monitor.owners as owners
|
||||
from media.monitor.handler import ReportHandler
|
||||
|
@ -72,13 +71,9 @@ class Organizer(ReportHandler,Loggable):
|
|||
directory=d)
|
||||
return cb
|
||||
|
||||
time.sleep(0.02)
|
||||
|
||||
mmp.magic_move(event.path, new_path,
|
||||
after_dir_make=new_dir_watch(dirname(new_path)))
|
||||
|
||||
time.sleep(0.02)
|
||||
|
||||
# The reason we need to go around saving the owner in this ass
|
||||
# backwards way is bewcause we are unable to encode the owner id
|
||||
# into the file itself so that the StoreWatchListener listener can
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import copy
|
||||
from subprocess import Popen, PIPE
|
||||
import subprocess
|
||||
import os
|
||||
import math
|
||||
|
@ -165,6 +166,12 @@ def walk_supported(directory, clean_empties=False):
|
|||
for fp in full_paths: yield fp
|
||||
if clean_empties: clean_empty_dirs(directory)
|
||||
|
||||
|
||||
def file_locked(path):
|
||||
cmd = "lsof %s" % path
|
||||
f = Popen(cmd, shell=True, stdout=PIPE).stdout
|
||||
return bool(f.readlines())
|
||||
|
||||
def magic_move(old, new, after_dir_make=lambda : None):
|
||||
"""
|
||||
Moves path old to new and constructs the necessary to directories for new
|
||||
|
|
Loading…
Reference in New Issue