-Media monitor not handling unicode incorrectly or comparing UTF-8 with unicode
This commit is contained in:
parent
39a41f40ed
commit
0716e0425c
|
@ -42,7 +42,7 @@ class AirtimeMediaMonitorBootstrap():
|
||||||
|
|
||||||
for id, dir in directories.iteritems():
|
for id, dir in directories.iteritems():
|
||||||
self.logger.debug("%s, %s", id, dir)
|
self.logger.debug("%s, %s", id, dir)
|
||||||
self.sync_database_to_filesystem(id, api_client.encode_to(dir, "utf-8"))
|
self.sync_database_to_filesystem(id, dir)
|
||||||
|
|
||||||
"""Gets a list of files that the Airtime database knows for a specific directory.
|
"""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
|
||||||
|
@ -82,7 +82,7 @@ class AirtimeMediaMonitorBootstrap():
|
||||||
db_known_files_set = set()
|
db_known_files_set = set()
|
||||||
files = self.list_db_files(dir_id)
|
files = self.list_db_files(dir_id)
|
||||||
for file in files['files']:
|
for file in files['files']:
|
||||||
db_known_files_set.add(api_client.encode_to(file, 'utf-8'))
|
db_known_files_set.add(file)
|
||||||
|
|
||||||
new_files = self.mmc.scan_dir_for_new_files(dir)
|
new_files = self.mmc.scan_dir_for_new_files(dir)
|
||||||
|
|
||||||
|
@ -123,9 +123,6 @@ class AirtimeMediaMonitorBootstrap():
|
||||||
new_files_set = all_files_set - db_known_files_set
|
new_files_set = all_files_set - db_known_files_set
|
||||||
modified_files_set = new_and_modified_files - new_files_set
|
modified_files_set = new_and_modified_files - new_files_set
|
||||||
|
|
||||||
#NAOMI: Please comment out the "Known files" line, if you find the bug.
|
|
||||||
#it is for debugging purposes only (Too much data will be written to log). -mk
|
|
||||||
#self.logger.info("Known files: \n%s\n\n"%db_known_files_set)
|
|
||||||
self.logger.info("Deleted files: \n%s\n\n"%deleted_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("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)
|
||||||
|
|
|
@ -251,12 +251,29 @@ class MediaMonitorCommon:
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
self.logger.warn("command \n%s\n return with a non-zero return value", command)
|
self.logger.warn("command \n%s\n return with a non-zero return value", command)
|
||||||
self.logger.error(stderr)
|
self.logger.error(stderr)
|
||||||
|
|
||||||
|
try:
|
||||||
|
"""
|
||||||
|
File name charset encoding is UTF-8.
|
||||||
|
"""
|
||||||
|
stdout = stdout.decode("UTF-8")
|
||||||
|
except Exception, e:
|
||||||
|
self.logger.error("Could not decode %s using UTF-8" % stdout)
|
||||||
|
|
||||||
return stdout
|
return stdout
|
||||||
|
|
||||||
def scan_dir_for_new_files(self, dir):
|
def scan_dir_for_new_files(self, dir):
|
||||||
command = 'find "%s" -type f -iname "*.ogg" -o -iname "*.mp3" -readable' % dir.replace('"', '\\"')
|
command = 'find "%s" -type f -iname "*.ogg" -o -iname "*.mp3" -readable' % dir.replace('"', '\\"')
|
||||||
self.logger.debug(command)
|
self.logger.debug(command)
|
||||||
stdout = self.exec_command(command)
|
stdout = self.exec_command(command).decode("UTF-8")
|
||||||
|
|
||||||
|
try:
|
||||||
|
"""
|
||||||
|
File name charset encoding is UTF-8.
|
||||||
|
"""
|
||||||
|
stdout = stdout.decode("UTF-8")
|
||||||
|
except Exception, e:
|
||||||
|
self.logger.error("Could not decode %s using UTF-8" % stdout)
|
||||||
|
|
||||||
return stdout.splitlines()
|
return stdout.splitlines()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue