cc-2419: media monitor import on startup

-fixed support for watched dirs
This commit is contained in:
martin 2011-07-04 17:37:05 -04:00
parent c67e711a05
commit df1dec2078
7 changed files with 38 additions and 22 deletions

View file

@ -521,8 +521,9 @@ class ApiController extends Zend_Controller_Action
print 'You are not allowed to access this resource.';
exit;
}
$dir_id = $request->getParam('dir_id');
$this->view->files = StoredFile::listAllFiles();
$this->view->files = StoredFile::listAllFiles($dir_id);
}
public function listAllWatchedDirsAction() {
@ -542,10 +543,10 @@ class ApiController extends Zend_Controller_Action
$arrWatchedDirs = MusicDir::getWatchedDirs();
$storDir = MusicDir::getStorDir();
$result[] = $storDir->getDirectory();
$result[$storDir->getId()] = $storDir->getDirectory();
foreach ($arrWatchedDirs as $watchedDir){
$result[] = $watchedDir->getDirectory();
$result[$watchedDir->getId()] = $watchedDir->getDirectory();
}
$this->view->dirs = $result;

View file

@ -819,14 +819,15 @@ class StoredFile {
}
public static function listAllFiles(){
public static function listAllFiles($dir_id){
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT m.directory || '/' || f.filepath as fp"
." FROM CC_MUSIC_DIRS m"
." LEFT JOIN CC_FILES f"
." ON m.id = f.directory"
." WHERE m.id = f.directory";
." WHERE m.id = f.directory"
." AND directory = $dir_id";
$rows = $CC_DBC->getAll($sql);
$results = array();

View file

@ -105,7 +105,7 @@ class ApiClientInterface:
def update_media_metadata(self, md):
pass
def list_all_db_files(self):
def list_all_db_files(self, dir_id):
pass
def list_all_watched_dirs(self):
@ -409,12 +409,13 @@ class AirTimeApiClient(ApiClientInterface):
return response
def list_all_db_files(self):
def list_all_db_files(self, dir_id):
logger = logging.getLogger()
try:
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["list_all_db_files"])
url = url.replace("%%api_key%%", self.config["api_key"])
url = url.replace("%%dir_id%%", dir_id)
req = urllib2.Request(url)
response = urllib2.urlopen(req).read()

View file

@ -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)

View file

@ -64,11 +64,14 @@ class AirtimeNotifier(Notifier):
self.md_manager.save_md_to_file(m)
elif m['event_type'] == "new_watch":
mm = self.proc_fun()
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 = self.proc_fun()
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):
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)

View file

@ -62,6 +62,13 @@ class AirtimeProcessEvent(ProcessEvent):
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):
try:
@ -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)

View file

@ -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 #