CC-1799 Put Airtime Storage into a Human Readable File Naming Convention
starting to better work with renamed files.
This commit is contained in:
parent
84dd5dac62
commit
51b1f00ac9
1 changed files with 33 additions and 20 deletions
|
@ -130,13 +130,26 @@ class MediaMonitor(ProcessEvent):
|
||||||
self.supported_file_formats = ['mp3', 'ogg']
|
self.supported_file_formats = ['mp3', 'ogg']
|
||||||
self.logger = logging.getLogger('root')
|
self.logger = logging.getLogger('root')
|
||||||
self.temp_files = {}
|
self.temp_files = {}
|
||||||
|
self.moved_files = {}
|
||||||
self.file_events = deque()
|
self.file_events = deque()
|
||||||
|
|
||||||
|
self.mask = pyinotify.IN_CREATE | \
|
||||||
|
pyinotify.IN_MODIFY | \
|
||||||
|
pyinotify.IN_MOVED_FROM | \
|
||||||
|
pyinotify.IN_MOVED_TO | \
|
||||||
|
pyinotify.IN_DELETE | \
|
||||||
|
pyinotify.IN_DELETE_SELF
|
||||||
|
|
||||||
|
self.wm = WatchManager()
|
||||||
|
|
||||||
schedule_exchange = Exchange("airtime-media-monitor", "direct", durable=True, auto_delete=True)
|
schedule_exchange = Exchange("airtime-media-monitor", "direct", durable=True, auto_delete=True)
|
||||||
schedule_queue = Queue("media-monitor", exchange=schedule_exchange, key="filesystem")
|
schedule_queue = Queue("media-monitor", exchange=schedule_exchange, key="filesystem")
|
||||||
connection = BrokerConnection(config["rabbitmq_host"], config["rabbitmq_user"], config["rabbitmq_password"], "/")
|
connection = BrokerConnection(config["rabbitmq_host"], config["rabbitmq_user"], config["rabbitmq_password"], "/")
|
||||||
channel = connection.channel()
|
channel = connection.channel()
|
||||||
|
|
||||||
|
def watch_directory(self, directory):
|
||||||
|
return self.wm.add_watch(directory, self.mask, rec=True, auto_add=True)
|
||||||
|
|
||||||
def get_md5(self, filepath):
|
def get_md5(self, filepath):
|
||||||
f = open(filepath, 'rb')
|
f = open(filepath, 'rb')
|
||||||
m = hashlib.md5()
|
m = hashlib.md5()
|
||||||
|
@ -163,24 +176,22 @@ class MediaMonitor(ProcessEvent):
|
||||||
return length
|
return length
|
||||||
|
|
||||||
def ensure_dir(self, filepath):
|
def ensure_dir(self, filepath):
|
||||||
|
|
||||||
directory = os.path.dirname(filepath)
|
directory = os.path.dirname(filepath)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
omask = os.umask(0)
|
omask = os.umask(0)
|
||||||
if ((not os.path.exists(directory)) or ((os.path.exists(directory) and not os.path.isdir(directory)))):
|
if ((not os.path.exists(directory)) or ((os.path.exists(directory) and not os.path.isdir(directory)))):
|
||||||
os.makedirs(directory, 02775)
|
os.makedirs(directory, 02775)
|
||||||
|
self.watch_directory(directory)
|
||||||
finally:
|
finally:
|
||||||
os.umask(omask)
|
os.umask(omask)
|
||||||
|
|
||||||
|
|
||||||
def create_unique_filename(self, filepath):
|
def create_unique_filename(self, filepath):
|
||||||
|
|
||||||
file_dir = os.path.dirname(filepath)
|
|
||||||
filename = os.path.basename(filepath).split(".")[0]
|
|
||||||
file_ext = os.path.splitext(filepath)[1]
|
|
||||||
|
|
||||||
if(os.path.exists(filepath)):
|
if(os.path.exists(filepath)):
|
||||||
|
file_dir = os.path.dirname(filepath)
|
||||||
|
filename = os.path.basename(filepath).split(".")[0]
|
||||||
|
file_ext = os.path.splitext(filepath)[1]
|
||||||
i = 1;
|
i = 1;
|
||||||
while(True):
|
while(True):
|
||||||
new_filepath = "%s/%s(%s).%s" % (file_dir, filename, i, file_ext)
|
new_filepath = "%s/%s(%s).%s" % (file_dir, filename, i, file_ext)
|
||||||
|
@ -329,7 +340,7 @@ class MediaMonitor(ProcessEvent):
|
||||||
self.update_airtime(file_info['filepath'], file_info['mode'])
|
self.update_airtime(file_info['filepath'], file_info['mode'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
notifier.connection.drain_events(timeout=int(config["check_airtime_events"]))
|
notifier.connection.drain_events(timeout=1)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger = logging.getLogger('root')
|
logger = logging.getLogger('root')
|
||||||
logger.info("%s", e)
|
logger.info("%s", e)
|
||||||
|
@ -337,15 +348,6 @@ class MediaMonitor(ProcessEvent):
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# watched events
|
|
||||||
mask = pyinotify.IN_CREATE | \
|
|
||||||
pyinotify.IN_MODIFY | \
|
|
||||||
pyinotify.IN_MOVED_FROM | \
|
|
||||||
pyinotify.IN_MOVED_TO | \
|
|
||||||
pyinotify.IN_DELETE | \
|
|
||||||
pyinotify.IN_DELETE_SELF
|
|
||||||
#mask = pyinotify.ALL_EVENTS
|
|
||||||
|
|
||||||
logger = logging.getLogger('root')
|
logger = logging.getLogger('root')
|
||||||
mm = MediaMonitor()
|
mm = MediaMonitor()
|
||||||
|
|
||||||
|
@ -355,15 +357,26 @@ if __name__ == '__main__':
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
storage_directory = response["stor"]
|
storage_directory = response["stor"]
|
||||||
|
plupload_directory = response["plupload"]
|
||||||
|
|
||||||
wm = WatchManager()
|
wdd = mm.watch_directory(storage_directory)
|
||||||
wdd = wm.add_watch(storage_directory, mask, rec=True, auto_add=True)
|
|
||||||
logger.info("Added watch to %s", storage_directory)
|
logger.info("Added watch to %s", storage_directory)
|
||||||
logger.info("wdd result %s", wdd[storage_directory])
|
logger.info("wdd result %s", wdd[storage_directory])
|
||||||
|
wdd = mm.watch_directory(plupload_directory)
|
||||||
|
logger.info("Added watch to %s", plupload_directory)
|
||||||
|
logger.info("wdd result %s", wdd[plupload_directory])
|
||||||
|
|
||||||
notifier = AirtimeNotifier(wm, mm, read_freq=int(config["check_filesystem_events"]), timeout=1)
|
notifier = AirtimeNotifier(mm.wm, mm, read_freq=int(config["check_filesystem_events"]), timeout=1)
|
||||||
notifier.coalesce_events()
|
notifier.coalesce_events()
|
||||||
notifier.loop(callback=mm.notifier_loop_callback)
|
|
||||||
|
#notifier.loop(callback=mm.notifier_loop_callback)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if(notifier.check_events(1)):
|
||||||
|
notifier.read_events()
|
||||||
|
notifier.process_events()
|
||||||
|
mm.notifier_loop_callback(notifier)
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
notifier.stop()
|
notifier.stop()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue