From c643783556d3d0337421d47ffc1b4649ebebad61 Mon Sep 17 00:00:00 2001
From: James Meyer <james.meyer@operamail.com>
Date: Sat, 1 Dec 2012 17:31:27 -0600
Subject: LinHES-system: added gen_game_xml.py   This should be used to modify
 mythtv game.xml

---
 abs/core/LinHES-system/PKGBUILD        |   6 +-
 abs/core/LinHES-system/gen_game_xml.py | 117 +++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+), 2 deletions(-)
 create mode 100644 abs/core/LinHES-system/gen_game_xml.py

diff --git a/abs/core/LinHES-system/PKGBUILD b/abs/core/LinHES-system/PKGBUILD
index d230ed2..006db84 100755
--- a/abs/core/LinHES-system/PKGBUILD
+++ b/abs/core/LinHES-system/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=LinHES-system
 pkgver=2
-pkgrel=124
+pkgrel=125
 arch=('i686' 'x86_64')
 MVDIR=$startdir/pkg/usr/LH
 BINDIR=$startdir/pkg/usr/bin
@@ -24,7 +24,7 @@ binfiles="LinHES-start optimize_mythdb.py
  cacheclean lh_backend_control.sh switch_web.sh
  create_media_dirs.sh
  msg_client.py msg_daemon.py
- gen_is_xml.py gen_lib_xml.py gen_light_include.py
+ gen_is_xml.py gen_lib_xml.py gen_light_include.py gen_game_xml.py
  misc_recent_recordings.pl
  misc_status_config.py
  misc_status_info.sh
@@ -62,6 +62,7 @@ build() {
         install -m644 -D $startdir/src/alsa-base $startdir/pkg/etc/modprobe.d/alsa-base.conf
         install -m644 -D $startdir/src/readme_is_xml $startdir/pkg/etc/gen_is_xml.d/readme_is_xml
         install -m644 -D $startdir/src/readme_is_xml $startdir/pkg/etc/gen_lib_xml.d/readme_gen_xml
+        install -m644 -D $startdir/src/readme_is_xml $startdir/pkg/etc/gen_game_xml.d/readme_gen_xml
         install -m644 -D $startdir/src/readme_light  $startdir/pkg/etc/gen_light_conf.d/readme_gen_light
         install -m644 -D $startdir/src/add_storage.readme $startdir/pkg/etc/storage.d/readme
        # install -m755 -D $startdir/src/smolt.cron $startdir/pkg/etc/cron.weekly/smolt.cron
@@ -108,6 +109,7 @@ md5sums=('06bc649bce56c22b9a1f56890e0765b6'
          'ea315f41dcd6c978e546c95fc05546cf'
          'ac61cc460d9e97ba1f5ef69e92cdfbe5'
          'f3502bb7c665750da0ecdf6918f7c838'
+         'b7febd04f64fe21e8cfbb888219b0b31'
          '06a628469051237943b7c874f2e29b8a'
          '54ebcc024db2e0ebe8121305d8926767'
          '45f46d1f9193c8dde18e56369ec29a1e'
diff --git a/abs/core/LinHES-system/gen_game_xml.py b/abs/core/LinHES-system/gen_game_xml.py
new file mode 100644
index 0000000..e5d9afe
--- /dev/null
+++ b/abs/core/LinHES-system/gen_game_xml.py
@@ -0,0 +1,117 @@
+#! /usr/bin/python2
+#Helper program that generates library.xml thats custom to linhes.
+#Contents are read from /etc/gen_game_xml.d
+#This script should be run everytime an entry is added or removed
+
+
+import os, sys
+import glob
+
+class Gen_lib_xml:
+    def __init__(self,snippit_dir,orig_theme_file):
+        self.snippit_dir = snippit_dir
+        self.orig_theme_file =  orig_theme_file
+        self.xml_snippets=[]
+        self.orig_theme_xml=[]
+        self.new_xml=[]
+
+    def get_new_xml(self):
+        return self.new_xml
+    def get_orig_xml(self):
+        return self.orig_theme_xml
+    def get_snippits(self):
+        return self.xml_snippets
+
+    def read_snippets(self):
+        xml_snippets=""
+        try:
+            os.chdir(self.snippit_dir)
+        except:
+            print "    gen_game_xml: Couldn't change dir to %s" %self.snippit_dir
+            print "    Exiting"
+            sys.exit(0)
+        file_list=glob.glob("*.conf")
+        for conf_file in file_list:
+            try:
+                print "    gen_game_xml: reading in %s" %conf_file
+                f=open(conf_file,'r')
+                lines=f.readlines()
+                f.close()
+            except:
+                print "    gen_game_xml: Couldn't open %s for reading" %conf_file
+                print "    Exiting"
+                sys.exit(0)
+
+        if len(file_list) == 0:
+            print "    gen_game_xml:  no conf files found"
+            lines = []
+        self.xml_snippets = lines
+
+    def read_orig_xml(self):
+        try:
+            print "    gen_game_xml:  reading in %s" %self.orig_theme_file
+            f=open(self.orig_theme_file,'r')
+            lines=f.readlines()
+            f.close()
+
+        except:
+            print "    gen_game_xml: Couldn't open %s for reading" %self.orig_theme_file
+            print "    Exiting"
+            sys.exit(2)
+        #print lines
+        for i in lines:
+            if i.strip() == "</mythmenu>":
+                lines.remove(i)
+                print "    gen_game_xml:  Removing /mythmenu tag "
+                break
+        self.orig_theme_xml=lines
+
+    def make_new_xml(self):
+        self.new_xml = self.orig_theme_xml + self.xml_snippets
+        self.new_xml.append("</mythmenu>\n")
+        pass
+
+
+
+
+
+
+
+
+def write_xml(xml,filename):
+    try:
+        f=open(filename, 'w')
+    except:
+        print "    gen_game_xml: Couldn't open %s" %(filename)
+        print "    Exiting"
+        sys.exit(2)
+    print "    gen_game_xml:  Writing %s" %(filename)
+    for i in xml:
+        f.write(i)
+    f.close()
+
+def main():
+    sys.path.append('/usr/MythVantage/bin/')
+    config_file = "mv_config"
+    data_config = __import__(config_file,  globals(),  locals(),  [])
+
+    filename="%s/.mythtv/game.xml" %data_config.MYTHHOME
+    #filename="/tmp/library.xml"
+    orig_theme_file="/usr/share/mythtv/themes/defaultmenu/game.xml"
+    lib_xml_dir="/etc/gen_game_xml.d/"
+
+    lib_xml = Gen_lib_xml(lib_xml_dir,orig_theme_file)
+    lib_xml.read_snippets()
+    lib_xml.read_orig_xml()
+    lib_xml.make_new_xml()
+    lib_xml.make_new_xml()
+    new_xml = lib_xml.get_new_xml()
+
+    #a = lib_xml.get_new_xml()
+    #b = lib_xml.get_orig_xml()
+    #c = lib_xml.get_snippits()
+
+    write_xml(new_xml,filename)
+
+if __name__ == "__main__":
+    main()
\ No newline at end of file
-- 
cgit v0.12