1 | import string |
---|
2 | from StringIO import StringIO |
---|
3 | from zLOG import LOG, INFO |
---|
4 | from Products.CMFCore.utils import getToolByName |
---|
5 | from Products.%(SKIN_PRODUCT_NAME)s.config import * |
---|
6 | from Products.%(SKIN_PRODUCT_NAME)s.Extensions.utils import * |
---|
7 | |
---|
8 | CHECKED_MESSAGE = "The base installation checkings completed." |
---|
9 | |
---|
10 | def prepareInstallation(portal, pp, product, out): |
---|
11 | checkSuccessInstall(product) |
---|
12 | uninstallOtherSkinProducts(portal) |
---|
13 | if not ('uninstall_properties' in pp.objectIds()) : |
---|
14 | pp.addPropertySheet(id='uninstall_properties', title= 'uninstall_properties') |
---|
15 | print >> out, "Created 'portal_properties.uninstall_properties' PropertySheet (UP) for backup purpose" |
---|
16 | |
---|
17 | def checkSuccessInstall(product): |
---|
18 | # Check for successfully completed 1 installation step |
---|
19 | transcript = getattr(product,'transcript',None) |
---|
20 | if transcript: |
---|
21 | msg = str(transcript[0]['msg']) |
---|
22 | if msg.find(CHECKED_MESSAGE) < 0 : |
---|
23 | product.log("First part installation procedure not completed - installation terminated.") |
---|
24 | raise |
---|
25 | |
---|
26 | def uninstallOtherSkinProducts(portal): |
---|
27 | qi=getToolByName(portal, 'portal_quickinstaller', None) |
---|
28 | if not qi: |
---|
29 | raise Exception("Can't work without QuickInstaller tool.") |
---|
30 | # Get installed products |
---|
31 | installed_products = [getattr(qi, p_dict['id']) \ |
---|
32 | for p_dict in qi.listInstalledProducts() |
---|
33 | if p_dict['id'] != PRODUCT_NAME] |
---|
34 | seek_str = "%%s generated product" %% GENERATOR_PRODUCT |
---|
35 | installed_skin_products = [] |
---|
36 | # Looking for installed skin-products |
---|
37 | for p in installed_products: |
---|
38 | transcript = p.getTranscriptAsText() |
---|
39 | if transcript.find(seek_str) >= 0 : |
---|
40 | installed_skin_products.append(p.getId()) |
---|
41 | # Uninstall found skin-products |
---|
42 | if installed_skin_products: |
---|
43 | qi.uninstallProducts(products=installed_skin_products) |
---|
44 | |
---|
45 | def install(self): |
---|
46 | # Checking base condition for installation |
---|
47 | skinsTool = getToolByName(self, 'portal_skins') |
---|
48 | # Checking for BASE_SKIN_NAME presenting in portal |
---|
49 | skin_names = skinsTool.getSkinSelections() |
---|
50 | if not BASE_SKIN_NAME in skin_names: |
---|
51 | raise AttributeError("Impossible installation without %%s skin." %% BASE_SKIN_NAME) |
---|
52 | # Checking for presenting lower_SKIN_NAME directory in portal skins |
---|
53 | lower_SKIN_NAME = string.lower(SKIN_NAME) |
---|
54 | if lower_SKIN_NAME in skinsTool.objectIds(): |
---|
55 | raise AttributeError("%%s skin layer already exist in portal skins. Installation Impossible." %% lower_SKIN_NAME) |
---|
56 | return CHECKED_MESSAGE |
---|
57 | |
---|
58 | # For prevent quickInstaller's intervention in uninstall process - use afterInstall |
---|
59 | def afterInstall(self,product,reinstall): |
---|
60 | out=StringIO() |
---|
61 | # get all needed tools and some portal's core objects |
---|
62 | portal = getToolByName(self, 'portal_url').getPortalObject() |
---|
63 | pp = getToolByName(portal, 'portal_properties') |
---|
64 | portal_css = getToolByName(portal, 'portal_css', None) |
---|
65 | portal_js = getToolByName(portal, 'portal_javascripts', None) |
---|
66 | # Make main prepare procedures |
---|
67 | prepareInstallation(portal, pp, product, out) |
---|
68 | pp_up = pp.uninstall_properties |
---|
69 | # Install skin |
---|
70 | installSkin(portal, pp_up, out) |
---|
71 | # Register css resources |
---|
72 | if portal_css and DOES_COSTOMIZE_CSS: |
---|
73 | registerResource(pp_up, portal_css, portal_css.registerStylesheet, out \ |
---|
74 | ,CSS_LIST, SKIN_CSS_REGDATA, 'q_registered_css', CSS_REG_PROPS) |
---|
75 | print >> out, "Completed tuning CSS registry for new skin needs." |
---|
76 | # Register js resources |
---|
77 | if portal_js and DOES_COSTOMIZE_JS: |
---|
78 | registerResource(pp_up, portal_js, portal_js.registerScript, out \ |
---|
79 | ,JS_LIST, SKIN_JS_REGDATA, 'q_registered_js', JS_REG_PROPS)#---installJS--- |
---|
80 | print >> out, "Completed tuning JS registry for new skin needs." |
---|
81 | # Customize slots |
---|
82 | if LEFT_SLOTS or RIGHT_SLOTS: |
---|
83 | customizeSlots(portal, pp_up, out) |
---|
84 | # Import object(s) to portal |
---|
85 | if checkIfImport(): |
---|
86 | res_import = performImportToPortal(portal) |
---|
87 | print >> out, res_import |
---|
88 | # FINAL customization call additional functions from config |
---|
89 | if FINAL_CUSTOMIZATION_FUNCTIONS: |
---|
90 | dummy = [func(portal, out) for func in FINAL_CUSTOMIZATION_FUNCTIONS] |
---|
91 | print >> out, "%%s generated product." %% GENERATOR_PRODUCT |
---|
92 | print >> out, '=== Installation successfully completed. ===' |
---|
93 | product.log(out.getvalue()) |
---|
94 | product._p_changed = 1 #XXX:NEED for stable writing 'out' log to qi on afterinstallation. |
---|
95 | return out.getvalue() |
---|
96 | |
---|
97 | def uninstall(self): |
---|
98 | # get all needed tools and some portal's core objects |
---|
99 | portal = self.portal_url.getPortalObject() |
---|
100 | skinsTool = getToolByName(portal, 'portal_skins') |
---|
101 | pp = getToolByName(portal, 'portal_properties') |
---|
102 | portal_css = getToolByName(portal, 'portal_css', None) |
---|
103 | portal_js = getToolByName(portal, 'portal_javascripts', None) |
---|
104 | # Get all properies, saving during installation, for uninstalling |
---|
105 | actual_skin_name = getProperty(pp, 'uninstall_properties', 'q_actual_skin_name',default=SKIN_NAME) |
---|
106 | initial_skin = getProperty(pp, 'uninstall_properties', 'q_default_skin',default="") |
---|
107 | original_css_list = getProperty(pp, 'uninstall_properties', 'q_registered_css') |
---|
108 | original_js_list = getProperty(pp, 'uninstall_properties', 'q_registered_js') |
---|
109 | orig_left_slots = getProperty(pp, 'uninstall_properties','q_left_slots') |
---|
110 | orig_right_slots = getProperty(pp, 'uninstall_properties','q_right_slots') |
---|
111 | # Remove 'uninstall_properties' from portal_properties |
---|
112 | if 'uninstall_properties' in pp.objectIds() : |
---|
113 | pp.manage_delObjects(ids=['uninstall_properties',]) |
---|
114 | # Uninstall skin |
---|
115 | uninstallSkin(skinsTool, actual_skin_name, initial_skin) |
---|
116 | # Unregister skin's CSS-es from portal_css. Only for Plone 2.1+ |
---|
117 | if portal_css and DOES_COSTOMIZE_CSS: |
---|
118 | uninstallResource(portal_css, original_css_list, CSS_LIST, portal_css.registerStylesheet) |
---|
119 | # Unregister skin's JS-s from portal_javascripts. Only for Plone 2.1+ |
---|
120 | if portal_js and DOES_COSTOMIZE_JS: |
---|
121 | uninstallResource(portal_js, original_js_list, JS_LIST, portal_js.registerScript) |
---|
122 | # Return site's column slots list unless Skin product installation |
---|
123 | if orig_left_slots: |
---|
124 | portal.left_slots = tuple(orig_left_slots) |
---|
125 | if orig_right_slots: |
---|
126 | portal.right_slots = tuple(orig_right_slots) |
---|