forked from openlp/openlp
Clean up directory creation
This commit is contained in:
parent
3190599a76
commit
f6a8e6884c
@ -34,7 +34,7 @@ from subprocess import Popen, PIPE
|
|||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
from openlp.core.lib import Receiver
|
from openlp.core.lib import Receiver, checkDirectoryExists
|
||||||
from openlp.core.resources import qInitResources
|
from openlp.core.resources import qInitResources
|
||||||
from openlp.core.ui.mainwindow import MainWindow
|
from openlp.core.ui.mainwindow import MainWindow
|
||||||
from openlp.core.ui.exceptionform import ExceptionForm
|
from openlp.core.ui.exceptionform import ExceptionForm
|
||||||
@ -216,7 +216,7 @@ class OpenLP(QtGui.QApplication):
|
|||||||
|
|
||||||
def setNormalCursor(self):
|
def setNormalCursor(self):
|
||||||
"""
|
"""
|
||||||
Sets the Normal Cursor forthe Application
|
Sets the Normal Cursor for the Application
|
||||||
"""
|
"""
|
||||||
self.restoreOverrideCursor()
|
self.restoreOverrideCursor()
|
||||||
|
|
||||||
@ -243,8 +243,7 @@ def main():
|
|||||||
help='Set the Qt4 style (passed directly to Qt4).')
|
help='Set the Qt4 style (passed directly to Qt4).')
|
||||||
# Set up logging
|
# Set up logging
|
||||||
log_path = AppLocation.get_directory(AppLocation.CacheDir)
|
log_path = AppLocation.get_directory(AppLocation.CacheDir)
|
||||||
if not os.path.exists(log_path):
|
checkDirectoryExists(log_path)
|
||||||
os.makedirs(log_path)
|
|
||||||
filename = os.path.join(log_path, u'openlp.log')
|
filename = os.path.join(log_path, u'openlp.log')
|
||||||
logfile = logging.FileHandler(filename, u'w')
|
logfile = logging.FileHandler(filename, u'w')
|
||||||
logfile.setFormatter(logging.Formatter(
|
logfile.setFormatter(logging.Formatter(
|
||||||
|
@ -306,6 +306,17 @@ def expand_tags(text):
|
|||||||
text = text.replace(tag[u'end tag'], tag[u'end html'])
|
text = text.replace(tag[u'end tag'], tag[u'end html'])
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
def checkDirectoryExists(dir):
|
||||||
|
"""
|
||||||
|
Check a theme directory exists and if not create it
|
||||||
|
|
||||||
|
``dir``
|
||||||
|
Theme directory to make sure exists
|
||||||
|
"""
|
||||||
|
log.debug(u'checkDirectoryExists')
|
||||||
|
if not os.path.exists(dir):
|
||||||
|
os.mkdir(dir)
|
||||||
|
|
||||||
from theme import ThemeLevel, ThemeXML, BackgroundGradientType, \
|
from theme import ThemeLevel, ThemeXML, BackgroundGradientType, \
|
||||||
BackgroundType, HorizontalType, VerticalType
|
BackgroundType, HorizontalType, VerticalType
|
||||||
from displaytags import DisplayTags
|
from displaytags import DisplayTags
|
||||||
|
@ -387,7 +387,6 @@ class SlideController(QtGui.QWidget):
|
|||||||
Settings dialog has changed the screen size of adjust output and
|
Settings dialog has changed the screen size of adjust output and
|
||||||
screen previews.
|
screen previews.
|
||||||
"""
|
"""
|
||||||
log.debug(u'screenSizeChanged live = %s' % self.isLive)
|
|
||||||
# rebuild display as screen size changed
|
# rebuild display as screen size changed
|
||||||
self.display = MainDisplay(self, self.screens, self.isLive)
|
self.display = MainDisplay(self, self.screens, self.isLive)
|
||||||
self.display.imageManager = self.parent.renderManager.image_manager
|
self.display.imageManager = self.parent.renderManager.image_manager
|
||||||
@ -403,7 +402,6 @@ class SlideController(QtGui.QWidget):
|
|||||||
Takes care of the SlidePreview's size. Is called when one of the the
|
Takes care of the SlidePreview's size. Is called when one of the the
|
||||||
splitters is moved or when the screen size is changed.
|
splitters is moved or when the screen size is changed.
|
||||||
"""
|
"""
|
||||||
log.debug(u'previewSizeChanged live = %s' % self.isLive)
|
|
||||||
if self.ratio < float(self.PreviewFrame.width()) / float(
|
if self.ratio < float(self.PreviewFrame.width()) / float(
|
||||||
self.PreviewFrame.height()):
|
self.PreviewFrame.height()):
|
||||||
# We have to take the height as limit.
|
# We have to take the height as limit.
|
||||||
|
@ -36,7 +36,7 @@ from openlp.core.ui import FileRenameForm, ThemeForm
|
|||||||
from openlp.core.theme import Theme
|
from openlp.core.theme import Theme
|
||||||
from openlp.core.lib import OpenLPToolbar, ThemeXML, get_text_file_string, \
|
from openlp.core.lib import OpenLPToolbar, ThemeXML, get_text_file_string, \
|
||||||
build_icon, Receiver, SettingsManager, translate, check_item_selected, \
|
build_icon, Receiver, SettingsManager, translate, check_item_selected, \
|
||||||
BackgroundType, BackgroundGradientType
|
BackgroundType, BackgroundGradientType, checkDirectoryExists
|
||||||
from openlp.core.utils import AppLocation, get_filesystem_encoding
|
from openlp.core.utils import AppLocation, get_filesystem_encoding
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -125,9 +125,9 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
# Variables
|
# Variables
|
||||||
self.themelist = []
|
self.themelist = []
|
||||||
self.path = AppLocation.get_section_data_path(self.settingsSection)
|
self.path = AppLocation.get_section_data_path(self.settingsSection)
|
||||||
self.checkDirectoryExists(self.path)
|
checkDirectoryExists(self.path)
|
||||||
self.thumbPath = os.path.join(self.path, u'thumbnails')
|
self.thumbPath = os.path.join(self.path, u'thumbnails')
|
||||||
self.checkDirectoryExists(self.thumbPath)
|
checkDirectoryExists(self.thumbPath)
|
||||||
self.themeForm.path = self.path
|
self.themeForm.path = self.path
|
||||||
self.oldBackgroundImage = None
|
self.oldBackgroundImage = None
|
||||||
# Last little bits of setting up
|
# Last little bits of setting up
|
||||||
@ -457,17 +457,6 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
else:
|
else:
|
||||||
return self._createThemeFromXml(xml, self.path)
|
return self._createThemeFromXml(xml, self.path)
|
||||||
|
|
||||||
def checkDirectoryExists(self, dir):
|
|
||||||
"""
|
|
||||||
Check a theme directory exists and if not create it
|
|
||||||
|
|
||||||
``dir``
|
|
||||||
Theme directory to make sure exists
|
|
||||||
"""
|
|
||||||
log.debug(u'check themes')
|
|
||||||
if not os.path.exists(dir):
|
|
||||||
os.mkdir(dir)
|
|
||||||
|
|
||||||
def unzipTheme(self, filename, dir):
|
def unzipTheme(self, filename, dir):
|
||||||
"""
|
"""
|
||||||
Unzip the theme, remove the preview file if stored
|
Unzip the theme, remove the preview file if stored
|
||||||
@ -498,8 +487,7 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
theme_dir = None
|
theme_dir = None
|
||||||
if osfile.endswith(os.path.sep):
|
if osfile.endswith(os.path.sep):
|
||||||
theme_dir = os.path.join(dir, osfile)
|
theme_dir = os.path.join(dir, osfile)
|
||||||
if not os.path.exists(theme_dir):
|
checkDirectoryExists(theme_dir)
|
||||||
os.mkdir(os.path.join(dir, osfile))
|
|
||||||
else:
|
else:
|
||||||
fullpath = os.path.join(dir, osfile)
|
fullpath = os.path.join(dir, osfile)
|
||||||
names = osfile.split(os.path.sep)
|
names = osfile.split(os.path.sep)
|
||||||
@ -509,8 +497,7 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
themename = names[0]
|
themename = names[0]
|
||||||
if theme_dir is None:
|
if theme_dir is None:
|
||||||
theme_dir = os.path.join(dir, names[0])
|
theme_dir = os.path.join(dir, names[0])
|
||||||
if not os.path.exists(theme_dir):
|
checkDirectoryExists(theme_dir)
|
||||||
os.mkdir(os.path.join(dir, names[0]))
|
|
||||||
if os.path.splitext(ucsfile)[1].lower() in [u'.xml']:
|
if os.path.splitext(ucsfile)[1].lower() in [u'.xml']:
|
||||||
xml_data = zip.read(file)
|
xml_data = zip.read(file)
|
||||||
try:
|
try:
|
||||||
@ -529,16 +516,19 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
theme = self._createThemeFromXml(filexml, self.path)
|
theme = self._createThemeFromXml(filexml, self.path)
|
||||||
self.generateAndSaveImage(dir, themename, theme)
|
self.generateAndSaveImage(dir, themename, theme)
|
||||||
else:
|
else:
|
||||||
QtGui.QMessageBox.critical(self,
|
Receiver.send_message(u'openlp_error_message', {
|
||||||
translate('OpenLP.ThemeManager', 'Error'),
|
u'title': translate('OpenLP.ThemeManager', \
|
||||||
translate('OpenLP.ThemeManager',
|
'Validation Error'),
|
||||||
'File is not a valid theme.'))
|
u'message':translate('OpenLP.ThemeManager',
|
||||||
|
'File is not a valid theme.')})
|
||||||
log.exception(u'Theme file does not contain XML data %s' %
|
log.exception(u'Theme file does not contain XML data %s' %
|
||||||
filename)
|
filename)
|
||||||
except (IOError, NameError):
|
except (IOError, NameError):
|
||||||
QtGui.QMessageBox.critical(self,
|
Receiver.send_message(u'openlp_error_message', {
|
||||||
translate('OpenLP.ThemeManager', 'Error'),
|
u'title': translate('OpenLP.ThemeManager', \
|
||||||
translate('OpenLP.ThemeManager', 'File is not a valid theme.'))
|
'Validation Error'),
|
||||||
|
u'message':translate('OpenLP.ThemeManager',
|
||||||
|
'File is not a valid theme.')})
|
||||||
log.exception(u'Importing theme from zip failed %s' % filename)
|
log.exception(u'Importing theme from zip failed %s' % filename)
|
||||||
finally:
|
finally:
|
||||||
if zip:
|
if zip:
|
||||||
@ -571,11 +561,11 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
"""
|
"""
|
||||||
theme_dir = os.path.join(self.path, themeName)
|
theme_dir = os.path.join(self.path, themeName)
|
||||||
if os.path.exists(theme_dir):
|
if os.path.exists(theme_dir):
|
||||||
QtGui.QMessageBox.critical(self,
|
Receiver.send_message(u'openlp_error_message', {
|
||||||
translate('OpenLP.ThemeManager', 'Theme Exists'),
|
u'title': translate('OpenLP.ThemeManager', \
|
||||||
translate('OpenLP.ThemeManager',
|
'Validation Error'),
|
||||||
'A theme with this name already exists.'),
|
u'message':translate('OpenLP.ThemeManager',
|
||||||
(QtGui.QMessageBox.Ok), QtGui.QMessageBox.Ok)
|
'A theme with this name already exists.')})
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -588,8 +578,7 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
theme_pretty_xml = theme.extract_formatted_xml()
|
theme_pretty_xml = theme.extract_formatted_xml()
|
||||||
log.debug(u'saveTheme %s %s', name, theme_pretty_xml)
|
log.debug(u'saveTheme %s %s', name, theme_pretty_xml)
|
||||||
theme_dir = os.path.join(self.path, name)
|
theme_dir = os.path.join(self.path, name)
|
||||||
if not os.path.exists(theme_dir):
|
checkDirectoryExists(theme_dir)
|
||||||
os.mkdir(os.path.join(self.path, name))
|
|
||||||
theme_file = os.path.join(theme_dir, name + u'.xml')
|
theme_file = os.path.join(theme_dir, name + u'.xml')
|
||||||
if imageTo and self.oldBackgroundImage and \
|
if imageTo and self.oldBackgroundImage and \
|
||||||
imageTo != self.oldBackgroundImage:
|
imageTo != self.oldBackgroundImage:
|
||||||
@ -699,34 +688,13 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
if testPlugin:
|
if testPlugin:
|
||||||
for plugin in self.parent.pluginManager.plugins:
|
for plugin in self.parent.pluginManager.plugins:
|
||||||
if plugin.usesTheme(theme):
|
if plugin.usesTheme(theme):
|
||||||
QtGui.QMessageBox.critical(self,
|
Receiver.send_message(u'openlp_error_message', {
|
||||||
translate('OpenLP.ThemeManager', 'Error'),
|
u'title': translate('OpenLP.ThemeManager', \
|
||||||
unicode(translate('OpenLP.ThemeManager',
|
'Validation Error'),
|
||||||
'Theme %s is used in the %s plugin.')) % \
|
u'message': unicode(translate('OpenLP.ThemeManager',
|
||||||
(theme, plugin.name))
|
'Theme %s is used in the %s plugin.')) % \
|
||||||
|
(theme, plugin.name)})
|
||||||
return False
|
return False
|
||||||
if unicode(self.serviceComboBox.currentText()) == theme:
|
|
||||||
QtGui.QMessageBox.critical(self,
|
|
||||||
translate('OpenLP.ThemeManager', 'Error'),
|
|
||||||
translate('OpenLP.ThemeManager',
|
|
||||||
'You are unable to delete the default theme.'))
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
if testPlugin:
|
|
||||||
for plugin in self.parent.pluginManager.plugins:
|
|
||||||
if plugin.usesTheme(theme):
|
|
||||||
QtGui.QMessageBox.critical(self,
|
|
||||||
translate('OpenLP.ThemeManager', 'Error'),
|
|
||||||
unicode(translate('OpenLP.ThemeManager',
|
|
||||||
'Theme %s is used in the %s plugin.')) % \
|
|
||||||
(theme, plugin.name))
|
|
||||||
return False
|
|
||||||
if unicode(self.serviceComboBox.currentText()) == theme:
|
|
||||||
QtGui.QMessageBox.critical(self,
|
|
||||||
translate('OpenLP.ThemeManager', 'Error'),
|
|
||||||
unicode(translate('OpenLP.ThemeManager',
|
|
||||||
'Theme %s is used by the service manager.')) % theme)
|
|
||||||
return False
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _migrateVersion122(self, xml_data):
|
def _migrateVersion122(self, xml_data):
|
||||||
|
@ -31,7 +31,7 @@ from PyQt4 import QtCore, QtGui
|
|||||||
|
|
||||||
from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \
|
from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \
|
||||||
context_menu_action, ItemCapabilities, SettingsManager, translate, \
|
context_menu_action, ItemCapabilities, SettingsManager, translate, \
|
||||||
check_item_selected, Receiver
|
check_item_selected, Receiver, checkDirectoryExists
|
||||||
from openlp.core.utils import AppLocation, get_images_filter
|
from openlp.core.utils import AppLocation, get_images_filter
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -79,8 +79,7 @@ class ImageMediaItem(MediaManagerItem):
|
|||||||
self.servicePath = os.path.join(
|
self.servicePath = os.path.join(
|
||||||
AppLocation.get_section_data_path(self.settingsSection),
|
AppLocation.get_section_data_path(self.settingsSection),
|
||||||
u'thumbnails')
|
u'thumbnails')
|
||||||
if not os.path.exists(self.servicePath):
|
checkDirectoryExists(self.servicePath)
|
||||||
os.mkdir(self.servicePath)
|
|
||||||
self.loadList(SettingsManager.load_list(
|
self.loadList(SettingsManager.load_list(
|
||||||
self.settingsSection, self.settingsSection))
|
self.settingsSection, self.settingsSection))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user