CC-3784: Some media files can be added twice when trying to upload 200 media files
-should be fixed
This commit is contained in:
parent
56fa147b6f
commit
7376e16077
5 changed files with 21 additions and 21 deletions
|
@ -406,9 +406,6 @@ class AirTimeApiClient(ApiClientInterface):
|
|||
logger = self.logger
|
||||
response = None
|
||||
try:
|
||||
|
||||
start = time.time()
|
||||
|
||||
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["update_media_url"])
|
||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
||||
url = url.replace("%%mode%%", mode)
|
||||
|
@ -422,9 +419,6 @@ class AirTimeApiClient(ApiClientInterface):
|
|||
logger.info("update media %s, filepath: %s, mode: %s", response, md['MDATA_KEY_FILEPATH'], mode)
|
||||
response = json.loads(response)
|
||||
|
||||
elapsed = (time.time() - start)
|
||||
logger.info("time taken to get response %s", elapsed)
|
||||
|
||||
if("error" not in response and is_record):
|
||||
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["upload_recorded"])
|
||||
url = url.replace("%%fileid%%", str(response[u'id']))
|
||||
|
|
|
@ -117,15 +117,15 @@ class AirtimeProcessEvent(ProcessEvent):
|
|||
self.logger.info("event: %s", event)
|
||||
self.logger.info("create_dict: %s", self.create_dict)
|
||||
|
||||
if event.pathname in self.create_dict:
|
||||
# detele corresponding entry from create_dict
|
||||
self.create_dict.pop(event.pathname)
|
||||
try:
|
||||
del self.create_dict[event.pathname]
|
||||
self.handle_created_file(event.dir, event.pathname, event.name)
|
||||
except KeyError, e:
|
||||
self.logger.error("%s does not exist in create_dict", event.pathname)
|
||||
|
||||
def handle_created_file(self, dir, pathname, name):
|
||||
if not dir:
|
||||
self.logger.debug("PROCESS_IN_CLOSE_WRITE: %s, name: %s, pathname: %s ", dir, name, pathname)
|
||||
#event is because of a created file
|
||||
|
||||
if self.mmc.is_temp_file(name) :
|
||||
#file created is a tmp file which will be modified and then moved back to the original filename.
|
||||
|
@ -150,10 +150,13 @@ class AirtimeProcessEvent(ProcessEvent):
|
|||
except Exception, e:
|
||||
self.logger.error('Exception: %s', e)
|
||||
self.logger.error("traceback: %s", traceback.format_exc())
|
||||
return
|
||||
|
||||
is_recorded = self.mmc.is_parent_directory(pathname, self.config.recorded_directory)
|
||||
self.file_events.append({'mode': self.config.MODE_CREATE, 'filepath': pathname, 'is_recorded_show': is_recorded})
|
||||
finally:
|
||||
return
|
||||
else:
|
||||
# only append to self.file_events if the file isn't going to be altered by organize_new_file(). If file is going
|
||||
# to be altered by organize_new_file(), then process_IN_MOVED_TO event will handle appending it to self.file_events
|
||||
is_recorded = self.mmc.is_parent_directory(pathname, self.config.recorded_directory)
|
||||
self.file_events.append({'mode': self.config.MODE_CREATE, 'filepath': pathname, 'is_recorded_show': is_recorded})
|
||||
|
||||
|
||||
def process_IN_MODIFY(self, event):
|
||||
|
@ -239,7 +242,7 @@ class AirtimeProcessEvent(ProcessEvent):
|
|||
self.file_events.append({'filepath': event.pathname, 'mode': self.config.MODE_MODIFY})
|
||||
del self.temp_files[event.cookie]
|
||||
elif event.cookie in self.cookies_IN_MOVED_FROM:
|
||||
#files original location was also in a watched directory
|
||||
#file's original location was also in a watched directory
|
||||
del self.cookies_IN_MOVED_FROM[event.cookie]
|
||||
if self.mmc.is_parent_directory(event.pathname, self.config.organize_directory):
|
||||
filepath = self.mmc.organize_new_file(event.pathname)
|
||||
|
@ -263,17 +266,18 @@ class AirtimeProcessEvent(ProcessEvent):
|
|||
if self.mmc.is_parent_directory(event.pathname, self.config.organize_directory):
|
||||
filepath = self.mmc.organize_new_file(event.pathname)
|
||||
|
||||
#delete files from organize if they can not be read properly.
|
||||
#delete files from organize if they cannot be read properly.
|
||||
if filepath is None:
|
||||
try:
|
||||
self.logger.info("Deleting file because it cannot be read properly: %s", event.pathname)
|
||||
os.remove(event.pathname)
|
||||
return
|
||||
except Exception, e:
|
||||
self.logger.error('Exception: %s', e)
|
||||
self.logger.error("traceback: %s", traceback.format_exc())
|
||||
finally:
|
||||
return
|
||||
else:
|
||||
#show dragged from unwatched folder into a watched folder. Do not "organize".:q!
|
||||
#show moved from unwatched folder into a watched folder. Do not "organize".
|
||||
if self.mmc.is_parent_directory(event.pathname, self.config.recorded_directory):
|
||||
is_recorded = True
|
||||
else:
|
||||
|
|
|
@ -335,7 +335,9 @@ def test_file_playability(pathname):
|
|||
|
||||
#when there is an single apostrophe inside of a string quoted by apostrophes, we can only escape it by replace that apostrophe
|
||||
#with '\''. This breaks the string into two, and inserts an escaped single quote in between them.
|
||||
command = "liquidsoap -c 'output.dummy(audio_to_stereo(single(\"%s\")))'" % pathname.replace("'", "'\\''")
|
||||
#We run the command as pypo because otherwise the target file is opened with write permissions, and this causes an ON_CLOSE_WRITE event
|
||||
#to be fired :/
|
||||
command = "sudo -u pypo liquidsoap -c 'output.dummy(audio_to_stereo(single(\"%s\")))'" % pathname.replace("'", "'\\''")
|
||||
return_code = subprocess.call(command, shell=True)
|
||||
else:
|
||||
return_code = 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue