This commit is contained in:
Tim Bentley 2013-01-23 20:32:49 +00:00
commit 25eb8ae8e8
3 changed files with 20 additions and 27 deletions

View File

@ -43,12 +43,7 @@ from traceback import format_exception
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
<<<<<<< TREE from openlp.core.lib import Receiver, Settings, check_directory_exists, ScreenList, UiStrings, Registry
from openlp.core.lib import Receiver, Settings, check_directory_exists, Registry
from openlp.core.lib.ui import UiStrings
=======
from openlp.core.lib import Receiver, Settings, check_directory_exists, ScreenList, UiStrings
>>>>>>> MERGE-SOURCE
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.firsttimelanguageform import FirstTimeLanguageForm from openlp.core.ui.firsttimelanguageform import FirstTimeLanguageForm
@ -217,7 +212,7 @@ def set_up_logging(log_path):
""" """
Setup our logging using log_path Setup our logging using log_path
""" """
check_directory_exists(log_path) check_directory_exists(log_path, True)
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(u'%(asctime)s %(name)-55s %(levelname)-8s %(message)s')) logfile.setFormatter(logging.Formatter(u'%(asctime)s %(name)-55s %(levelname)-8s %(message)s'))
@ -247,12 +242,6 @@ def main(args=None):
# Parse command line options and deal with them. # Parse command line options and deal with them.
# Use args supplied programatically if possible. # Use args supplied programatically if possible.
(options, args) = parser.parse_args(args) if args else parser.parse_args() (options, args) = parser.parse_args(args) if args else parser.parse_args()
if options.portable:
app_path = AppLocation.get_directory(AppLocation.AppDir)
set_up_logging(os.path.abspath(os.path.join(app_path, u'..', u'..', u'Other')))
log.info(u'Running portable')
else:
set_up_logging(AppLocation.get_directory(AppLocation.CacheDir))
qt_args = [] qt_args = []
if options.loglevel.lower() in ['d', 'debug']: if options.loglevel.lower() in ['d', 'debug']:
log.setLevel(logging.DEBUG) log.setLevel(logging.DEBUG)
@ -277,14 +266,16 @@ def main(args=None):
app.setApplicationName(u'OpenLPPortable') app.setApplicationName(u'OpenLPPortable')
Settings.setDefaultFormat(Settings.IniFormat) Settings.setDefaultFormat(Settings.IniFormat)
# Get location OpenLPPortable.ini # Get location OpenLPPortable.ini
app_path = AppLocation.get_directory(AppLocation.AppDir)
set_up_logging(os.path.abspath(os.path.join(app_path, u'..', u'..', u'Other')))
log.info(u'Running portable')
portable_settings_file = os.path.abspath(os.path.join(app_path, u'..', u'..', u'Data', u'OpenLP.ini')) portable_settings_file = os.path.abspath(os.path.join(app_path, u'..', u'..', u'Data', u'OpenLP.ini'))
# Make this our settings file # Make this our settings file
log.info(u'INI file: %s', portable_settings_file) log.info(u'INI file: %s', portable_settings_file)
Settings.set_filename(portable_settings_file) Settings.set_filename(portable_settings_file)
portable_settings = Settings() portable_settings = Settings()
# Set our data path # Set our data path
data_path = os.path.abspath(os.path.join(app_path, data_path = os.path.abspath(os.path.join(app_path, u'..', u'..', u'Data',))
u'..', u'..', u'Data',))
log.info(u'Data path: %s', data_path) log.info(u'Data path: %s', data_path)
# Point to our data path # Point to our data path
portable_settings.setValue(u'advanced/data path', data_path) portable_settings.setValue(u'advanced/data path', data_path)
@ -292,6 +283,7 @@ def main(args=None):
portable_settings.sync() portable_settings.sync()
else: else:
app.setApplicationName(u'OpenLP') app.setApplicationName(u'OpenLP')
set_up_logging(AppLocation.get_directory(AppLocation.CacheDir))
registry = Registry.create() registry = Registry.create()
app.setApplicationVersion(get_application_version()[u'version']) app.setApplicationVersion(get_application_version()[u'version'])
# Instance check # Instance check

View File

@ -338,17 +338,21 @@ def expand_tags(text):
return text return text
def check_directory_exists(dir): def check_directory_exists(directory, do_not_log=False):
""" """
Check a theme directory exists and if not create it Check a theme directory exists and if not create it
``dir`` ``directory``
Theme directory to make sure exists The directory to make sure exists
``do_not_log``
To not log anything. This is need for the start up, when the log isn't ready.
""" """
log.debug(u'check_directory_exists %s' % dir) if not do_not_log:
log.debug(u'check_directory_exists %s' % directory)
try: try:
if not os.path.exists(dir): if not os.path.exists(directory):
os.makedirs(dir) os.makedirs(directory)
except IOError: except IOError:
pass pass

View File

@ -154,16 +154,13 @@ def _get_os_dir_path(dir_type):
return os.path.join(unicode(os.getenv(u'APPDATA'), encoding), u'openlp', u'data') return os.path.join(unicode(os.getenv(u'APPDATA'), encoding), u'openlp', u'data')
elif dir_type == AppLocation.LanguageDir: elif dir_type == AppLocation.LanguageDir:
return os.path.split(openlp.__file__)[0] return os.path.split(openlp.__file__)[0]
return os.path.join(unicode(os.getenv(u'APPDATA'), encoding), return os.path.join(unicode(os.getenv(u'APPDATA'), encoding), u'openlp')
u'openlp')
elif sys.platform == u'darwin': elif sys.platform == u'darwin':
if dir_type == AppLocation.DataDir: if dir_type == AppLocation.DataDir:
return os.path.join(unicode(os.getenv(u'HOME'), encoding), return os.path.join(unicode(os.getenv(u'HOME'), encoding), u'Library', u'Application Support', u'openlp', u'Data')
u'Library', u'Application Support', u'openlp', u'Data')
elif dir_type == AppLocation.LanguageDir: elif dir_type == AppLocation.LanguageDir:
return os.path.split(openlp.__file__)[0] return os.path.split(openlp.__file__)[0]
return os.path.join(unicode(os.getenv(u'HOME'), encoding), return os.path.join(unicode(os.getenv(u'HOME'), encoding), u'Library', u'Application Support', u'openlp')
u'Library', u'Application Support', u'openlp')
else: else:
if dir_type == AppLocation.LanguageDir: if dir_type == AppLocation.LanguageDir:
prefixes = [u'/usr/local', u'/usr'] prefixes = [u'/usr/local', u'/usr']