cc-2419: media monitor import on startup
-fixed support for watched dirs
This commit is contained in:
parent
c67e711a05
commit
df1dec2078
7 changed files with 38 additions and 22 deletions
|
@ -26,17 +26,17 @@ class AirtimeMediaMonitorBootstrap():
|
|||
|
||||
self.logger.info("watched directories found: %s", directories)
|
||||
|
||||
for dir in directories:
|
||||
self.check_for_diff(dir)
|
||||
for id, dir in directories:
|
||||
self.check_for_diff(id, dir)
|
||||
|
||||
def list_db_files(self):
|
||||
return self.api_client.list_all_db_files()
|
||||
def list_db_files(self, dir_id):
|
||||
return self.api_client.list_all_db_files(dir_id)
|
||||
|
||||
def get_list_of_watched_dirs(self):
|
||||
json = self.api_client.list_all_watched_dirs()
|
||||
return json["dirs"]
|
||||
|
||||
def check_for_diff(self, dir):
|
||||
def check_for_diff(self, dir_id, dir):
|
||||
#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.
|
||||
|
@ -45,7 +45,7 @@ class AirtimeMediaMonitorBootstrap():
|
|||
|
||||
|
||||
db_known_files_set = set()
|
||||
files = self.list_db_files()
|
||||
files = self.list_db_files(dir_id)
|
||||
for file in files['files']:
|
||||
db_known_files_set.add(file)
|
||||
|
||||
|
|
|
@ -64,11 +64,14 @@ class AirtimeNotifier(Notifier):
|
|||
self.md_manager.save_md_to_file(m)
|
||||
|
||||
elif m['event_type'] == "new_watch":
|
||||
self.logger.info("AIRTIME NOTIFIER add watched folder event " + m['directory'])
|
||||
self.walk_newly_watched_directory(m['directory'])
|
||||
|
||||
mm = self.proc_fun()
|
||||
mm.watch_directory(m['directory'])
|
||||
if mm.has_correct_permissions(m['directory']):
|
||||
self.logger.info("AIRTIME NOTIFIER add watched folder event " + m['directory'])
|
||||
self.walk_newly_watched_directory(m['directory'])
|
||||
|
||||
mm.watch_directory(m['directory'])
|
||||
else:
|
||||
self.logger.warn("filepath '%s' has does not have sufficient read permissions. Ignoring.", full_filepath)
|
||||
|
||||
elif m['event_type'] == "remove_watch":
|
||||
watched_directory = m['directory'].encode('utf-8')
|
||||
|
@ -170,7 +173,10 @@ class AirtimeNotifier(Notifier):
|
|||
full_filepath = path+"/"+filename
|
||||
|
||||
if mm.is_audio_file(full_filepath):
|
||||
self.logger.info("importing %s", full_filepath)
|
||||
event = {'filepath': full_filepath, 'mode': self.config.MODE_CREATE, 'is_recorded_show': False}
|
||||
mm.multi_queue.put(event)
|
||||
if mm.has_correct_permissions(full_filepath):
|
||||
self.logger.info("importing %s", full_filepath)
|
||||
event = {'filepath': full_filepath, 'mode': self.config.MODE_CREATE, 'is_recorded_show': False}
|
||||
mm.multi_queue.put(event)
|
||||
else:
|
||||
self.logger.warn("file '%s' has does not have sufficient read permissions. Ignoring.", full_filepath)
|
||||
|
||||
|
|
|
@ -61,6 +61,13 @@ class AirtimeProcessEvent(ProcessEvent):
|
|||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
#file needs to be readable by all users, and directories
|
||||
#up to this file needs to be readable AND executable by all
|
||||
#users.
|
||||
def has_correct_permissions(self, filepath):
|
||||
st = os.stat(filepath)
|
||||
return bool(st.st_mode & stat.S_IROTH)
|
||||
|
||||
def set_needed_file_permissions(self, item, is_dir):
|
||||
|
||||
|
@ -100,7 +107,7 @@ class AirtimeProcessEvent(ProcessEvent):
|
|||
omask = os.umask(0)
|
||||
os.rename(source, dest)
|
||||
except Exception, e:
|
||||
self.logger.error("failed to move file.")
|
||||
self.logger.error("failed to move file. %s", e)
|
||||
finally:
|
||||
os.umask(omask)
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ update_media_url = 'reload-metadata/format/json/api_key/%%api_key%%/mode/%%mode%
|
|||
list_all_db_files = 'list-all-files/format/json/api_key/%%api_key%%'
|
||||
|
||||
# URL to tell Airtime we want a listing of all dirs its watching (including the stor dir)
|
||||
list_all_watched_dirs = 'list-all-watched-dirs/format/json/api_key/%%api_key%%'
|
||||
list_all_watched_dirs = 'list-all-watched-dirs/format/json/api_key/%%api_key%%/dir_id/%%dir_id%%'
|
||||
|
||||
############################################
|
||||
# RabbitMQ settings #
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue