source: main/trunk/model-sites-dev/twso/PreProcessing/metadatacreator.py@ 34227

Last change on this file since 34227 was 34227, checked in by kjdon, 4 years ago

the processing files to help you generate metadata.xml files for the programmes

File size: 2.2 KB
Line 
1import sys
2import os
3
4global fn
5
6#If not all the arguments are entered throw an error
7if len(sys.argv) != 3:
8 print "ERROR: You must enter 'python metadatacreator.py <name_list.txt> <addtoprogramme>"
9
10#Otherwise initialise the variables
11else:
12 #the name of the file to process
13 namelistfile = sys.argv[1]
14 #the name of the file which the metadata will be added to
15 programmename = sys.argv[2]
16
17 #splitting the name to create the metadata.xml name
18 #start = namelistfile.split(".")
19 #start2 = namelistfile.split("_")
20 #filename = start2[0] + "metadata.xml"
21 filename = programmename + "-metadata.xml"
22 #if the file exists get that file or create a new one
23 if os.path.exists(filename):
24 fn = file(filename, "r+")
25 else:
26 fn = file(filename, "w+")
27
28#This method is called to create the file
29def create(filename):
30
31 fn.write("<DirectoryMetadata>\n")
32
33 #add the names of the metadata
34 addNames(namelistfile)
35
36 fn.write("</DirectoryMetadata>\n")
37
38 fn.close()
39
40def addStart():
41 #This must be included at the start of the xml file for it to be valid
42 global fn
43 fn.write("<FileSet>\n")
44 fn.write("<FileName>" + programmename.strip() + "\.pdf</FileName>\n")
45 fn.write("<Description>\n")
46
47def addEnd():
48 #This must be included at the end of the xml file for it to be vaild
49 global fn
50 fn.write("</Description>\n")
51 fn.write("</FileSet>\n")
52
53#This method is used to get the name from a "conductor Buchanan-Smart, Andrew" line
54#ie it removes the conductor part
55def printName(temp):
56
57 i = 1
58 name = ""
59 while i < len(temp):
60 name += temp[i] + " "
61 i +=1
62
63 return name.strip()
64
65
66#This method adds the names to the file in the appropriate line.
67def addNames(namelistfile):
68
69 f = open(namelistfile)
70 lines = f.readlines()
71 f.close()
72
73 addStart()
74 for line in lines:
75 temp = line.split()
76 if temp[0] == "soloist":
77 fn.write("<Metadata mode='accumulate' name='pd.Soloist'>" + printName(temp) + "</Metadata>\n")
78 elif temp[0] == "conductor":
79 fn.write("<Metadata mode='accumulate' name='pd.Conductor'>" + printName(temp) + "</Metadata>\n")
80 else:
81 fn.write("<Metadata mode='accumulate' name='pd.Player'>" + line.strip() + "</Metadata>\n")
82 addEnd()
83
84#intial call to start the program
85create(filename)
86
87
Note: See TracBrowser for help on using the repository browser.