Added env-PATH and more mimetypes to cloudooo.conf.in
[slapos.git] / slapos / recipe / cloudooo / __init__.py
1 ##############################################################################
2 #
3 # Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
4 #
5 # WARNING: This program as such is intended to be used by professional
6 # programmers who take the whole responsibility of assessing all potential
7 # consequences resulting from its eventual inadequacies and bugs
8 # End users who are looking for a ready-to-use solution with commercial
9 # guarantees and support are strongly adviced to contract a Free Software
10 # Service Company
11 #
12 # This program is Free Software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 3
15 # of the License, or (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #
26 ##############################################################################
27 from slapos.lib.recipe.BaseSlapRecipe import BaseSlapRecipe
28 import os
29 import pkg_resources
30 import sys
31 import zc.buildout
32 import zc.recipe.egg
33
34 class Recipe(BaseSlapRecipe):
35 def getTemplateFilename(self, template_name):
36 return pkg_resources.resource_filename(__name__,
37 'template/%s' % template_name)
38
39 def _install(self):
40 self.path_list = []
41 self.requirements, self.ws = self.egg.working_set([__name__])
42 # Use killpidfromfile from ERP5.
43 self.killpidfromfile = zc.buildout.easy_install.scripts(
44 [('killpidfromfile', __name__ + 'slapos.recipe.erp5.killpidfromfile',
45 'killpidfromfile')], self.ws, sys.executable, self.bin_directory)[0]
46 self.path_list.append(self.killpidfromfile)
47 conversion_server_conf = self.installConversionServer(
48 self.getLocalIPv4Address(), 23000, 23060)
49
50 self.linkBinary()
51 self.setConnectionDict(dict(
52 site_url="http://%s:%s/" % (self.getLocalIPv4Address(), 23000),
53 ))
54 return self.path_list
55
56 def linkBinary(self):
57 """Links binaries to instance's bin directory for easier exposal"""
58 for linkline in self.options.get('link_binary_list', '').splitlines():
59 if not linkline:
60 continue
61 target = linkline.split()
62 if len(target) == 1:
63 target = target[0]
64 path, linkname = os.path.split(target)
65 else:
66 linkname = target[1]
67 target = target[0]
68 link = os.path.join(self.bin_directory, linkname)
69 if os.path.lexists(link):
70 if not os.path.islink(link):
71 raise zc.buildout.UserError(
72 'Target link already %r exists but it is not link' % link)
73 os.unlink(link)
74 os.symlink(target, link)
75 self.logger.debug('Created link %r -> %r' % (link, target))
76 self.path_list.append(link)
77
78 def installConversionServer(self, ip, port, openoffice_port):
79 name = 'conversion_server'
80 working_directory = self.createDataDirectory(name)
81 conversion_server_dict = dict(
82 working_path=working_directory,
83 uno_path=self.options['ooo_uno_path'],
84 office_binary_path=self.options['ooo_binary_path'],
85 ip=ip,
86 port=port,
87 openoffice_port=openoffice_port,
88 )
89 for env_line in self.options['environment'].splitlines():
90 env_line = env_line.strip()
91 if not env_line:
92 continue
93 if '=' in env_line:
94 env_key, env_value = env_line.split('=')
95 conversion_server_dict[env_key.strip()] = env_value.strip()
96 else:
97 raise zc.buildout.UserError('Line %r in environment parameter is '
98 'incorrect' % env_line)
99 config_file = self.createConfigurationFile(name + '.cfg',
100 self.substituteTemplate(self.getTemplateFilename('cloudooo.cfg.in'),
101 conversion_server_dict))
102 self.path_list.append(config_file)
103 # Use execute from erp5.
104 self.path_list.extend(zc.buildout.easy_install.scripts([(name,
105 __name__ + 'slapos.recipe.librecipe.execute',
106 'execute_with_signal_translation')], self.ws,
107 sys.executable, self.wrapper_directory,
108 arguments=[self.options['ooo_paster'].strip(), 'serve', config_file]))
109 return {
110 name + '_port': conversion_server_dict['port'],
111 name + '_ip': conversion_server_dict['ip']
112 }