From 506f6afa7b7ec80fa955ebd16fd917e5c4d8c19d Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 24 Aug 2012 17:10:43 -0400 Subject: [PATCH 01/20] cc-3936: Added function to recognize the owner of a file if it's there. Added corresponding tests. --- .../media-monitor2/media/monitor/pure.py | 20 +++++++++++++++++++ python_apps/media-monitor2/tests/test_pure.py | 12 +++++++++++ 2 files changed, 32 insertions(+) diff --git a/python_apps/media-monitor2/media/monitor/pure.py b/python_apps/media-monitor2/media/monitor/pure.py index fa4aa7480..bf6975068 100644 --- a/python_apps/media-monitor2/media/monitor/pure.py +++ b/python_apps/media-monitor2/media/monitor/pure.py @@ -418,6 +418,26 @@ def sub_path(directory,f): common = os.path.commonprefix([ normalized, normpath(f) ]) return common == normalized +def owner_id(original_path): + """ + Given 'original_path' return the file name of the of 'identifier' file. + return the id that is contained in it. If no file is found or nothing is + read then -1 is returned. File is deleted after the number has been read + """ + fname = "%s.identifier" % original_path + owner_id = -1 + try: + f = open(fname) + for line in f: + owner_id = int(line) + break + f.close() + except Exception: pass + else: + try: os.unlink(fname) + except Exception: raise + return owner_id + if __name__ == '__main__': import doctest doctest.testmod() diff --git a/python_apps/media-monitor2/tests/test_pure.py b/python_apps/media-monitor2/tests/test_pure.py index 59f88dabe..b4e870023 100644 --- a/python_apps/media-monitor2/tests/test_pure.py +++ b/python_apps/media-monitor2/tests/test_pure.py @@ -82,4 +82,16 @@ class TestMMP(unittest.TestCase): self.assertEqual( mmp.parse_int("123asf"), "123" ) self.assertEqual( mmp.parse_int("asdf"), None ) + def test_owner_id(self): + start_path = "testing.mp3" + id_path = "testing.mp3.identifier" + o_id = 123 + f = open(id_path, 'w') + f.write("123") + f.close() + possible_id = mmp.owner_id(start_path) + self.assertFalse( os.path.exists(id_path) ) + self.assertEqual( possible_id, o_id ) + self.assertEqual( -1, mmp.owner_id("something.random") ) + if __name__ == '__main__': unittest.main() From 899d76ecbb3ccdec52f46808cc40b6b2d790f504 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 24 Aug 2012 17:11:14 -0400 Subject: [PATCH 02/20] cc-3936: Added mechanism that will assign ownership to file events in mm2 --- .../media-monitor2/media/monitor/owners.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 python_apps/media-monitor2/media/monitor/owners.py diff --git a/python_apps/media-monitor2/media/monitor/owners.py b/python_apps/media-monitor2/media/monitor/owners.py new file mode 100644 index 000000000..c85045c7f --- /dev/null +++ b/python_apps/media-monitor2/media/monitor/owners.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +from media.monitor.log import get_logger +log = get_logger() +# hash: 'filepath' => owner_id +owners = {} + +def add_file_owner(f,owner): + """ + Associate file f with owner. If owner is -1 then do we will not record it + because -1 means there is no owner + """ + if owner == -1: return None + if f in owners: + if owner != owners[f]: # check for fishiness + log.info("Warning ownership of file '%s' changed from '%d' to '%d'" + % (f, owners[f], owner)) + owners[f] = owner + +def has_owner(f): + """ + True if f is owned by somebody. False otherwise. + """ + return f in owners + +def remove_file_owner(f): + """ + Try and delete any association made with file f. Returns true if the the + association was actually deleted. False otherwise. + """ + if f in owners: + del owners[f] + return True + else: + log.warn("Trying to delete file that does not exist: '%s'" % f) + return False + From 8e6bc0bedeea9d09877b5edaa45ce0e1f18af5e9 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 24 Aug 2012 17:39:27 -0400 Subject: [PATCH 03/20] cc-3936: Added reset owners function for safe use. Changed the return mechanics of add_file_owner. --- python_apps/media-monitor2/media/monitor/owners.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/python_apps/media-monitor2/media/monitor/owners.py b/python_apps/media-monitor2/media/monitor/owners.py index c85045c7f..a8a39cd7d 100644 --- a/python_apps/media-monitor2/media/monitor/owners.py +++ b/python_apps/media-monitor2/media/monitor/owners.py @@ -4,17 +4,27 @@ log = get_logger() # hash: 'filepath' => owner_id owners = {} +def reset_owners(): + """ + Wipes out all file => owner associations + """ + global owners + owners = {} + def add_file_owner(f,owner): """ Associate file f with owner. If owner is -1 then do we will not record it - because -1 means there is no owner + because -1 means there is no owner. Returns True if f is being stored after + the function. False otherwise. """ - if owner == -1: return None + if owner == -1: return False if f in owners: if owner != owners[f]: # check for fishiness log.info("Warning ownership of file '%s' changed from '%d' to '%d'" % (f, owners[f], owner)) + else: return True owners[f] = owner + return True def has_owner(f): """ From 1654d524d1d5168e555660611d26f31499bfe563 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 24 Aug 2012 17:39:52 -0400 Subject: [PATCH 04/20] cc-3936: Added some tests for media.monitor.owners. --- .../media-monitor2/tests/test_owners.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 python_apps/media-monitor2/tests/test_owners.py diff --git a/python_apps/media-monitor2/tests/test_owners.py b/python_apps/media-monitor2/tests/test_owners.py new file mode 100644 index 000000000..3958bb4da --- /dev/null +++ b/python_apps/media-monitor2/tests/test_owners.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +import unittest +import media.monitor.owners as owners + +class TestMMP(unittest.TestCase): + def setUp(self): + self.f = "test.mp3" + + def test_has_owner(self): + owners.reset_owners() + o = 12345 + self.assertTrue( owners.add_file_owner(self.f,o) ) + self.assertTrue( owners.has_owner(self.f) ) + + def test_add_file_owner(self): + owners.reset_owners() + self.assertFalse( owners.add_file_owner('testing', -1) ) + self.assertTrue( owners.add_file_owner(self.f, 123) ) + self.assertTrue( owners.add_file_owner(self.f, 123) ) + self.assertTrue( owners.add_file_owner(self.f, 456) ) + + def test_remove_file_owner(self): + owners.reset_owners() + self.assertTrue( owners.add_file_owner(self.f, 123) ) + self.assertTrue( owners.remove_file_owner(self.f) ) + self.assertFalse( owners.remove_file_owner(self.f) ) + +if __name__ == '__main__': unittest.main() + From fcc853b732b09f0bfcfc5997c3c6ca05a1fa7dc1 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 24 Aug 2012 18:19:32 -0400 Subject: [PATCH 05/20] cc-3936: Renamed metadata key for owner id. --- airtime_mvc/application/models/StoredFile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index da01d8c54..79b6a062b 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -150,7 +150,7 @@ class Application_Model_StoredFile if(!$owner) { // no owner detected, we try to assign one. // if MDATA_OWNER_ID is not set then we default to the // first admin user we find - if (!array_key_exists('MDATA_OWNER_ID', $p_md)) { + if (!array_key_exists('MDATA_KEY_OWNER_ID', $p_md)) { //$admins = Application_Model_User::getUsers(array('A')); $admins = Application_Model_User::getUsersOfType('A'); //$admins = array(); From ad4cc7bdaf8214d50c1f0999052a455b8bddd3c9 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 24 Aug 2012 18:19:55 -0400 Subject: [PATCH 06/20] cc-3936: Assigned MDATA_KEY_OWNER_ID to new file events. --- python_apps/media-monitor2/media/monitor/events.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/python_apps/media-monitor2/media/monitor/events.py b/python_apps/media-monitor2/media/monitor/events.py index 43ae883f8..a3515a4ff 100644 --- a/python_apps/media-monitor2/media/monitor/events.py +++ b/python_apps/media-monitor2/media/monitor/events.py @@ -2,6 +2,7 @@ import os import abc import media.monitor.pure as mmp +import media.monitor.owners as owners from media.monitor.pure import LazyProperty from media.monitor.metadata import Metadata from media.monitor.log import Loggable @@ -12,6 +13,8 @@ class PathChannel(object): self.signal = signal self.path = path +# TODO : Move this to it's file. Also possible unsingleton and use it as a +# simple module just like m.m.owners class EventRegistry(object): """ This class's main use is to keep track all events with a cookie attribute. @@ -56,6 +59,7 @@ class BaseEvent(Loggable): self._raw_event = raw_event self.path = os.path.normpath(raw_event.pathname) else: self.path = raw_event + self.owner = owners.get_owner() self._pack_hook = lambda: None # no op # into another event @@ -90,6 +94,7 @@ class BaseEvent(Loggable): try: self._pack_hook() ret = self.pack() + owners.remove_file_owner(self.path) return ret except BadSongFile as e: return [e] @@ -102,6 +107,14 @@ class BaseEvent(Loggable): # We don't transfer the _pack_hook over to the new event return self + def assign_owner(self,req): + """ + Packs self.owner to req if the owner is valid. I.e. it's not -1. This + method is used by various events that would like to pass owner as a + parameter. NewFile for example. + """ + if self.owner != -1: req['MDATA_KEY_OWNER_ID'] + class FakePyinotify(object): """ sometimes we must create our own pyinotify like objects to @@ -125,6 +138,7 @@ class NewFile(BaseEvent, HasMetaData): """ req_dict = self.metadata.extract() req_dict['mode'] = u'create' + self.assign_owner(req_dict) req_dict['MDATA_KEY_FILEPATH'] = unicode( self.path ) return [req_dict] From 517fa705bcea333e6b39d809ffff2bf21819e906 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 24 Aug 2012 18:20:29 -0400 Subject: [PATCH 07/20] cc-3936: added owner recognition to organizer. --- python_apps/media-monitor2/media/monitor/organizer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python_apps/media-monitor2/media/monitor/organizer.py b/python_apps/media-monitor2/media/monitor/organizer.py index 7bab09fd5..42d567dc8 100644 --- a/python_apps/media-monitor2/media/monitor/organizer.py +++ b/python_apps/media-monitor2/media/monitor/organizer.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- -import media.monitor.pure as mmp +import media.monitor.pure as mmp +import media.monitor.owners as owners from media.monitor.handler import ReportHandler from media.monitor.log import Loggable from media.monitor.exceptions import BadSongFile @@ -47,6 +48,7 @@ class Organizer(ReportHandler,Loggable): new_path = mmp.organized_path(event.path, target_path, event.metadata.extract()) mmp.magic_move(event.path, new_path) + owners.add_file_owner(event.path, mmp.owner_id(event.path) ) self.logger.info('Organized: "%s" into "%s"' % (event.path, new_path)) except BadSongFile as e: From fec8f06135a4f47e0964438f8ed381e39c8b57f4 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 24 Aug 2012 18:21:19 -0400 Subject: [PATCH 08/20] cc-3936: - added get_owner to actually get the owner of the file for event objects. - removed possibly annoying logging. --- python_apps/media-monitor2/media/monitor/owners.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/python_apps/media-monitor2/media/monitor/owners.py b/python_apps/media-monitor2/media/monitor/owners.py index a8a39cd7d..9d9c043bf 100644 --- a/python_apps/media-monitor2/media/monitor/owners.py +++ b/python_apps/media-monitor2/media/monitor/owners.py @@ -11,6 +11,14 @@ def reset_owners(): global owners owners = {} + +def get_owner(f): + """ + Get the owner id of the file 'f' + """ + return owners[f] if f in owners else -1 + + def add_file_owner(f,owner): """ Associate file f with owner. If owner is -1 then do we will not record it @@ -40,7 +48,5 @@ def remove_file_owner(f): if f in owners: del owners[f] return True - else: - log.warn("Trying to delete file that does not exist: '%s'" % f) - return False + else: return False From d4bead4bd92e4044a01f6bad34e4e1af86d8b25c Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 27 Aug 2012 11:16:00 -0400 Subject: [PATCH 09/20] cc-3936: Added documenatation for various events. --- .../media-monitor2/media/monitor/events.py | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/python_apps/media-monitor2/media/monitor/events.py b/python_apps/media-monitor2/media/monitor/events.py index a3515a4ff..523e91f12 100644 --- a/python_apps/media-monitor2/media/monitor/events.py +++ b/python_apps/media-monitor2/media/monitor/events.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import os import abc -import media.monitor.pure as mmp +import media.monitor.pure as mmp import media.monitor.owners as owners from media.monitor.pure import LazyProperty from media.monitor.metadata import Metadata @@ -130,6 +130,10 @@ class OrganizeFile(BaseEvent, HasMetaData): raise AttributeError("You can't send organize events to airtime!!!") class NewFile(BaseEvent, HasMetaData): + """ + NewFile events are the only events that contain MDATA_KEY_OWNER_ID metadata + in them. + """ def __init__(self, *args, **kwargs): super(NewFile, self).__init__(*args, **kwargs) def pack(self): @@ -143,6 +147,11 @@ class NewFile(BaseEvent, HasMetaData): return [req_dict] class DeleteFile(BaseEvent): + """ + DeleteFile event only contains the path to be deleted. No other metadata + can be or is included. (This is because this event is fired after the + deletion occurs). + """ def __init__(self, *args, **kwargs): super(DeleteFile, self).__init__(*args, **kwargs) def pack(self): @@ -175,6 +184,10 @@ class ModifyFile(BaseEvent, HasMetaData): return [req_dict] def map_events(directory, constructor): + """ + Walks 'directory' and creates an event using 'constructor'. Returns a list + of the constructed events. + """ # -unknown-path should not appear in the path here but more testing # might be necessary for f in mmp.walk_supported(directory, clean_empties=False): @@ -183,18 +196,30 @@ def map_events(directory, constructor): except BadSongFile as e: yield e class DeleteDir(BaseEvent): + """ + A DeleteDir event unfolds itself into a list of DeleteFile events for every + file in the directory. + """ def __init__(self, *args, **kwargs): super(DeleteDir, self).__init__(*args, **kwargs) def pack(self): return map_events( self.path, DeleteFile ) class MoveDir(BaseEvent): + """ + A MoveDir event unfolds itself into a list of MoveFile events for every + file in the directory. + """ def __init__(self, *args, **kwargs): super(MoveDir, self).__init__(*args, **kwargs) def pack(self): return map_events( self.path, MoveFile ) class DeleteDirWatch(BaseEvent): + """ + Deleting a watched directory is different from deleting any other + directory. Hence we must have a separate event to handle this case + """ def __init__(self, *args, **kwargs): super(DeleteDirWatch, self).__init__(*args, **kwargs) def pack(self): From c05fd2baed5fd83b465d1811068218a3b6197d46 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 27 Aug 2012 11:21:20 -0400 Subject: [PATCH 10/20] cc-3936: Fixed bug where owner assignment statement was missing. --- python_apps/media-monitor2/media/monitor/events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python_apps/media-monitor2/media/monitor/events.py b/python_apps/media-monitor2/media/monitor/events.py index 523e91f12..11ceefaa9 100644 --- a/python_apps/media-monitor2/media/monitor/events.py +++ b/python_apps/media-monitor2/media/monitor/events.py @@ -113,7 +113,7 @@ class BaseEvent(Loggable): method is used by various events that would like to pass owner as a parameter. NewFile for example. """ - if self.owner != -1: req['MDATA_KEY_OWNER_ID'] + if self.owner != -1: req['MDATA_KEY_OWNER_ID'] = self.owner class FakePyinotify(object): """ From fd98b8c8b69b32722dc8e8b484b41e2d3b96d58d Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 27 Aug 2012 11:21:39 -0400 Subject: [PATCH 11/20] cc-3936: Documented 2 classes and 1 method. --- python_apps/media-monitor2/media/monitor/events.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/python_apps/media-monitor2/media/monitor/events.py b/python_apps/media-monitor2/media/monitor/events.py index 11ceefaa9..541d4e54a 100644 --- a/python_apps/media-monitor2/media/monitor/events.py +++ b/python_apps/media-monitor2/media/monitor/events.py @@ -9,6 +9,10 @@ from media.monitor.log import Loggable from media.monitor.exceptions import BadSongFile class PathChannel(object): + """ + Simple struct to hold a 'signal' string and a related 'path'. Basically + used as a named tuple + """ def __init__(self, signal, path): self.signal = signal self.path = path @@ -64,6 +68,11 @@ class BaseEvent(Loggable): # into another event def reset_hook(self): + """ + Resets the hook that is called after an event is packed. Before + resetting the hook we execute it to make sure that whatever cleanup + operations were queued are executed. + """ self._pack_hook() self._pack_hook = lambda: None @@ -124,6 +133,10 @@ class FakePyinotify(object): def __init__(self, path): self.pathname = path class OrganizeFile(BaseEvent, HasMetaData): + """ + The only kind of event that does support the pack protocol. It's used + internally with mediamonitor to move files in the organize directory. + """ def __init__(self, *args, **kwargs): super(OrganizeFile, self).__init__(*args, **kwargs) def pack(self): From ba61d4f4fbd88521e66160c73c549b41ecd68258 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 27 Aug 2012 11:26:48 -0400 Subject: [PATCH 12/20] cc-3936: Fixed bug caught by unit tests. --- python_apps/media-monitor2/media/monitor/events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python_apps/media-monitor2/media/monitor/events.py b/python_apps/media-monitor2/media/monitor/events.py index 541d4e54a..a36750b7f 100644 --- a/python_apps/media-monitor2/media/monitor/events.py +++ b/python_apps/media-monitor2/media/monitor/events.py @@ -63,7 +63,7 @@ class BaseEvent(Loggable): self._raw_event = raw_event self.path = os.path.normpath(raw_event.pathname) else: self.path = raw_event - self.owner = owners.get_owner() + self.owner = owners.get_owner(self.path) self._pack_hook = lambda: None # no op # into another event From 687a6d3c5ac6c0d4fa369d0560f93b3e924070d7 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 27 Aug 2012 11:44:33 -0400 Subject: [PATCH 13/20] cc-3936: removed intrusive logging --- airtime_mvc/application/models/StoredFile.php | 1 - python_apps/media-monitor2/media/monitor/eventcontractor.py | 1 - 2 files changed, 2 deletions(-) diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 79b6a062b..7e3bc26f7 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -183,7 +183,6 @@ class Application_Model_StoredFile if (isset($this->_dbMD[$dbColumn])) { $propelColumn = $this->_dbMD[$dbColumn]; $method = "set$propelColumn"; - Logging::info($method); $this->_file->$method($mdValue); } } diff --git a/python_apps/media-monitor2/media/monitor/eventcontractor.py b/python_apps/media-monitor2/media/monitor/eventcontractor.py index 089b30a44..7fa13b8cc 100644 --- a/python_apps/media-monitor2/media/monitor/eventcontractor.py +++ b/python_apps/media-monitor2/media/monitor/eventcontractor.py @@ -29,7 +29,6 @@ class EventContractor(Loggable): some other event in the storage was morphed into this newer one. Which should mean that the old event should be discarded. """ - self.logger.info("Attempting to register: '%s'" % str(evt)) if self.event_registered(evt): old_e = self.get_old_event(evt) # TODO : Perhaps there are other events that we can "contract" From 7270893b4de1a957aee8c5f36cf8f72392d23347 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 27 Aug 2012 12:07:54 -0400 Subject: [PATCH 14/20] cc-3936: Clarified comments regarding event hooks and file ownership. --- python_apps/media-monitor2/media/monitor/events.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python_apps/media-monitor2/media/monitor/events.py b/python_apps/media-monitor2/media/monitor/events.py index a36750b7f..660ff4c40 100644 --- a/python_apps/media-monitor2/media/monitor/events.py +++ b/python_apps/media-monitor2/media/monitor/events.py @@ -98,11 +98,11 @@ class BaseEvent(Loggable): events that must catch their own BadSongFile exceptions since generate a set of exceptions instead of a single one """ - # pack will only throw an exception if it processes one file but this - # is a little bit hacky try: self._pack_hook() ret = self.pack() + # Remove owner of this file only after packing. Otherwise packing + # will not serialize the owner correctly into the airtime request owners.remove_file_owner(self.path) return ret except BadSongFile as e: return [e] @@ -114,6 +114,8 @@ class BaseEvent(Loggable): self.path = evt.path self.__class__ = evt.__class__ # We don't transfer the _pack_hook over to the new event + # TODO : perhaps we should call the old events pack_hook just to make + # sure everything is done cleanly? return self def assign_owner(self,req): From 97bb041ba31e414af164883f5ba5a90a4fcd1e7b Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 27 Aug 2012 12:08:21 -0400 Subject: [PATCH 15/20] cc-3936: Added assertion for organizer to only handle correct events. --- python_apps/media-monitor2/media/monitor/organizer.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python_apps/media-monitor2/media/monitor/organizer.py b/python_apps/media-monitor2/media/monitor/organizer.py index 42d567dc8..bd4f218f0 100644 --- a/python_apps/media-monitor2/media/monitor/organizer.py +++ b/python_apps/media-monitor2/media/monitor/organizer.py @@ -5,6 +5,7 @@ import media.monitor.owners as owners from media.monitor.handler import ReportHandler from media.monitor.log import Loggable from media.monitor.exceptions import BadSongFile +from media.monitor.events import OrganizeFile class Organizer(ReportHandler,Loggable): """ @@ -39,6 +40,8 @@ class Organizer(ReportHandler,Loggable): directory and place it in the correct path (starting with self.target_path) """ + # Only handle this event type + assert isinstance(event, OrganizeFile) try: # We must select the target_path based on whether file was recorded # by airtime or not. From 92edaba55c1358c0eddfae7cc7556dfc1a318655 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 27 Aug 2012 12:08:36 -0400 Subject: [PATCH 16/20] cc-3936: Added test for get_owner function of the owner module. --- python_apps/media-monitor2/tests/test_owners.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/python_apps/media-monitor2/tests/test_owners.py b/python_apps/media-monitor2/tests/test_owners.py index 3958bb4da..04788cf4c 100644 --- a/python_apps/media-monitor2/tests/test_owners.py +++ b/python_apps/media-monitor2/tests/test_owners.py @@ -25,5 +25,12 @@ class TestMMP(unittest.TestCase): self.assertTrue( owners.remove_file_owner(self.f) ) self.assertFalse( owners.remove_file_owner(self.f) ) + def test_get_owner(self): + owners.reset_owners() + self.assertTrue( owners.add_file_owner(self.f, 123) ) + self.assertEqual( owners.get_owner(self.f), 123, "file is owned" ) + self.assertEqual( owners.get_owner("random_stuff.txt"), -1, + "file is not owned" ) + if __name__ == '__main__': unittest.main() From 87225d322edda58c32be92cfb4c8e8f75e4ad62f Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 27 Aug 2012 12:28:16 -0400 Subject: [PATCH 17/20] cc-3936: Fixed assertion. --- python_apps/media-monitor2/media/monitor/organizer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python_apps/media-monitor2/media/monitor/organizer.py b/python_apps/media-monitor2/media/monitor/organizer.py index bd4f218f0..ac6808dab 100644 --- a/python_apps/media-monitor2/media/monitor/organizer.py +++ b/python_apps/media-monitor2/media/monitor/organizer.py @@ -41,7 +41,7 @@ class Organizer(ReportHandler,Loggable): self.target_path) """ # Only handle this event type - assert isinstance(event, OrganizeFile) + assert isinstance(event, OrganizeFile) == True try: # We must select the target_path based on whether file was recorded # by airtime or not. From c14af747b0d3475428341040f526dd5524da12f5 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 27 Aug 2012 12:28:44 -0400 Subject: [PATCH 18/20] cc-3936: Fixed bug where wrong path was being used to identify a file's ownership. --- python_apps/media-monitor2/media/monitor/organizer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python_apps/media-monitor2/media/monitor/organizer.py b/python_apps/media-monitor2/media/monitor/organizer.py index ac6808dab..869b1a485 100644 --- a/python_apps/media-monitor2/media/monitor/organizer.py +++ b/python_apps/media-monitor2/media/monitor/organizer.py @@ -51,7 +51,7 @@ class Organizer(ReportHandler,Loggable): new_path = mmp.organized_path(event.path, target_path, event.metadata.extract()) mmp.magic_move(event.path, new_path) - owners.add_file_owner(event.path, mmp.owner_id(event.path) ) + owners.add_file_owner(new_path, mmp.owner_id(event.path) ) self.logger.info('Organized: "%s" into "%s"' % (event.path, new_path)) except BadSongFile as e: From dea764b8fd08d1a78100cd8ab0b0afb077679f57 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 27 Aug 2012 14:03:22 -0400 Subject: [PATCH 19/20] cc-3936: added warning for metadata attributes that are not defined in constants.php --- airtime_mvc/application/configs/constants.php | 1 + airtime_mvc/application/models/StoredFile.php | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/application/configs/constants.php b/airtime_mvc/application/configs/constants.php index 4833f7d91..1d1ed55e4 100644 --- a/airtime_mvc/application/configs/constants.php +++ b/airtime_mvc/application/configs/constants.php @@ -31,6 +31,7 @@ define('MDATA_KEY_TRACKNUMBER', 'track_number'); define('MDATA_KEY_CONDUCTOR', 'conductor'); define('MDATA_KEY_LANGUAGE', 'language'); define('MDATA_KEY_REPLAYGAIN', 'replay_gain'); +define('MDATA_KEY_OWNER_ID', 'owner_id'); define('UI_MDATA_VALUE_FORMAT_FILE', 'File'); define('UI_MDATA_VALUE_FORMAT_STREAM', 'live stream'); diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 7e3bc26f7..0052d1160 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -125,6 +125,9 @@ class Application_Model_StoredFile foreach ($p_md as $mdConst => $mdValue) { if (defined($mdConst)) { $dbMd[constant($mdConst)] = $mdValue; + } else { + Logging::info("Warning: using metadata that is not defined. + [$mdConst] => [$mdValue]"); } } $this->setDbColMetadata($dbMd); @@ -153,7 +156,6 @@ class Application_Model_StoredFile if (!array_key_exists('MDATA_KEY_OWNER_ID', $p_md)) { //$admins = Application_Model_User::getUsers(array('A')); $admins = Application_Model_User::getUsersOfType('A'); - //$admins = array(); if (count($admins) > 0) { // found admin => pick first one $owner = $admins[0]; } From cab7a6c93030beda068900ef1d69d34cd97b06d5 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 27 Aug 2012 14:07:05 -0400 Subject: [PATCH 20/20] cc-3936: added comment documenting metadata translation --- airtime_mvc/application/models/StoredFile.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 0052d1160..70c804c92 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -122,6 +122,8 @@ class Application_Model_StoredFile $p_md["MDATA_KEY_YEAR"] = $year; } + # Translate metadata attributes from media monitor (MDATA_KEY_*) + # to their counterparts in constants.php (usually the column names) foreach ($p_md as $mdConst => $mdValue) { if (defined($mdConst)) { $dbMd[constant($mdConst)] = $mdValue;