cc-4105: fixed horrible bug related to 'strong' reffing
This commit is contained in:
parent
95e4488518
commit
ab658a3800
|
@ -13,7 +13,7 @@ def get_process_output(command):
|
||||||
"""
|
"""
|
||||||
Run subprocess and return stdout
|
Run subprocess and return stdout
|
||||||
"""
|
"""
|
||||||
logger.debug(command)
|
#logger.debug(command)
|
||||||
p = Popen(command, shell=True, stdout=PIPE)
|
p = Popen(command, shell=True, stdout=PIPE)
|
||||||
return p.communicate()[0].strip()
|
return p.communicate()[0].strip()
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ def duplicate_file(file_path):
|
||||||
fsrc = open(file_path, 'r')
|
fsrc = open(file_path, 'r')
|
||||||
fdst = tempfile.NamedTemporaryFile(delete=False)
|
fdst = tempfile.NamedTemporaryFile(delete=False)
|
||||||
|
|
||||||
logger.info("Copying %s to %s" % (file_path, fdst.name))
|
#logger.info("Copying %s to %s" % (file_path, fdst.name))
|
||||||
|
|
||||||
shutil.copyfileobj(fsrc, fdst)
|
shutil.copyfileobj(fsrc, fdst)
|
||||||
|
|
||||||
|
|
|
@ -16,14 +16,15 @@ class Handles(object):
|
||||||
|
|
||||||
class ReportHandler(Handles):
|
class ReportHandler(Handles):
|
||||||
__metaclass__ = abc.ABCMeta
|
__metaclass__ = abc.ABCMeta
|
||||||
def __init__(self, signal):
|
def __init__(self, signal, weak=False):
|
||||||
self.signal = signal
|
self.signal = signal
|
||||||
self.report_signal = "badfile"
|
self.report_signal = "badfile"
|
||||||
def dummy(sender, event): self.handle(sender,event)
|
def dummy(sender, event): self.handle(sender,event)
|
||||||
dispatcher.connect(dummy, signal=signal, sender=dispatcher.Any,
|
dispatcher.connect(dummy, signal=signal, sender=dispatcher.Any,
|
||||||
weak=False)
|
weak=weak)
|
||||||
|
|
||||||
def report_problem_file(self, event, exception=None):
|
def report_problem_file(self, event, exception=None):
|
||||||
|
import ipdb; ipdb.set_trace()
|
||||||
dispatcher.send(signal=self.report_signal, sender=self, event=event,
|
dispatcher.send(signal=self.report_signal, sender=self, event=event,
|
||||||
exception=exception)
|
exception=exception)
|
||||||
|
|
||||||
|
|
|
@ -85,13 +85,17 @@ class BaseListener(object):
|
||||||
class OrganizeListener(BaseListener, pyinotify.ProcessEvent, Loggable):
|
class OrganizeListener(BaseListener, pyinotify.ProcessEvent, Loggable):
|
||||||
# this class still don't handle the case where a dir was copied recursively
|
# this class still don't handle the case where a dir was copied recursively
|
||||||
|
|
||||||
def process_IN_CLOSE_WRITE(self, event): self.process_to_organize(event)
|
def process_IN_CLOSE_WRITE(self, event):
|
||||||
|
self.process_to_organize(event)
|
||||||
# got cookie
|
# got cookie
|
||||||
def process_IN_MOVED_TO(self, event): self.process_to_organize(event)
|
def process_IN_MOVED_TO(self, event):
|
||||||
|
self.process_to_organize(event)
|
||||||
|
|
||||||
def flush_events(self, path):
|
def flush_events(self, path):
|
||||||
"""organize the whole directory at path. (pretty much by doing what
|
"""
|
||||||
handle does to every file"""
|
organize the whole directory at path. (pretty much by doing what
|
||||||
|
handle does to every file
|
||||||
|
"""
|
||||||
flushed = 0
|
flushed = 0
|
||||||
for f in mmp.walk_supported(path, clean_empties=True):
|
for f in mmp.walk_supported(path, clean_empties=True):
|
||||||
self.logger.info("Bootstrapping: File in 'organize' directory: \
|
self.logger.info("Bootstrapping: File in 'organize' directory: \
|
||||||
|
@ -104,6 +108,8 @@ class OrganizeListener(BaseListener, pyinotify.ProcessEvent, Loggable):
|
||||||
@mediate_ignored
|
@mediate_ignored
|
||||||
@IncludeOnly(mmp.supported_extensions)
|
@IncludeOnly(mmp.supported_extensions)
|
||||||
def process_to_organize(self, event):
|
def process_to_organize(self, event):
|
||||||
|
print("I AM COMPLETELY INNOCENT")
|
||||||
|
import ipdb; ipdb.set_trace()
|
||||||
dispatcher.send(signal=self.signal, sender=self,
|
dispatcher.send(signal=self.signal, sender=self,
|
||||||
event=OrganizeFile(event))
|
event=OrganizeFile(event))
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,13 @@ class Organizer(ReportHandler,Loggable):
|
||||||
directory". The "storage" directory picks up all of its events through
|
directory". The "storage" directory picks up all of its events through
|
||||||
pyinotify. (These events are fed to it through StoreWatchListener)
|
pyinotify. (These events are fed to it through StoreWatchListener)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, channel, target_path, recorded_path):
|
def __init__(self, channel, target_path, recorded_path):
|
||||||
self.channel = channel
|
self.channel = channel
|
||||||
self.target_path = target_path
|
self.target_path = target_path
|
||||||
self.recorded_path = recorded_path
|
self.recorded_path = recorded_path
|
||||||
super(Organizer, self).__init__(signal=self.channel)
|
super(Organizer, self).__init__(signal=self.channel, weak=True)
|
||||||
|
|
||||||
def handle(self, sender, event):
|
def handle(self, sender, event):
|
||||||
"""
|
"""
|
||||||
Intercept events where a new file has been added to the organize
|
Intercept events where a new file has been added to the organize
|
||||||
|
@ -28,6 +30,7 @@ class Organizer(ReportHandler,Loggable):
|
||||||
# We must select the target_path based on whether file was recorded
|
# We must select the target_path based on whether file was recorded
|
||||||
# by airtime or not.
|
# by airtime or not.
|
||||||
# Do we need to "massage" the path using mmp.organized_path?
|
# Do we need to "massage" the path using mmp.organized_path?
|
||||||
|
print("Organizing: %s" % event.path)
|
||||||
target_path = self.recorded_path if event.metadata.is_recorded() \
|
target_path = self.recorded_path if event.metadata.is_recorded() \
|
||||||
else self.target_path
|
else self.target_path
|
||||||
new_path = mmp.organized_path(event.path, target_path,
|
new_path = mmp.organized_path(event.path, target_path,
|
||||||
|
@ -39,5 +42,6 @@ class Organizer(ReportHandler,Loggable):
|
||||||
self.report_problem_file(event=event, exception=e)
|
self.report_problem_file(event=event, exception=e)
|
||||||
# probably general error in mmp.magic.move...
|
# probably general error in mmp.magic.move...
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
self.unexpected_exception( e )
|
||||||
self.report_problem_file(event=event, exception=e)
|
self.report_problem_file(event=event, exception=e)
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import locale
|
||||||
|
|
||||||
from media.monitor.exceptions import FailedToSetLocale, FailedToCreateDir
|
from media.monitor.exceptions import FailedToSetLocale, FailedToCreateDir
|
||||||
|
|
||||||
supported_extensions = [u"mp3", u"ogg"]
|
supported_extensions = [u"mp3", u"ogg", u"oga"]
|
||||||
unicode_unknown = u'unknown'
|
unicode_unknown = u'unknown'
|
||||||
|
|
||||||
class LazyProperty(object):
|
class LazyProperty(object):
|
||||||
|
@ -31,8 +31,8 @@ class LazyProperty(object):
|
||||||
|
|
||||||
class IncludeOnly(object):
|
class IncludeOnly(object):
|
||||||
"""
|
"""
|
||||||
A little decorator to help listeners only be called on extensions they
|
A little decorator to help listeners only be called on extensions
|
||||||
support
|
they support
|
||||||
NOTE: this decorator only works on methods and not functions. Maybe
|
NOTE: this decorator only works on methods and not functions. Maybe
|
||||||
fix this?
|
fix this?
|
||||||
"""
|
"""
|
||||||
|
@ -138,6 +138,7 @@ def magic_move(old, new):
|
||||||
Moves path old to new and constructs the necessary to directories for new
|
Moves path old to new and constructs the necessary to directories for new
|
||||||
along the way
|
along the way
|
||||||
"""
|
"""
|
||||||
|
print("'%s' ==> '%s'" % (old, new))
|
||||||
new_dir = os.path.dirname(new)
|
new_dir = os.path.dirname(new)
|
||||||
if not os.path.exists(new_dir): os.makedirs(new_dir)
|
if not os.path.exists(new_dir): os.makedirs(new_dir)
|
||||||
shutil.move(old,new)
|
shutil.move(old,new)
|
||||||
|
|
Loading…
Reference in New Issue