Merge branch 'devel' of dev.sourcefabric.org:airtime into devel
This commit is contained in:
commit
0e3bae4b5c
|
@ -151,6 +151,7 @@ class LibraryController extends Zend_Controller_Action
|
|||
return;
|
||||
}
|
||||
else {
|
||||
$res = settype($res, "integer");
|
||||
$data = array("filepath" => $file->getFilePath(), "delete" => $res);
|
||||
RabbitMq::SendMessageToMediaMonitor("file_delete", $data);
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ class ScheduleGroup {
|
|||
|
||||
// Check if there are any conflicts with existing entries
|
||||
$metadata = $track->getMetadata();
|
||||
$length = trim($metadata["length"]);
|
||||
$length = $metadata['MDATA_KEY_DURATION'];
|
||||
if (empty($length)) {
|
||||
return new PEAR_Error("Length is empty.");
|
||||
}
|
||||
|
@ -540,7 +540,7 @@ class Schedule {
|
|||
$retVal = $CC_DBC->query($sql);
|
||||
return $retVal;
|
||||
}
|
||||
|
||||
|
||||
public static function getSchduledPlaylistCount(){
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$sql = "SELECT count(*) as cnt FROM ".$CC_CONFIG['scheduleTable'];
|
||||
|
@ -750,7 +750,7 @@ class Schedule {
|
|||
global $CC_CONFIG, $CC_DBC;
|
||||
$CC_DBC->query("TRUNCATE TABLE ".$CC_CONFIG["scheduleTable"]);
|
||||
}
|
||||
|
||||
|
||||
public static function createNewFormSections($p_view){
|
||||
$formWhat = new Application_Form_AddShowWhat();
|
||||
$formWho = new Application_Form_AddShowWho();
|
||||
|
@ -769,7 +769,7 @@ class Schedule {
|
|||
$formRecord->removeDecorator('DtDdWrapper');
|
||||
$formAbsoluteRebroadcast->removeDecorator('DtDdWrapper');
|
||||
$formRebroadcast->removeDecorator('DtDdWrapper');
|
||||
|
||||
|
||||
$p_view->what = $formWhat;
|
||||
$p_view->when = $formWhen;
|
||||
$p_view->repeats = $formRepeats;
|
||||
|
@ -779,7 +779,7 @@ class Schedule {
|
|||
$p_view->absoluteRebroadcast = $formAbsoluteRebroadcast;
|
||||
$p_view->rebroadcast = $formRebroadcast;
|
||||
$p_view->addNewShow = true;
|
||||
|
||||
|
||||
$formWhat->populate(array('add_show_id' => '-1'));
|
||||
$formWhen->populate(array('add_show_start_date' => date("Y-m-d"),
|
||||
'add_show_start_time' => '00:00',
|
||||
|
|
|
@ -318,6 +318,13 @@ class StoredFile {
|
|||
|
||||
Playlist::DeleteFileFromAllPlaylists($this->getId());
|
||||
$this->_file->delete();
|
||||
|
||||
if (isset($res)) {
|
||||
return $res;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,7 +6,7 @@ from subprocess import Popen, PIPE
|
|||
class AirtimeMediaMonitorBootstrap():
|
||||
|
||||
"""AirtimeMediaMonitorBootstrap constructor
|
||||
|
||||
|
||||
Keyword Arguments:
|
||||
logger -- reference to the media-monitor logging facility
|
||||
pe -- reference to an instance of ProcessEvent
|
||||
|
@ -17,36 +17,36 @@ class AirtimeMediaMonitorBootstrap():
|
|||
self.pe = pe
|
||||
self.api_client = api_client
|
||||
self.mmc = mmc
|
||||
|
||||
|
||||
"""On bootup we want to scan all directories and look for files that
|
||||
weren't there or files that changed before media-monitor process
|
||||
went offline.
|
||||
"""
|
||||
def scan(self):
|
||||
directories = self.get_list_of_watched_dirs();
|
||||
|
||||
|
||||
self.logger.info("watched directories found: %s", directories)
|
||||
|
||||
|
||||
for id, dir in directories.iteritems():
|
||||
self.logger.debug("%s, %s", id, dir)
|
||||
self.sync_database_to_filesystem(id, dir)
|
||||
|
||||
|
||||
"""Gets a list of files that the Airtime database knows for a specific directory.
|
||||
You need to provide the directory's row ID, which is obtained when calling
|
||||
You need to provide the directory's row ID, which is obtained when calling
|
||||
get_list_of_watched_dirs function.
|
||||
dir_id -- row id of the directory in the cc_watched_dirs database table
|
||||
"""
|
||||
def list_db_files(self, dir_id):
|
||||
return self.api_client.list_all_db_files(dir_id)
|
||||
|
||||
|
||||
"""
|
||||
returns the path and the database row id for this path for all watched directories. Also
|
||||
returns the path and the database row id for this path for all watched directories. Also
|
||||
returns the Stor directory, which can be identified by its row id (always has value of "1")
|
||||
"""
|
||||
def get_list_of_watched_dirs(self):
|
||||
json = self.api_client.list_all_watched_dirs()
|
||||
return json["dirs"]
|
||||
|
||||
return json["dirs"]
|
||||
|
||||
"""
|
||||
This function takes in a path name provided by the database (and its corresponding row id)
|
||||
and reads the list of files in the local file system. Its purpose is to discover which files
|
||||
|
@ -57,42 +57,42 @@ class AirtimeMediaMonitorBootstrap():
|
|||
dir -- pathname of the directory
|
||||
"""
|
||||
def sync_database_to_filesystem(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 because some of the tests for new files return result sets that are not
|
||||
mutually exclusive from each other.
|
||||
"""
|
||||
new_and_modified_files = set()
|
||||
removed_files = set()
|
||||
|
||||
|
||||
|
||||
|
||||
db_known_files_set = set()
|
||||
files = self.list_db_files(dir_id)
|
||||
for file in files['files']:
|
||||
db_known_files_set.add(file)
|
||||
|
||||
|
||||
new_files = self.mmc.scan_dir_for_new_files(dir)
|
||||
all_files_set = set()
|
||||
for file_path in new_files:
|
||||
if len(file_path.strip(" \n")) > 0:
|
||||
all_files_set.add(file_path[len(dir):])
|
||||
|
||||
all_files_set.add(file_path[len(dir):])
|
||||
|
||||
if os.path.exists(self.mmc.timestamp_file):
|
||||
"""find files that have been modified since the last time media-monitor process started."""
|
||||
time_diff_sec = time.time() - os.path.getmtime(self.mmc.timestamp_file)
|
||||
command = "find %s -type f -iname '*.ogg' -o -iname '*.mp3' -readable -mmin -%d" % (dir, time_diff_sec/60+1)
|
||||
else:
|
||||
command = "find %s -type f -iname '*.ogg' -o -iname '*.mp3' -readable" % dir
|
||||
|
||||
|
||||
stdout = self.mmc.execCommandAndReturnStdOut(command)
|
||||
stdout = unicode(stdout, "utf_8")
|
||||
|
||||
new_files = stdout.splitlines()
|
||||
|
||||
|
||||
for file_path in new_files:
|
||||
if len(file_path.strip(" \n")) > 0:
|
||||
new_and_modified_files.add(file_path[len(dir)+1:])
|
||||
|
||||
new_and_modified_files.add(file_path[len(dir):])
|
||||
|
||||
"""
|
||||
new_and_modified_files gives us a set of files that were either copied or modified
|
||||
since the last time media-monitor was running. These files were collected based on
|
||||
|
@ -101,28 +101,32 @@ class AirtimeMediaMonitorBootstrap():
|
|||
not affect last modified timestamp). Lets get a list of files that are on the file-system
|
||||
that the db has no record of, and vice-versa.
|
||||
"""
|
||||
|
||||
|
||||
deleted_files_set = db_known_files_set - all_files_set
|
||||
new_files_set = all_files_set - db_known_files_set
|
||||
modified_files_set = new_and_modified_files - new_files_set
|
||||
|
||||
|
||||
self.logger.info("Deleted files: \n%s\n\n"%deleted_files_set)
|
||||
self.logger.info("New files: \n%s\n\n"%new_files_set)
|
||||
self.logger.info("Modified files: \n%s\n\n"%modified_files_set)
|
||||
|
||||
self.logger.info("Modified files: \n%s\n\n"%modified_files_set)
|
||||
|
||||
#"touch" file timestamp
|
||||
self.mmc.touch_index_file()
|
||||
|
||||
|
||||
for file_path in deleted_files_set:
|
||||
self.pe.handle_removed_file(False, "%s/%s" % (dir, file_path))
|
||||
|
||||
self.pe.handle_removed_file(False, "%s%s" % (dir, file_path))
|
||||
deleted_files_set.clear()
|
||||
|
||||
for file_path in new_files_set:
|
||||
file_path = "%s/%s" % (dir, file_path)
|
||||
file_path = "%s%s" % (dir, file_path)
|
||||
if os.path.exists(file_path):
|
||||
self.pe.handle_created_file(False, os.path.basename(file_path), file_path)
|
||||
|
||||
|
||||
new_files_set.clear()
|
||||
|
||||
for file_path in modified_files_set:
|
||||
file_path = "%s/%s" % (dir, file_path)
|
||||
file_path = "%s%s" % (dir, file_path)
|
||||
if os.path.exists(file_path):
|
||||
self.pe.handle_modified_file(False, os.path.basename(file_path), file_path)
|
||||
|
||||
modified_files_set.clear()
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ class AirtimeNotifier(Notifier):
|
|||
self.logger.info("Adding file to ignore: %s ", filepath)
|
||||
mm.add_filepath_to_ignore(filepath)
|
||||
|
||||
if m['delete'] == "true":
|
||||
if m['delete']:
|
||||
self.logger.info("Deleting file: %s ", filepath)
|
||||
os.unlink(filepath)
|
||||
|
||||
|
|
Loading…
Reference in New Issue