Merge lp:~meths/openlp/trivialfixes into lp:openlp

Proposed by Jon Tibble
Status: Merged
Merged at revision: not available
Proposed branch: lp:~meths/openlp/trivialfixes
Merge into: lp:openlp
Diff against target: None lines
To merge this branch: bzr merge lp:~meths/openlp/trivialfixes
Reviewer Review Type Date Requested Status
Raoul Snyman Approve
Review via email: mp+12126@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jon Tibble (meths) wrote :

Refactor services to:

- Change all references of oos to service
- Add code to clean service directory on closing OpenLP

Revision history for this message
Raoul Snyman (raoul-snyman) :
review: Approve
lp:~meths/openlp/trivialfixes updated
557. By Jon Tibble

Refactor services

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/core/lib/serviceitem.py'
2--- openlp/core/lib/serviceitem.py 2009-09-16 04:59:38 +0000
3+++ openlp/core/lib/serviceitem.py 2009-09-19 21:45:50 +0000
4@@ -174,12 +174,12 @@
5 self.service_item_path = path
6 self.service_frames.append({u'title': frame_title, u'command': None})
7
8- def get_oos_repr(self):
9+ def get_service_repr(self):
10 """
11- This method returns some text which can be saved into the OOS
12+ This method returns some text which can be saved into the service
13 file to represent this item.
14 """
15- oos_header = {
16+ service_header = {
17 u'name': self.name.lower(),
18 u'plugin': self.shortname,
19 u'theme':self.theme,
20@@ -189,19 +189,19 @@
21 u'type':self.service_item_type,
22 u'audit':self.audit
23 }
24- oos_data = []
25+ service_data = []
26 if self.service_item_type == ServiceType.Text:
27 for slide in self.service_frames:
28- oos_data.append(slide)
29+ service_data.append(slide)
30 elif self.service_item_type == ServiceType.Image:
31 for slide in self.service_frames:
32- oos_data.append(slide[u'title'])
33+ service_data.append(slide[u'title'])
34 elif self.service_item_type == ServiceType.Command:
35 for slide in self.service_frames:
36- oos_data.append(slide[u'title'])
37- return {u'header': oos_header, u'data': oos_data}
38+ service_data.append(slide[u'title'])
39+ return {u'header': service_header, u'data': service_data}
40
41- def set_from_oos(self, serviceitem, path=None):
42+ def set_from_service(self, serviceitem, path=None):
43 """
44 This method takes a service item from a saved service file (passed
45 from the ServiceManager) and extracts the data actually required.
46
47=== modified file 'openlp/core/ui/mainwindow.py'
48--- openlp/core/ui/mainwindow.py 2009-09-19 11:25:01 +0000
49+++ openlp/core/ui/mainwindow.py 2009-09-19 21:45:50 +0000
50@@ -453,7 +453,7 @@
51 QtGui.QMainWindow.__init__(self)
52 self.closeEvent = self.onCloseEvent
53 self.screenList = screens
54- self.oosNotSaved = False
55+ self.serviceNotSaved = False
56 self.settingsmanager = SettingsManager(screens)
57 self.mainDisplay = MainDisplay(self, screens)
58 self.generalConfig = PluginConfig(u'General')
59@@ -535,8 +535,8 @@
60 self.plugin_helpers[u'service'] = self.ServiceManagerContents
61 self.plugin_helpers[u'settings'] = self.settingsForm
62 self.plugin_manager.find_plugins(pluginpath, self.plugin_helpers)
63- # hook methods have to happen after find_plugins. Find plugins needs the
64- # controllers hence the hooks have moved from setupUI() to here
65+ # hook methods have to happen after find_plugins. Find plugins needs
66+ # the controllers hence the hooks have moved from setupUI() to here
67 # Find and insert settings tabs
68 log.info(u'hook settings')
69 self.plugin_manager.hook_settings_tabs(self.settingsForm)
70@@ -617,10 +617,10 @@
71 """
72 Hook to close the main window and display windows on exit
73 """
74- if self.oosNotSaved == True:
75+ if self.serviceNotSaved == True:
76 ret = QtGui.QMessageBox.question(None,
77 translate(u'mainWindow', u'Save Changes to Service?'),
78- translate(u'mainWindow', u'Your service has been changed, do you want to save those changes?'),
79+ translate(u'mainWindow', u'Your service has changed, do you want to save those changes?'),
80 QtGui.QMessageBox.StandardButtons(
81 QtGui.QMessageBox.Cancel |
82 QtGui.QMessageBox.Discard |
83@@ -629,16 +629,19 @@
84 if ret == QtGui.QMessageBox.Save:
85 self.ServiceManagerContents.onSaveService()
86 self.mainDisplay.close()
87+ self.ServiceManagerContents.cleanUp()
88 self.cleanUp()
89 event.accept()
90 elif ret == QtGui.QMessageBox.Discard:
91 self.mainDisplay.close()
92+ self.ServiceManagerContents.cleanUp()
93 self.cleanUp()
94 event.accept()
95 else:
96 event.ignore()
97 else:
98 self.mainDisplay.close()
99+ self.ServiceManagerContents.cleanUp()
100 self.cleanUp()
101 event.accept()
102
103@@ -647,21 +650,25 @@
104 log.info(u'cleanup plugins')
105 self.plugin_manager.finalise_plugins()
106
107- def OosChanged(self, reset=False, oosName=None):
108- """
109- Hook to change the title if the OOS has been changed
110- reset - tells if the OOS has been cleared or saved
111- oosName - is the name of the OOS (if it has one)
112- """
113- if not oosName:
114+ def serviceChanged(self, reset=False, serviceName=None):
115+ """
116+ Hook to change the main window title when the service changes
117+
118+ ``reset``
119+ Shows if the service has been cleared or saved
120+
121+ ``serviceName``
122+ The name of the service (if it has one)
123+ """
124+ if not serviceName:
125 service_name = u'(unsaved service)'
126 else:
127- service_name = oosName
128+ service_name = serviceName
129 if reset == True:
130- self.oosNotSaved = False
131+ self.serviceNotSaved = False
132 title = u'%s - %s' % (self.mainTitle, service_name)
133 else:
134- self.oosNotSaved = True
135+ self.serviceNotSaved = True
136 title = u'%s - %s*' % (self.mainTitle, service_name)
137 self.setWindowTitle(title)
138
139
140=== modified file 'openlp/core/ui/servicemanager.py'
141--- openlp/core/ui/servicemanager.py 2009-09-19 19:37:01 +0000
142+++ openlp/core/ui/servicemanager.py 2009-09-19 21:45:50 +0000
143@@ -84,10 +84,9 @@
144
145 class ServiceManager(QtGui.QWidget):
146 """
147- Manages the orders of service. Currently this involves taking
148- text strings from plugins and adding them to an OOS file. In
149- future, it will also handle zipping up all the resources used into
150- one lump.
151+ Manages the services. This involves taking text strings from plugins and
152+ adding them to the service. This service can then be zipped up with all
153+ the resources used into one OSZ file for use on any OpenLP v2 installation.
154 Also handles the UI tasks of moving things up and down etc.
155 """
156 global log
157@@ -274,7 +273,7 @@
158 self.serviceItems.remove(self.serviceItems[item])
159 self.serviceItems.insert(0, temp)
160 self.repaintServiceList(0, count)
161- self.parent.OosChanged(False, self.serviceName)
162+ self.parent.serviceChanged(False, self.serviceName)
163
164 def onServiceUp(self):
165 """
166@@ -287,7 +286,7 @@
167 self.serviceItems.remove(self.serviceItems[item])
168 self.serviceItems.insert(item - 1, temp)
169 self.repaintServiceList(item - 1, count)
170- self.parent.OosChanged(False, self.serviceName)
171+ self.parent.serviceChanged(False, self.serviceName)
172
173 def onServiceDown(self):
174 """
175@@ -300,7 +299,7 @@
176 self.serviceItems.remove(self.serviceItems[item])
177 self.serviceItems.insert(item + 1, temp)
178 self.repaintServiceList(item + 1, count)
179- self.parent.OosChanged(False, self.serviceName)
180+ self.parent.serviceChanged(False, self.serviceName)
181
182 def onServiceEnd(self):
183 """
184@@ -312,7 +311,7 @@
185 self.serviceItems.remove(self.serviceItems[item])
186 self.serviceItems.insert(len(self.serviceItems), temp)
187 self.repaintServiceList(len(self.serviceItems) - 1, count)
188- self.parent.OosChanged(False, self.serviceName)
189+ self.parent.serviceChanged(False, self.serviceName)
190
191 def onNewService(self):
192 """
193@@ -322,7 +321,7 @@
194 self.serviceItems = []
195 self.serviceName = u''
196 self.isNew = True
197- self.parent.OosChanged(True, self.serviceName)
198+ self.parent.serviceChanged(True, self.serviceName)
199
200 def onDeleteFromService(self):
201 """
202@@ -332,9 +331,9 @@
203 if item is not -1:
204 self.serviceItems.remove(self.serviceItems[item])
205 self.repaintServiceList(0, 0)
206- self.parent.OosChanged(False, self.serviceName)
207+ self.parent.serviceChanged(False, self.serviceName)
208
209- def repaintServiceList(self, serviceItem, serviceItemCount):
210+ def repaintServiceList(self, serviceItem, serviceItemCount):
211 """
212 Clear the existing service list and prepaint all the items
213 Used when moving items as the move takes place in supporting array,
214@@ -366,28 +365,29 @@
215
216 def onSaveService(self, quick=False):
217 """
218- Save the current service in a zip file
219+ Save the current service in a zip (OSZ) file
220 This file contains
221- * An ood which is a pickle of the service items
222+ * An osd which is a pickle of the service items
223 * All image, presentation and video files needed to run the service.
224 """
225 if not quick or self.isNew:
226 filename = QtGui.QFileDialog.getSaveFileName(self,
227- u'Save Order of Service',self.config.get_last_dir() )
228+ u'Save Service', self.config.get_last_dir())
229 else:
230 filename = self.config.get_last_dir()
231 if filename != u'':
232 splittedFile = filename.split(u'.')
233- if splittedFile[-1] != u'oos':
234- filename = filename + u'.oos'
235+ if splittedFile[-1] != u'osz':
236+ filename = filename + u'.osz'
237 filename = unicode(filename)
238 self.isNew = False
239 self.config.set_last_dir(filename)
240 service = []
241- servicefile= filename + u'.ood'
242+ servicefile = filename + u'.osd'
243 zip = zipfile.ZipFile(unicode(filename), 'w')
244 for item in self.serviceItems:
245- service.append({u'serviceitem':item[u'data'].get_oos_repr()})
246+ service.append(
247+ {u'serviceitem':item[u'data'].get_service_repr()})
248 if item[u'data'].service_item_type == ServiceType.Image or \
249 item[u'data'].service_item_type == ServiceType.Command:
250 for frame in item[u'data'].frames:
251@@ -405,20 +405,19 @@
252 pass #if not present do not worry
253 name = filename.split(os.path.sep)
254 self.serviceName = name[-1]
255- self.parent.OosChanged(True, self.serviceName)
256+ self.parent.serviceChanged(True, self.serviceName)
257
258 def onQuickSaveService(self):
259 self.onSaveService(True)
260
261 def onLoadService(self):
262 """
263- Load an existing service from disk and rebuilds the serviceitems
264- All files retrieved from the zip file are placed in a temporary
265- directory and will only be used for this service.
266+ Load an existing service from disk and rebuild the serviceitems. All
267+ files retrieved from the zip file are placed in a temporary directory
268+ and will only be used for this service.
269 """
270- filename = QtGui.QFileDialog.getOpenFileName(self,
271- u'Open Order of Service', self.config.get_last_dir(),
272- u'Services (*.oos)')
273+ filename = QtGui.QFileDialog.getOpenFileName(self, u'Open Service',
274+ self.config.get_last_dir(), u'Services (*.osz)')
275 filename = unicode(filename)
276 name = filename.split(os.path.sep)
277 if filename != u'':
278@@ -439,7 +438,7 @@
279 f.write(zip.read(file))
280 f.flush()
281 f.close()
282- if file_to.endswith(u'ood'):
283+ if file_to.endswith(u'osd'):
284 p_file = file_to
285 f = open(p_file, u'r')
286 items = cPickle.load(f)
287@@ -448,17 +447,30 @@
288 for item in items:
289 serviceitem = ServiceItem()
290 serviceitem.RenderManager = self.parent.RenderManager
291- serviceitem.set_from_oos(item, self.servicePath )
292+ serviceitem.set_from_service(item, self.servicePath )
293 self.addServiceItem(serviceitem)
294 try:
295- os.remove(p_file)
296+ if os.path.isfile(p_file):
297+ os.remove(p_file)
298 except:
299- log.exception(u'Failed to remove ood file')
300+ log.exception(u'Failed to remove osd file')
301 except:
302 log.exception(u'Problem loading a service file')
303 self.isNew = False
304 self.serviceName = name[len(name) - 1]
305- self.parent.OosChanged(True, self.serviceName)
306+ self.parent.serviceChanged(True, self.serviceName)
307+
308+ def cleanUp(self):
309+ """
310+ Empties the servicePath of temporary files
311+ """
312+ for file in os.listdir(self.servicePath):
313+ file_path = os.path.join(self.servicePath, file)
314+ try:
315+ if os.path.isfile(file_path):
316+ os.remove(file_path)
317+ except:
318+ log.exception(u'Failed to clean up servicePath')
319
320 def onThemeComboBoxSelected(self, currentIndex):
321 """
322@@ -501,7 +513,7 @@
323 treewidgetitem1.setData(0, QtCore.Qt.UserRole,
324 QtCore.QVariant(count))
325 count = count + 1
326- self.parent.OosChanged(False, self.serviceName)
327+ self.parent.serviceChanged(False, self.serviceName)
328
329 def makePreview(self):
330 """
331
332=== modified file 'openlp/core/ui/test/test_service_manager.py'
333--- openlp/core/ui/test/test_service_manager.py 2009-09-06 13:57:32 +0000
334+++ openlp/core/ui/test/test_service_manager.py 2009-09-19 21:45:50 +0000
335@@ -19,15 +19,17 @@
336 import time
337 import sys
338 import os, os.path
339+import logging
340 from PyQt4 import QtGui, QtCore
341 from PyQt4.QtCore import *
342 from PyQt4.QtGui import *
343-mypath=os.path.split(os.path.abspath(__file__))[0]
344-sys.path.insert(0,(os.path.join(mypath, '..','..', '..','..')))
345+
346+mypath = os.path.split(os.path.abspath(__file__))[0]
347+sys.path.insert(0, (os.path.join(mypath, '..', '..', '..', '..')))
348+
349 from openlp.core.ui import ServiceManager
350 from openlp.plugins.images.lib import ImageServiceItem
351
352-import logging
353 logging.basicConfig(filename='test_service_manager.log', level=logging.INFO,
354 filemode='w')
355
356@@ -36,69 +38,72 @@
357 # return sys._getframe(depth).f_code.co_name
358 global app
359 global log
360-log=logging.getLogger(u'TestServiceManager')
361+log = logging.getLogger(u'TestServiceManager')
362+
363 class TestServiceManager_base:
364 def __init__(self):
365 pass
366
367 def setup_class(self):
368- log.info( "class setup"+unicode(self))
369+ log.info( "class setup" + unicode(self))
370 try:
371 if app is None:
372 app = QtGui.QApplication([])
373 except UnboundLocalError:
374 app = QtGui.QApplication([])
375
376-
377 def teardown_class(self):
378 pass
379
380 def setup_method(self, method):
381 log.info(u'Setup method:' + unicode(method))
382- self.expected_answer="Don't know yet"
383- self.answer=None
384- self.s=ServiceManager(None)
385+ self.expected_answer = "Don't know yet"
386+ self.answer = None
387+ self.s = ServiceManager(None)
388 log.info(u'--------------- Setup Done -------------')
389
390 def teardown_method(self, method):
391- self.s=None
392+ self.s = None
393
394 def select_row(self, row):
395 # now select the line we just added
396 # first get the index
397- i=QModelIndex(self.s.service_data.index(0,0))
398+ i = QModelIndex(self.s.service_data.index(0,0))
399 # make a selection of it
400- self.sm=QItemSelectionModel(self.s.service_data)
401+ self.sm = QItemSelectionModel(self.s.service_data)
402 self.sm.select(i, QItemSelectionModel.ClearAndSelect)
403 log.info(unicode(self.sm.selectedIndexes()))
404 self.s.TreeView.setSelectionModel(self.sm)
405- log.info(u'Selected indexes = ' + unicode(self.s.TreeView.selectedIndexes()))
406+ log.info(u'Selected indexes = ' + unicode(
407+ self.s.TreeView.selectedIndexes()))
408+
409 def test_easy(self):
410 log.info(u'test_easy')
411- item=ImageServiceItem(None)
412+ item = ImageServiceItem(None)
413 item.add(u'test.gif')
414 self.s.addServiceItem(item)
415- answer = self.s.oos_as_text()
416+ answer = self.s.service_as_text()
417 log.info(u'Answer = ' + unicode(answer))
418- lines=answer.split(u'\n')
419+ lines = answer.split(u'\n')
420 log.info(u'lines = ' + unicode(lines))
421 assert lines[0].startswith(u'# <openlp.plugins.images.imageserviceitem.ImageServiceItem object')
422 assert lines[1] == "test.gif"
423 log.info(u'done')
424
425 def test_2items_as_separate_items(self):
426- # If nothing is selected when item is added, a new base service item is added
427+ # If nothing is selected when item is added, a new base service item
428+ # is added
429 log.info(u'test_2items_as_separate_items')
430- item=ImageServiceItem(None)
431+ item = ImageServiceItem(None)
432 item.add(u'test.gif')
433 self.s.addServiceItem(item)
434- item=ImageServiceItem(None)
435+ item = ImageServiceItem(None)
436 item.add(u'test2.gif')
437 item.add(u'test3.gif')
438 self.s.addServiceItem(item)
439- answer = self.s.oos_as_text()
440+ answer = self.s.service_as_text()
441 log.info(u'Answer = ' + unicode(answer))
442- lines=answer.split(u'\n')
443+ lines = answer.split(u'\n')
444 log.info(u'lines = ' + unicode(lines))
445 assert lines[0].startswith(u'# <openlp.plugins.images.imageserviceitem.ImageServiceItem object')
446 assert lines[1] == "test.gif"
447@@ -108,20 +113,22 @@
448 log.info(u'done')
449
450 def test_2items_merged(self):
451- # If the first object is selected when item is added it should be extended
452+ # If the first object is selected when item is added it should be
453+ # extended
454 log.info(u'test_2items_merged')
455- item=ImageServiceItem(None)
456+ item = ImageServiceItem(None)
457 item.add(u'test.gif')
458 self.s.addServiceItem(item)
459 self.select_row(0)
460- log.info(u'Selected indexes = ' + unicode(self.s.TreeView.selectedIndexes()))
461- item=ImageServiceItem(None)
462+ log.info(u'Selected indexes = ' + unicode(
463+ self.s.TreeView.selectedIndexes()))
464+ item = ImageServiceItem(None)
465 item.add(u'test2.gif')
466 item.add(u'test3.gif')
467 self.s.addServiceItem(item)
468- answer = self.s.oos_as_text()
469+ answer = self.s.service_as_text()
470 log.info(u'Answer = ' + unicode(answer))
471- lines=answer.split(u'\n')
472+ lines = answer.split(u'\n')
473 log.info(u'lines = ' + unicode(lines))
474 assert lines[0].startswith(u'# <openlp.plugins.images.imageserviceitem.ImageServiceItem object')
475 assert lines[1] == "test.gif"
476@@ -138,7 +145,6 @@
477
478
479 if __name__ == "__main__":
480-
481 t=TestServiceManager_base()
482 t.setup_class()
483 t.setup_method(None)
484
485=== modified file 'openlp/plugins/plugin.txt'
486--- openlp/plugins/plugin.txt 2008-11-17 20:36:01 +0000
487+++ openlp/plugins/plugin.txt 2009-09-19 21:45:50 +0000
488@@ -9,21 +9,23 @@
489 * Powerpoint/Openoffice Impress
490 * Lyrics :) (with chords, rich text, etc...)
491 * Musical score
492-* Midi files (hmmm, that's not a thing to display, but feels like it should be there...)
493+* Midi files (hmmm, that's not a thing to display, but feels like it should be
494+ there...)
495 * Audio files, CDs (hmmm again)
496 * Collections of pictures
497 * Alerts to members of the congregation
498 ... etc.
499
500-The scope of these plugins is "things for display purposes", so
501-each needs to be able to:
502+The scope of these plugins is "things for display purposes", so each needs to
503+be able to:
504 * Render their display (on the projection screen and in a "shrunken form"
505 for preview purposes)
506
507-These plugins need to be part of an OOS. This means they need to
508-* Be able to tell the OOS manager code what to put in the OOS for their "bit"
509+These plugins need to be part of an service. This means they need to
510+* Be able to tell the service manager code what to put in the service for their
511+ "bit"
512 * Have a "tab" in the media manager, which they can render on request
513- to allow bits to be added to the OOS (or indeed shown live)
514+ to allow bits to be added to the service (or indeed shown live)
515
516 In addition, some plugins need to be able to show
517 * How their multiple screens of data are split (eg verses)
518@@ -41,29 +43,29 @@
519 * A version number
520 * Helpfile?
521
522-Funnily enough, the core lyrics engine fits those requirements, so
523-could actually form a plugin...
524+Funnily enough, the core lyrics engine fits those requirements, so could
525+actually form a plugin...
526
527-Each OOS entry may be made up of multiple plugins (to do text on
528-video), so each plugin that contributes to an OOS item will need a
529-"layering" priority.
530+Each service entry may be made up of multiple plugins (to do text on video), so
531+each plugin that contributes to an service item will need a "layering"
532+priority.
533
534 Plugin management
535 -----------------
536
537-Plugins will be packages within the plugins/ directory. The plugin
538-manager will scan this directory when openlp loads for any class which
539-is based on the base Plugin class (or should we call it the
540-DisplayPlugin class to allow for other sorts??)
541+Plugins will be packages within the plugins/ directory. The plugin manager
542+will scan this directory when openlp loads for any class which is based on the
543+base Plugin class (or should we call it the DisplayPlugin class to allow for
544+other sorts??)
545
546 These plugins are then queried for their capabilities/requirements and
547 spaces made in the prefs UI as required, and in the media manager.
548
549-The OOS manager can find out what plugins it has available (we need to
550-report missing plugins when an OOS is loaded).
551+The service manager can find out what plugins it has available (we need to
552+report missing plugins when an service is loaded).
553
554-The display manager will get a ref to a/some plugin(s) from the OOS
555-manager when each OOS item is made live, and can then call on each to
556+The display manager will get a ref to a/some plugin(s) from the service
557+manager when each service item is made live, and can then call on each to
558 render their display.
559
560 Each plugin will have basic attributes for
561@@ -78,8 +80,8 @@
562
563 and a set of API functions for
564 * media manager rendering and handling
565-* creating OOS data
566-* being told OOS data
567+* creating service data
568+* being told service data
569 * set paint context
570 * render
571 * selecting a screen to display