fe09642bde47a88044daa28e993beecc6acd0406
[enigma2.git] / lib / python / Plugins / Extensions / DVDBurn / DVDProject.py
1 from Tools.Directories import fileExists
2
3 class DVDProject:
4         def __init__(self):
5                 self.titles = [ ]
6                 self.target = None
7
8         def addService(self, service):
9                 import DVDTitle
10                 title = DVDTitle.DVDTitle()
11                 title.addService(service)
12                 self.titles.append(title)
13                 return title
14
15         def saveProject(self, path):
16                 import xml.dom.minidom
17                 from Tools.XMLTools import elementsWithTag, mergeText, stringToXML
18                 list = []
19                 list.append('<?xml version="1.0" encoding="utf-8" ?>\n')
20                 list.append('<DreamDVDBurnerProject>\n')
21                 list.append('\t<project')
22                 list.append(' name="' + self.name + '"')
23                 list.append(' vmgm="' + self.vmgm + '"')
24                 list.append(' />\n')
25                 list.append('\t<menu')
26                 list.append('\tuse="' + str(self.menu) + '"\n')
27                 list.append('\tbg="' + self.menubg + '"\n')
28                 list.append('\t\taudio="' + self.menuaudio + '"\n')
29                 list.append('\t\tcolor_button="' + str(self.color_button) + '"\n')
30                 list.append('\t\tcolor_highlight="' + str(self.color_highlight) + '"\n')
31                 list.append('\t\tcolor_headline="' + str(self.color_headline) + '"\n')
32                 list.append('\t\tfont_face="' + self.font_face + '"\n')
33                 list.append('\t\tfont_size="' + str(self.font_size) + '"\n')
34                 list.append('\t\tspace_left="' + str(self.space_left) + '"\n')
35                 list.append('\t\tspace_top="' + str(self.space_top) + '"\n')
36                 list.append('\t\tspace_rows="' + str(self.space_rows) + '"')
37                 list.append(' />\n')
38                 list.append('\t<titles')
39                 list.append(' link="' + str(self.linktitles) + '"')
40                 list.append(' />\n')
41                 for title in self.titles:
42                         list.append('\t\t<path>')
43                         list.append(stringToXML(title.source.getPath()))
44                         list.append('</path>\n')
45                 list.append('\t</titles>\n')
46                 list.append('</DreamDVDBurnerProject>\n')
47
48                 i = 0
49                 filename = path + "/" + self.name + ".ddvdp.xml"
50                 while fileExists(filename):
51                         i = i+1
52                         filename = path + "/" + self.name + str(i).zfill(3) + ".ddvdp.xml"
53                                 
54                 file = open(filename, "w")
55                 for x in list:
56                         file.write(x)
57                 file.close()
58
59         def loadProject(self, filename):
60                 import xml.dom.minidom
61                 print "[loadProject]", filename
62                 try:
63                   if not fileExists(filename):
64                         self.error = "file not found!"
65                         raise AttributeError
66                   else:
67                         self.error = ""
68                   file = open(filename, "r")
69                   data = file.read().decode("utf-8").replace('&',"&amp;").encode("ascii",'xmlcharrefreplace')
70                   file.close()
71                   projectfiledom = xml.dom.minidom.parseString(data)
72                   for project in projectfiledom.childNodes[0].childNodes:
73                     if project.nodeType == xml.dom.minidom.Element.nodeType:
74                       if project.tagName == 'project':
75                         self.name = project.getAttribute("name").encode("utf-8")
76                         self.vmgm = project.getAttribute("vmgm").encode("utf-8")
77                       if project.tagName == 'menu':
78                         self.menu = eval(project.getAttribute("use"))
79                         self.menubg = project.getAttribute("bg").encode("utf-8")
80                         self.menuaudio = project.getAttribute("audio").encode("utf-8")  
81                         # tuples with R, G, B values
82                         self.color_button = eval(project.getAttribute("color_button"))
83                         self.color_highlight = eval(project.getAttribute("color_highlight"))
84                         self.color_headline = eval(project.getAttribute("color_headline"))
85                         self.font_face = project.getAttribute("font_face").encode("utf-8")
86                         # tuple with three pixel sizes ( headline, title, subtitle )
87                         self.font_size = eval(project.getAttribute("font_size"))
88                         # please supply even numbers for all dimensions
89                         self.space_left = int(project.getAttribute("space_left"))
90                         self.space_top = int(project.getAttribute("space_top"))
91                         self.space_rows = int(project.getAttribute("space_rows"))
92                       if project.tagName == 'titles':
93                         self.linktitles = eval(project.getAttribute("link"))
94                   if not fileExists(self.vmgm):
95                         self.error += "\nvmgm '%s' not found" % self.vmgm
96                   if not fileExists(self.menubg):
97                         self.error += "\nmenu background '%s' not found" % self.menubg
98                   if not fileExists(self.menuaudio):
99                         self.error += "\nmenu audio '%s' not found" % self.menuaudio
100                   if not fileExists(self.font_face):
101                         self.error += "\nmenu font '%s' not found" % self.font_face
102                   print "len(self.error):", len(self.error)
103                   if len(self.error):
104                         raise AttributeError
105                 except:
106                         print "len(self.error):, error", len(self.error), len(self.error)
107                         self.error = ("error parsing project xml file '%s'" % filename) + self.error
108                         return False
109                 return True