Initial commit
This commit is contained in:
commit
4fc03a7a77
12
config.ini
Normal file
12
config.ini
Normal file
@ -0,0 +1,12 @@
|
||||
[Tools]
|
||||
# https://github.com/jiixyj/loudness-scanner.git
|
||||
LOUDNESS_SCANNER = /opt/loudness-scanner/loudness
|
||||
|
||||
[MOS]
|
||||
XML_LOG_PATH = /mnt/sp-somosgw-01/
|
||||
CLIP_PATH_TRANSFORM_FROM = \\\\sp-soisilon-01\\sonaps\\intern
|
||||
CLIP_PATH_TRANSFORM_TO = /mnt/sp-soisilon-01
|
||||
|
||||
[LUFS]
|
||||
TARGET_VALUE = -23.0
|
||||
|
64
dbschema.sql
Normal file
64
dbschema.sql
Normal file
@ -0,0 +1,64 @@
|
||||
PRAGMA journal_mode=WAL;
|
||||
PRAGMA foreign_keys=on;
|
||||
|
||||
CREATE TABLE "mosservers" (
|
||||
"mosId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
"mosServer" TEXT
|
||||
);
|
||||
|
||||
-- Default values ... might be omitted later?
|
||||
INSERT INTO "mosservers" ("mosServer") VALUES
|
||||
("Material.n24test.intern.mos"),
|
||||
("StudioA.n24test.intern.mos"),
|
||||
("Material.n24prod.intern.mos"),
|
||||
("StudioA.n24prod.intern.mos")
|
||||
;
|
||||
|
||||
CREATE TABLE "mosstatus" (
|
||||
"statusId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
"status" TEXT
|
||||
);
|
||||
|
||||
INSERT INTO "mosstatus" ("status") VALUES
|
||||
("NEW"),
|
||||
("UPDATED"),
|
||||
("MOVED")
|
||||
;
|
||||
|
||||
CREATE TABLE "mosair" (
|
||||
"airId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
"objAir" TEXT
|
||||
);
|
||||
|
||||
INSERT INTO "mosair" ("objAir") VALUES
|
||||
("READY"),
|
||||
("NOT READY")
|
||||
;
|
||||
|
||||
CREATE TABLE "mosgroups" (
|
||||
"groupId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
"objGroup" TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE "mosobjects" (
|
||||
"objId" TEXT PRIMARY KEY,
|
||||
"mosId" INTEGER REFERENCES "mosservers" ("mosId"),
|
||||
"statusId" INTEGER REFERENCES "mosstatus" ("statusId"),
|
||||
"objSlug" TEXT,
|
||||
"objPath" TEXT,
|
||||
"objAir" INTEGER REFERENCES "mosair" ("airId"),
|
||||
"created" INTEGER,
|
||||
"createdBy" TEXT,
|
||||
"changed" INTEGER,
|
||||
"changedBy" TEXT,
|
||||
"groupId" INTEGER REFERENCES "mosgroups" ("groupId")
|
||||
);
|
||||
|
||||
CREATE TABLE "mosobjlinks" (
|
||||
"objId" TEXT PRIMARY KEY,
|
||||
"planningId" TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE "todo" (
|
||||
"objId" TEXT PRIMARY KEY
|
||||
);
|
3
init_db.sh
Executable file
3
init_db.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
sqlite3 mosobjects.db3 < dbschema.sql
|
||||
|
96
scan_moslogs.py
Executable file
96
scan_moslogs.py
Executable file
@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import configparser
|
||||
import datetime
|
||||
import fnmatch
|
||||
import os
|
||||
import re
|
||||
import sqlite3
|
||||
import sys
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
c = configparser.ConfigParser()
|
||||
c.read("config.ini")
|
||||
|
||||
today_str = "{:%Y%m%d}".format(datetime.datetime.now())
|
||||
MOS_LOG_PATH = c.get("MOS", "XML_LOG_PATH")
|
||||
|
||||
# TODO: Store and read from database or ini!
|
||||
LAST_PARSED_FILE = "MOSMessage-20170221-120000.xml"
|
||||
|
||||
# Scan available MOSMessage logs and collect those we still need to scan
|
||||
files_to_parse = []
|
||||
for file in os.listdir(MOS_LOG_PATH):
|
||||
if fnmatch.fnmatch(file, "MOSMessage-*.xml"):
|
||||
# Only use less-than to re-read the file we had last (might have add. data)
|
||||
if file < LAST_PARSED_FILE:
|
||||
continue
|
||||
files_to_parse.append(MOS_LOG_PATH + file)
|
||||
|
||||
num_files = len(files_to_parse)
|
||||
print("Found {} files to be parsed.".format(num_files))
|
||||
|
||||
#sys.exit(0)
|
||||
|
||||
def get_text_or_default(parent_node, node_names, default_value):
|
||||
if not isinstance(node_names, list):
|
||||
node_names = [node_names]
|
||||
node = parent_node
|
||||
for n in node_names:
|
||||
node = node.find(n)
|
||||
if node is None:
|
||||
return default_value
|
||||
return node.text
|
||||
|
||||
def parse_mos_xml(mosElem):
|
||||
mosId = mosElem.find("mosID").text
|
||||
mosObj = mosElem.find("mosObj")
|
||||
objId = mosObj.find("objID").text
|
||||
status = mosObj.find("status").text
|
||||
|
||||
if status == "DELETED":
|
||||
return False
|
||||
|
||||
objData = {
|
||||
"mosId": mosId,
|
||||
"objId": objId,
|
||||
"status": status,
|
||||
"objSlug": get_text_or_default(mosObj, "objSlug", ""),
|
||||
"objPath": get_text_or_default(mosObj, ["objPaths", "objPath"], ""),
|
||||
"objGroup": get_text_or_default(mosObj, "objGroup", ""),
|
||||
"objAir": get_text_or_default(mosObj, "objAir", ""),
|
||||
"created": get_text_or_default(mosObj, "created", ""),
|
||||
"createdBy": get_text_or_default(mosObj, "createdBy", ""),
|
||||
"changed": get_text_or_default(mosObj, "changed", ""),
|
||||
"changedBy": get_text_or_default(mosObj, "changedBy", ""),
|
||||
"planningId": get_text_or_default(mosObj, ["mosExternalMetadata", "mosPayload", "planningID"], "")
|
||||
}
|
||||
#print(repr(objData))
|
||||
return objData
|
||||
|
||||
file_count = 0
|
||||
last_file = ""
|
||||
for file in files_to_parse:
|
||||
file_count += 1
|
||||
last_file = os.path.basename(file)
|
||||
tree = ET.parse(file)
|
||||
print("\n{} [{:d}/{:d}]: ".format(file, file_count, num_files), end="")
|
||||
|
||||
root = tree.getroot()
|
||||
# Walk all <mosNotify...> objects
|
||||
for elem in root:
|
||||
# Skip everything which is not a mosObj message
|
||||
if elem.attrib.get("command") != "mosObj":
|
||||
continue
|
||||
|
||||
mos = elem.find("mos")
|
||||
objData = parse_mos_xml(mos)
|
||||
if objData:
|
||||
# TODO: Write objData to database
|
||||
print(".", end="")
|
||||
else:
|
||||
print("x", end="")
|
||||
|
||||
print("")
|
||||
print("Last file: {}".format(last_file))
|
Loading…
x
Reference in New Issue
Block a user