When creating a launcher for ourselves, behave slightly differently.
[AddApp.git] / launcher.py
blob96032b779ab7e430932ead2d6ab72f4b2ee240ce
1 import os, shutil
2 from rox import saving
3 from xml.dom import minidom
5 class AppLauncher(saving.Saveable):
6 def __init__(self, uri, icon):
7 self.uri = uri
8 self.icon = icon
10 def save_to_file(self, path):
11 os.mkdir(path)
12 assert "'" not in self.uri
13 apprun = os.fdopen(os.open(os.path.join(path, 'AppRun'), os.O_CREAT | os.O_WRONLY, 0777), 'w')
14 if self.uri == 'http://rox.sourceforge.net/2005/interfaces/AddApp':
15 # Funky special case: AddApp behaves differently when run through AppRun
16 apprun.write("""#!/bin/sh
17 if [ "$*" = "--versions" ]; then
18 exec 0launch -gd '%s' "$@"
19 elif [ "$*" = "" ]; then
20 exec 0launch '%s' --prompt
21 else
22 exec 0launch '%s' "$@"
23 fi""" % (self.uri, self.uri, self.uri))
24 else:
25 apprun.write("""#!/bin/sh
26 if [ "$*" = "--versions" ]; then
27 exec 0launch -gd '%s' "$@"
28 else
29 exec 0launch '%s' "$@"
30 fi""" % (self.uri, self.uri))
32 apprun.close()
33 if self.icon:
34 shutil.copyfile(self.icon.name, os.path.join(path, '.DirIcon'))
36 doc = minidom.parseString("""<?xml version="1.0"?>
37 <AppInfo>
38 <AppMenu>
39 <Item option='--versions'>
40 <Label xml:lang="en">Versions...</Label>
41 </Item>
42 </AppMenu>
43 </AppInfo>
44 """)
45 info_file = file(os.path.join(path, 'AppInfo.xml'), 'w')
46 doc.writexml(info_file)
47 info_file.close()