Robot Framework Integrated Development Environment (RIDE)
specimporter.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 import os
17 import shutil
18 import wx
19 
20 from .. import context
21 from ..action import ActionInfo
22 from ..pluginapi import Plugin
23 from ..publish import PUBLISHER, RideExecuteSpecXmlImport
24 from .xmlreaders import get_name_from_xml
25 
26 
28 
29  HEADER = 'Import Library Spec XML'
30 
31  def enable(self):
32  self.register_actionregister_action(ActionInfo('Tools', self.HEADERHEADER,
33  self.execute_spec_importexecute_spec_import, position=83))
34  PUBLISHER.subscribe(self._ps_on_execute_spec_import_ps_on_execute_spec_import, RideExecuteSpecXmlImport)
35 
36  def disable(self):
37  self.unsubscribe_allunsubscribe_all()
38  self.unregister_actionsunregister_actions()
39 
40  def _ps_on_execute_spec_import(self, message):
41  self.execute_spec_importexecute_spec_import()
42 
44  path = self._get_path_to_library_spec_get_path_to_library_spec()
45  if self._is_valid_path_is_valid_path(path):
46  self._store_spec_store_spec(path)
47  self._execute_namespace_update_execute_namespace_update()
48 
49  def _is_valid_path(self, path):
50  return path and os.path.isfile(path)
51 
53  self.modelmodel.update_namespace()
54 
56  wildcard = ('Library Spec XML|*.xml|All Files|*.*')
57  dlg = wx.FileDialog(self.frameframe,
58  message='Import Library Spec XML',
59  wildcard=wildcard,
60  defaultDir=self.modelmodel.default_dir) # DEBUG
61  # , style=wx.OPEN)
62  if dlg.ShowModal() == wx.ID_OK:
63  path = dlg.GetPath()
64  else:
65  path = None
66  dlg.Destroy()
67  return path
68 
69  def _store_spec(self, path):
70  name = get_name_from_xml(path)
71  if name:
72  shutil.copy(path, os.path.join(context.LIBRARY_XML_DIRECTORY, name+'.xml'))
73  wx.MessageBox('Library "%s" imported\nfrom "%s"\nThis may require RIDE restart.' % (name, path), 'Info', wx.OK | wx.ICON_INFORMATION)
74  else:
75  wx.MessageBox('Could not import library from file "%s"' % path, 'Import failed', wx.OK | wx.ICON_ERROR)
Used to create menu entries, keyboard shortcuts and/or toolbar buttons.
Definition: actioninfo.py:176
Entry point to RIDE plugin API – all plugins must extend this class.
Definition: plugin.py:50
def unsubscribe_all(self)
Stops to listen to all messages this plugin has subscribed to.
Definition: plugin.py:411
def register_action(self, action_info)
Registers a menu entry and optionally a shortcut and a toolbar icon.
Definition: plugin.py:205
def unregister_actions(self)
Unregisters all actions registered by this plugin.
Definition: plugin.py:230
def disable(self)
Called by RIDE when the plugin is disabled.
Definition: specimporter.py:36
def enable(self)
This method is called by RIDE when the plugin is enabled.
Definition: specimporter.py:31