1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import qm.xmlutil
21 from distutils.command.install_lib import install_lib
22 import os, dircache, xml
23
24
25
26
27
29 """Compare the content of two files.
30
31 'a' -- Filename of first file to be compared.
32
33 'b' -- Filename of second file to be compared.
34
35 returns -- True if both files have the same content, False otherwise."""
36
37 file_a, file_b = open(a, 'r'), open(b, 'r')
38 for line in file_a:
39 if line != file_b.readline():
40 return False
41 if file_b.readline():
42 return False
43 return True
44
45
47 """Install extension files."""
48
49 description = "install qmtest extension classes."
50
51
64
65
67
68
69 self.run_command('build_extensions')
70
71 if not os.path.isdir(self.install_dir):
72 self.mkpath(self.install_dir)
73 if not os.path.exists(os.path.join(self.install_dir, 'classes.qmc')):
74
75 self.copy_tree(self.build_dir, self.install_dir)
76 else:
77
78 old_files = [f for f in dircache.listdir(self.install_dir)
79 if f.endswith('.py')]
80 new_files = [f for f in dircache.listdir(self.build_dir)
81 if f.endswith('.py') and f != '__init__.py']
82 overlap = []
83 for f in new_files:
84 if f in old_files:
85
86 if not _compare_files(os.path.join(self.build_dir, f),
87 os.path.join(self.install_dir, f)):
88 overlap.append(f)
89 if overlap:
90 print "Error: The following extension files already exist:"
91 for o in overlap:
92 print " %s"%o
93 return
94
95 for f in new_files:
96 self.copy_file(os.path.join(self.build_dir, f),
97 os.path.join(self.install_dir, f),
98 preserve_mode=0)
99
100
101 old_qmc = qm.xmlutil.load_xml_file(os.path.join(self.install_dir,
102 'classes.qmc'))
103 old_root = old_qmc.documentElement
104
105 new_qmc = qm.xmlutil.load_xml_file(os.path.join(self.build_dir,
106 'classes.qmc'))
107 new_root = new_qmc.documentElement
108
109 for ext in new_root.getElementsByTagName("class"):
110
111 name = ext.getAttribute("name")
112 entries = [c for c in old_root.childNodes
113 if c.nodeType == xml.dom.Node.ELEMENT_NODE and
114 c.tagName == "class" and
115 c.getAttribute("name") == name]
116 if not entries:
117 old_root.appendChild(ext)
118 old_root.appendChild(old_qmc.createTextNode('\n'))
119
120 old_qmc.writexml(open(os.path.join(self.install_dir,
121 'tmp-classes.qmc'), 'w'))
122
123 os.rename(os.path.join(self.install_dir, 'tmp-classes.qmc'),
124 os.path.join(self.install_dir, 'classes.qmc'))
125