Added --archive-url, --archive-file and --archive-extract. This adds an
[0publish.git] / create.py
blobe7da80f76ca56a3052d28e5e580b70dd4c88b691
1 import os
2 from xml.dom import minidom, XMLNS_NAMESPACE
3 from zeroinstall.injector.namespaces import XMLNS_IFACE
4 from zeroinstall.injector import model, reader
6 _local_template_start = """<?xml version="1.0" ?>
7 <?xml-stylesheet type='text/xsl'
8 href='http://0install.net/2006/stylesheets/interface.xsl'?>
9 """
11 _template = """<?xml version="1.0" ?>
12 <?xml-stylesheet type='text/xsl'
13 href='http://0install.net/2006/stylesheets/interface.xsl'?>
15 <interface xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
16 <name>%s</name>
17 <summary>cures all ills</summary>
18 <description>
19 A longer, multi-line description of the behaviour of the
20 program goes here. State clearly what the program is for
21 (clearly enough that people who don't want it will
22 realise too).
24 Use a blank line to separate paragraphs.
25 </description>
27 <!-- Optionally, uncomment this to specify an icon: -->
28 <!-- <icon href='http://site/icon.png' type='image/png'/> -->
30 <!-- Optionally, uncomment this to give the address of
31 the signed master interface: -->
32 <!-- <feed-for interface='http://site/interface'/> -->
34 <!-- Set 'main' to the relative path of your default
35 executable within the implementation's directory.
36 E.g.: "myprog" or "bin/myprog" -->
37 <group main='myprog'>
38 <!-- List any libraries your program needs here -->
39 <!--
40 <requires interface="http://site/library">
41 <environment insert="python" name="PYTHONPATH"/>
42 </requires>
43 -->
45 <!-- List all implementations here.
46 For local interfaces, '.' is a relative path from this
47 interface file to the directory containing the program.
48 Usually, you can just leave it as '.'.
49 -->
50 <implementation id="." version="0.1" released='Snapshot'/>
51 </group>
52 </interface>
53 """
55 def create(f):
56 assert not os.path.exists(f)
57 name = os.path.basename(f)
58 return _template % (name.split('.', 1)[0])
60 def create_from_local(local):
61 iface = model.Interface(os.path.abspath(local))
62 reader.update(iface, local, local = True)
63 doc = minidom.parseString(_local_template_start +
64 '<interface xmlns="http://zero-install.sourceforge.net/2004/injector/interface"/>')
65 root = doc.documentElement
66 def element(uri, localName, data):
67 root.appendChild(doc.createTextNode('\n '))
68 element = doc.createElementNS(uri, localName)
69 element.appendChild(doc.createTextNode(data))
70 return element
71 root.appendChild(element(XMLNS_IFACE, 'name', iface.name))
72 root.appendChild(element(XMLNS_IFACE, 'summary', iface.summary))
73 root.appendChild(element(XMLNS_IFACE, 'description', iface.description + '\n '))
75 if not iface.feed_for:
76 raise Exception("No <feed-for> in '%s'; can't use it as a local feed." % local)
77 if len(iface.feed_for) != 1:
78 raise Exception("Multiple <feed-for> elements. Not supported, sorry!")
79 uri = iface.feed_for.keys()[0]
81 root.setAttribute('uri', uri)
83 local_doc = minidom.parse(local)
84 for icon in local_doc.getElementsByTagNameNS(XMLNS_IFACE, 'icon'):
85 if icon.parentNode is local_doc.documentElement:
86 root.appendChild(doc.createTextNode('\n '))
87 root.appendChild(doc.importNode(icon, True))
89 root.appendChild(doc.createTextNode('\n'))
91 # minidom's writer loses the newline after the PI
92 return _local_template_start + root.toxml()