cc-2419: media monitor import on start
-files importing working...
This commit is contained in:
parent
778b645a69
commit
851d5c12b2
3 changed files with 72 additions and 39 deletions
|
@ -5,9 +5,10 @@ from subprocess import Popen, PIPE
|
|||
|
||||
class AirtimeMediaMonitorBootstrap():
|
||||
|
||||
def __init__(self, logger, multi_queue):
|
||||
def __init__(self, logger, multi_queue, pe):
|
||||
self.logger = logger
|
||||
self.multi_queue = multi_queue
|
||||
self.pe = pe
|
||||
|
||||
"""
|
||||
on bootup we want to scan all directories and look for files that
|
||||
|
@ -22,16 +23,24 @@ class AirtimeMediaMonitorBootstrap():
|
|||
|
||||
def check_for_diff(self, dir):
|
||||
airtime_tmp = '/var/tmp/airtime'
|
||||
|
||||
#set to hold new and/or modified files. We use a set to make it ok if files are added
|
||||
#twice. This is become some of the tests for new files return result sets that are not
|
||||
#mutually exclusive from each other.
|
||||
modified_files = set()
|
||||
|
||||
#find files that have been modified since the last time
|
||||
#media-monitor process was running.
|
||||
command = "find %s -type f -iname '*.ogg' -o -iname '*.mp3' -readable -mmin -30" % dir
|
||||
stdout = self.execCommandAndReturnStdOut(command)
|
||||
self.logger.info("Files modified since last checkin: \n%s\n", stdout)
|
||||
|
||||
#TODO: notify about modified and newly created files (not including copied files)
|
||||
|
||||
new_files = stdout.split('\n')
|
||||
|
||||
for file_path in new_files:
|
||||
modified_files.add(file_path)
|
||||
|
||||
if os.path.exists(airtime_tmp + '/.airtime_media_index'):
|
||||
if os.path.exists(airtime_tmp + '/.airtime_media_index') and False:
|
||||
#a previous index exists, we can do a diff between this
|
||||
#file and the current state to see whether anything has
|
||||
#changed.
|
||||
|
@ -54,11 +63,26 @@ class AirtimeMediaMonitorBootstrap():
|
|||
self.logger.info("Previous index file does not exist. Creating a new one")
|
||||
|
||||
#create a new index file.
|
||||
command = "find %s -type f -iname '*.ogg' -o -iname '*.mp3' -readable > %s/.airtime_media_index" % (dir, airtime_tmp)
|
||||
self.execCommand(command)
|
||||
command = "find %s -type f -iname '*.ogg' -o -iname '*.mp3' -readable" % dir
|
||||
stdout = self.execCommandAndReturnStdOut(command)
|
||||
self.logger.info("New files found: \n%s\n", stdout)
|
||||
self.write_file(airtime_tmp + '/.airtime_media_index', stdout)
|
||||
|
||||
new_files = stdout.split('\n')
|
||||
|
||||
for file_path in new_files:
|
||||
modified_files.add(file_path)
|
||||
|
||||
self.logger.debug("set size: %d", len(modified_files))
|
||||
|
||||
#TODO: notify about all files in this directory.
|
||||
self.multi_queue.put(event)
|
||||
for file_path in modified_files:
|
||||
if os.path.exists(file_path):
|
||||
self.pe.handle_created_file(False, os.path.basename(file_path), file_path)
|
||||
|
||||
def write_file(self, file, string):
|
||||
f = open(file, 'w')
|
||||
f.write(string)
|
||||
f.close()
|
||||
|
||||
def execCommand(self, command):
|
||||
p = Popen(command, shell=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue