Format code using black
This commit is contained in:
parent
efe4fa027e
commit
c27f020d73
85 changed files with 3238 additions and 2243 deletions
|
@ -16,8 +16,8 @@ similar code when it starts up (but then makes changes if something is different
|
|||
"""
|
||||
|
||||
|
||||
class AirtimeMediaMonitorBootstrap():
|
||||
|
||||
class AirtimeMediaMonitorBootstrap:
|
||||
|
||||
"""AirtimeMediaMonitorBootstrap constructor
|
||||
|
||||
Keyword Arguments:
|
||||
|
@ -25,8 +25,9 @@ class AirtimeMediaMonitorBootstrap():
|
|||
pe -- reference to an instance of ProcessEvent
|
||||
api_clients -- reference of api_clients to communicate with airtime-server
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
config = ConfigObj('/etc/airtime/airtime.conf')
|
||||
config = ConfigObj("/etc/airtime/airtime.conf")
|
||||
self.api_client = apc.api_client_factory(config)
|
||||
|
||||
"""
|
||||
|
@ -36,25 +37,26 @@ class AirtimeMediaMonitorBootstrap():
|
|||
print 'Error configuring logging: ', e
|
||||
sys.exit(1)
|
||||
"""
|
||||
|
||||
|
||||
self.logger = logging.getLogger()
|
||||
self.logger.info("Adding %s on watch list...", "xxx")
|
||||
|
||||
|
||||
self.scan()
|
||||
|
||||
|
||||
"""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();
|
||||
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)
|
||||
#CHANGED!!!
|
||||
#self.sync_database_to_filesystem(id, api_client.encode_to(dir, "utf-8"))
|
||||
# CHANGED!!!
|
||||
# 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.
|
||||
|
@ -62,6 +64,7 @@ class AirtimeMediaMonitorBootstrap():
|
|||
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)
|
||||
|
||||
|
@ -69,23 +72,29 @@ class AirtimeMediaMonitorBootstrap():
|
|||
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"]
|
||||
|
||||
|
||||
def scan_dir_for_existing_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)
|
||||
#CHANGED!!
|
||||
# CHANGED!!
|
||||
stdout = self.exec_command(command).decode("UTF-8")
|
||||
|
||||
|
||||
return stdout.splitlines()
|
||||
|
||||
|
||||
def exec_command(self, command):
|
||||
p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
|
||||
stdout, stderr = p.communicate()
|
||||
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)
|
||||
return stdout
|
||||
|
||||
|
@ -98,6 +107,7 @@ class AirtimeMediaMonitorBootstrap():
|
|||
dir_id -- row id of the directory in the cc_watched_dirs database table
|
||||
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
|
||||
|
@ -107,7 +117,7 @@ class AirtimeMediaMonitorBootstrap():
|
|||
db_known_files_set = set()
|
||||
|
||||
files = self.list_db_files(dir_id)
|
||||
for file in files['files']:
|
||||
for file in files["files"]:
|
||||
db_known_files_set.add(file)
|
||||
|
||||
existing_files = self.scan_dir_for_existing_files(dir)
|
||||
|
@ -115,18 +125,17 @@ class AirtimeMediaMonitorBootstrap():
|
|||
existing_files_set = set()
|
||||
for file_path in existing_files:
|
||||
if len(file_path.strip(" \n")) > 0:
|
||||
existing_files_set.add(file_path[len(dir):])
|
||||
existing_files_set.add(file_path[len(dir) :])
|
||||
|
||||
|
||||
deleted_files_set = db_known_files_set - existing_files_set
|
||||
new_files_set = existing_files_set - db_known_files_set
|
||||
|
||||
print("DB Known files: \n%s\n\n" % len(db_known_files_set))
|
||||
print("FS Known files: \n%s\n\n" % len(existing_files_set))
|
||||
|
||||
print("Deleted files: \n%s\n\n" % deleted_files_set)
|
||||
print("New files: \n%s\n\n" % new_files_set)
|
||||
|
||||
|
||||
print ("DB Known files: \n%s\n\n"%len(db_known_files_set))
|
||||
print ("FS Known files: \n%s\n\n"%len(existing_files_set))
|
||||
|
||||
print ("Deleted files: \n%s\n\n"%deleted_files_set)
|
||||
print ("New files: \n%s\n\n"%new_files_set)
|
||||
|
||||
if __name__ == "__main__":
|
||||
AirtimeMediaMonitorBootstrap()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue