1 from xml
.dom
import Node
, minidom
3 import rox
, os
, pango
, sys
, textwrap
, traceback
, subprocess
, time
, urlparse
4 from rox
import g
, tasks
, loading
10 from zeroinstall
.injector
import model
11 from zeroinstall
.zerostore
import unpack
, NotStored
13 RESPONSE_SAVE_AND_TEST
= 1
15 class ImplementationProperties
:
16 def __init__(self
, feed_editor
, element
= None, is_group
= False):
17 self
.feed_editor
= feed_editor
18 self
.element
= element
20 widgets
= gtk
.glade
.XML(main
.gladefile
, 'version')
22 #attributes = g.ListStore(str, str)
23 #attr_view = widgets.get_widget('attributes')
24 #attr_view.set_model(attributes)
26 #attr_view.append_column(g.TreeViewColumn('Name'))
27 #attr_view.append_column(g.TreeViewColumn('Value'))
29 inherit_arch
= widgets
.get_widget('inherit_arch')
31 s
= not inherit_arch
.get_active()
32 widgets
.get_widget('cpu').set_sensitive(s
)
33 widgets
.get_widget('os').set_sensitive(s
)
35 cpu
= widgets
.get_widget('cpu').get_active_text()
39 parent
= element
.parentNode
40 while parent
.nodeType
== Node
.ELEMENT_NODE
and not cpu
:
41 arch
= parent
.getAttribute('arch')
42 if arch
and '-' in arch
:
43 cpu
= arch
.split('-')[1]
44 parent
= parent
.parentNode
47 widgets
.get_widget('source_frame').show()
49 widgets
.get_widget('source_frame').hide()
50 command
= widgets
.get_widget('compile_command')
51 if command
.get_text() == '':
52 command
.set_text('"$SRCDIR/configure" --prefix="$DISTDIR" && make install')
53 inherit_arch
.connect('toggled', lambda cb
: shade_os_cpu())
54 widgets
.get_widget('cpu').connect('changed', lambda cb
: shade_os_cpu())
56 main_menu
= widgets
.get_widget('main_binary')
57 doc_menu
= widgets
.get_widget('doc_dir')
60 if element
.localName
== 'group':
64 id = element
.getAttribute('id')
66 version
= element
.getAttribute('version') + \
67 (element
.getAttribute('version-modifier') or '')
68 widgets
.get_widget('version_number').set_text(version
)
69 widgets
.get_widget('released').set_text(element
.getAttribute('released'))
71 widgets
.get_widget('compile_command').set_text(element
.getAttributeNS(XMLNS_COMPILE
, 'command'))
72 widgets
.get_widget('compile_binary_main').set_text(element
.getAttributeNS(XMLNS_COMPILE
, 'binary-main'))
73 widgets
.get_widget('compile_binary_lib_mappings').set_text(element
.getAttributeNS(XMLNS_COMPILE
, 'binary-lib-mappings'))
75 main_binary
= element
.getAttribute('main')
76 doc_dir
= element
.getAttribute('doc-dir')
78 stability_menu
= widgets
.get_widget('stability')
79 stability
= element
.getAttribute('stability')
82 for row
in stability_menu
.get_model():
83 if row
[0].lower() == stability
:
84 stability_menu
.set_active(i
)
88 stability_menu
.set_active(0)
90 main
.combo_set_text(widgets
.get_widget('license'), element
.getAttribute('license'))
91 arch
= element
.getAttribute('arch')
93 arch_os
, arch_cpu
= arch
.split('-')
94 main
.combo_set_text(widgets
.get_widget('os'), arch_os
)
95 main
.combo_set_text(widgets
.get_widget('cpu'), arch_cpu
)
96 inherit_arch
.set_active(False)
98 widgets
.get_widget('os').set_active(0)
99 widgets
.get_widget('cpu').set_active(0)
102 self
.update_impl(element
, widgets
)
104 released
= widgets
.get_widget('released')
108 widgets
.get_widget('version_number').set_text('')
109 released
.set_text('')
111 widgets
.get_widget('version_number').set_text('1.0')
112 released
.set_text(time
.strftime('%Y-%m-%d'))
114 widgets
.get_widget('cpu').set_active(0)
115 widgets
.get_widget('os').set_active(0)
116 widgets
.get_widget('stability').set_active(0)
122 element_name
= 'group'
124 element_name
= 'implementation'
125 element
= create_element(self
.feed_editor
.doc
.documentElement
, element_name
)
127 element
.setAttribute('id', '.')
129 self
.update_impl(element
, widgets
)
131 remove_element(element
)
136 self
.is_group
= is_group
138 id_label
= widgets
.get_widget('id_label')
141 id_label
.set_text('(group)')
143 id_label
.set_text(id)
144 if id.startswith('.') or id.startswith('/'):
145 id_label
.set_sensitive(True)
147 id_label
.set_text('-')
150 if r
in (g
.RESPONSE_OK
, RESPONSE_SAVE_AND_TEST
):
152 self
.feed_editor
.update_version_model()
153 if r
== RESPONSE_SAVE_AND_TEST
:
154 is_src
= bool(widgets
.get_widget('source_frame').flags() & gtk
.VISIBLE
)
155 self
.feed_editor
.save(lambda: self
.test(element
, is_src
))
159 if is_group
and element
:
160 # Find a cached implementation for getting main
161 for x
in child_elements(element
):
162 if x
.localName
== 'implementation' and x
.namespaceURI
== XMLNS_INTERFACE
:
163 id = x
.getAttribute('id')
165 if id and (id.startswith('.') or id.startswith('/') or main
.stores
.lookup(id)):
167 except NotStored
, ex
:
169 if id and (element
or id != '.'):
170 # Find possible main settings, if possible
171 if id.startswith('/') or id.startswith('.'):
172 cached_impl
= os
.path
.abspath(os
.path
.join(os
.path
.dirname(feed_editor
.pathname
), id))
175 cached_impl
= main
.stores
.lookup(id)
176 except NotStored
, ex
:
179 for (dirpath
, dirnames
, filenames
) in os
.walk(cached_impl
):
180 relbasedir
= dirpath
[len(cached_impl
) + 1:]
181 for file in filenames
:
182 info
= os
.lstat(os
.path
.join(dirpath
, file))
183 if info
.st_mode
& 0111:
184 new
= os
.path
.join(relbasedir
, file)
185 main_menu
.append_text(new
)
186 for d
in dirnames
[:]:
187 if d
.startswith('.'):
190 doc_menu
.append_text(os
.path
.join(relbasedir
, d
))
191 main
.combo_set_text(main_menu
, main_binary
)
192 main
.combo_set_text(doc_menu
, doc_dir
)
194 dialog
= widgets
.get_widget('version')
195 dialog
.connect('response', resp
)
197 def update_impl(self
, element
, widgets
):
198 version
= widgets
.get_widget('version_number').get_text()
199 released
= widgets
.get_widget('released').get_text()
200 inherit_arch
= widgets
.get_widget('inherit_arch')
203 widget
= widgets
.get_widget(name
)
204 return widget
.get_active_text()
206 cpu
= get_combo('cpu')
208 license
= get_combo('license')
210 widget
= widgets
.get_widget('stability')
211 if widget
.get_active() == 0:
214 stability
= get_combo('stability').lower()
216 if inherit_arch
.get_active():
219 arch
= os
+ '-' + cpu
221 main
= widgets
.get_widget('main_binary').get_active_text()
222 docs
= widgets
.get_widget('doc_dir').get_active_text()
224 old_id
= element
.getAttribute('id')
225 if old_id
.startswith('/') or old_id
.startswith('.'):
226 # Local paths are editable
227 new_id
= widgets
.get_widget('id_label').get_text()
228 if new_id
.startswith('.') or new_id
.startswith('/'):
229 element
.setAttribute('id', new_id
)
231 raise Exception('Local IDs must start with "." or "/"')
233 version_modifier
= None
235 model
.parse_version(version
)
237 version
, version_modifier
= version
.split('-', 1)
238 version_modifier
= '-' + version_modifier
240 for name
, value
in [('version', version
),
241 ('version-modifier', version_modifier
),
245 ('released', released
),
246 ('license', license
),
247 ('stability', stability
)]:
249 element
.setAttribute(name
, value
)
250 elif element
.hasAttribute(name
):
251 element
.removeAttribute(name
)
254 if widgets
.get_widget('source_frame').flags() & gtk
.VISIBLE
:
255 compile_command
= widgets
.get_widget('compile_command').get_text()
256 compile_binary_main
= widgets
.get_widget('compile_binary_main').get_text()
257 compile_binary_lib_mappings
= widgets
.get_widget('compile_binary_lib_mappings').get_text()
258 self
.feed_editor
.doc
.documentElement
.setAttribute('xmlns:compile', XMLNS_COMPILE
)
260 compile_command
= compile_binary_main
= compile_binary_lib_mappings
= None
262 for name
, value
in [('command', compile_command
),
263 ('binary-main', compile_binary_main
),
264 ('binary-lib-mappings', compile_binary_lib_mappings
)]:
266 element
.setAttributeNS(XMLNS_COMPILE
, 'compile:' + name
, value
)
267 elif element
.hasAttributeNS(XMLNS_COMPILE
, name
):
268 element
.removeAttributeNS(XMLNS_COMPILE
, name
)
270 def test(self
, element
, compile):
273 if element
.hasAttribute('version'):
274 version
= element
.getAttribute('version')
276 element
= element
.parentNode
277 if element
.namespaceURI
!= XMLNS_INTERFACE
:
279 if element
.localName
!= 'group':
283 # TODO: 0compile doesn't allow setting the version
284 self
.feed_editor
.test_compile([])
287 args
= ['--not-before', version
, '--before', version
+ '-0-pre9999']
290 self
.feed_editor
.test(args
)