root/CPS3/legacy/CPSIO/trunk/XMLIOTool.py

Revision 28989, 4.0 kB (checked in by madarche, 4 years ago)

Removed remaining import and exports broken declarations + renamed the dtml directory into zmi since ZMI pages can be written using ZPTs too and actually it is more legible in ZPT.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 # (C) Copyright 2004-2005 Nuxeo SARL <http://nuxeo.com>
2 # Author: Emmanuel Pietriga <ep@nuxeo.com>
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 2 as published
6 # by the Free Software Foundation.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
16 # 02111-1307, USA.
17 #
18 # $Id$
19 """XML-based Import/Export Tool
20 """
21
22 from zLOG import LOG, ERROR, DEBUG
23 from Globals import InitializeClass, DTMLFile
24 from AccessControl import ClassSecurityInfo
25
26 from Products.CMFCore.utils import UniqueObject
27 try:
28     from Products.CMFCore.permissions import ManagePortal
29 except ImportError: # CPS <= 3.2
30     from Products.CMFCore.CMFCorePermissions import ManagePortal
31 from OFS.Folder import Folder
32
33 from types import ModuleType
34 import sys
35
36 class XMLIOTool(UniqueObject, Folder):
37
38     id = 'portal_io'
39     meta_type = 'CPS IO Tool'
40
41     security = ClassSecurityInfo()
42
43     manage_options = (
44         {'label': "Overview",
45          'action': 'overview_page'
46          },
47         ) + Folder.manage_options[2:]
48
49     security.declareProtected(ManagePortal, 'overview_page')
50     overview_page = DTMLFile('zmi/overview', globals())
51
52     #
53     # Import/export modules management
54     #
55
56     def listImportModules(self):
57         return self._listPluginNames('import_modules')
58
59     def listExportModules(self):
60         return self._listPluginNames('export_modules')
61
62     def _listPluginNames(self, package_name):
63         return [ plugin.__name__.split(".")[-1]
64                  for plugin in self._listPlugins(package_name) ]
65
66     def _listPlugins(self, package_name):
67         dotted_name = "Products.CPSIO." + package_name
68         products = __import__(dotted_name)
69         package = sys.modules[dotted_name]
70         plugin_list = []
71         for name in dir(package):
72             obj = getattr(package, name)
73             if type(obj) == ModuleType:
74                 plugin_list.append(obj)
75         return plugin_list
76
77     def getImportPluginTemplate(self, plugin_name):
78         dotted_name = "Products.CPSIO.import_modules.%s" % plugin_name
79         products = __import__(dotted_name)
80         options_template = sys.modules[dotted_name].Importer.options_template
81         if options_template:
82             return options_template
83         else:
84             return "default_importer_form"
85
86     def getImportOptionsTable(self, plugin_name):
87         dotted_name = "Products.CPSIO.import_modules.%s" % plugin_name
88         products = __import__(dotted_name)
89         options_table = sys.modules[dotted_name].Importer.options_table
90         return options_table
91
92     def getExportPluginTemplate(self, plugin_name):
93         dotted_name = "Products.CPSIO.export_modules.%s" % plugin_name
94         products = __import__(dotted_name)
95         options_template = sys.modules[dotted_name].Exporter.options_template
96         if options_template:
97             return options_template
98         else:
99             return "default_exporter_form"
100
101     def getExportOptionsTable(self, plugin_name):
102         dotted_name = "Products.CPSIO.export_modules.%s" % plugin_name
103         products = __import__(dotted_name)
104         options_table = sys.modules[dotted_name].Exporter.options_table
105         return options_table
106
107     def getImportPlugin(self, plugin_name, portal):
108         dotted_name = "Products.CPSIO.import_modules.%s" % plugin_name
109         products = __import__(dotted_name)
110         return sys.modules[dotted_name].Importer(portal).__of__(portal)
111
112     def getExportPlugin(self, plugin_name, portal):
113         dotted_name = "Products.CPSIO.export_modules.%s" % plugin_name
114         products = __import__(dotted_name)
115         return sys.modules[dotted_name].Exporter(portal).__of__(portal)
116
117 InitializeClass(XMLIOTool)
118
Note: See TracBrowser for help on using the browser.