add portable settings

This commit is contained in:
rimach 2010-03-15 22:49:37 +01:00
parent 1835a922e5
commit 5170ad1607
2 changed files with 29 additions and 19 deletions

View File

@ -155,11 +155,28 @@ def main():
help="Set logging to LEVEL level. Valid values are "
"\"debug\", \"info\", \"warning\".")
parser.add_option("-p", "--portable", dest="portable",
action="store_true",
help="Specify if this should be run as a portable app, "
"off a USB flash drive.")
default="../openlp-data", metavar="APP_PATH",
help="Specify relative Path where database should be located. E.g. ../openlp-data")
parser.add_option("-s", "--style", dest="style",
help="Set the Qt4 style (passed directly to Qt4).")
# Parse command line options and deal with them.
(options, args) = parser.parse_args()
qt_args = []
if options.loglevel.lower() in ['d', 'debug']:
log.setLevel(logging.DEBUG)
#print 'Logging to:', filename
elif options.loglevel.lower() in ['w', 'warning']:
log.setLevel(logging.WARNING)
else:
log.setLevel(logging.INFO)
if options.style:
qt_args.extend(['-style', options.style])
if options.portable:
os.environ['PORTABLE'] = options.portable
# Throw the rest of the arguments at Qt, just in case.
qt_args.extend(args)
# Set up logging
log_path = AppLocation.get_directory(AppLocation.ConfigDir)
if not os.path.exists(log_path):
@ -170,20 +187,7 @@ def main():
u'%(asctime)s %(name)-20s %(levelname)-8s %(message)s'))
log.addHandler(logfile)
logging.addLevelName(15, u'Timer')
# Parse command line options and deal with them.
(options, args) = parser.parse_args()
qt_args = []
if options.loglevel.lower() in ['d', 'debug']:
log.setLevel(logging.DEBUG)
print 'Logging to:', filename
elif options.loglevel.lower() in ['w', 'warning']:
log.setLevel(logging.WARNING)
else:
log.setLevel(logging.INFO)
if options.style:
qt_args.extend(['-style', options.style])
# Throw the rest of the arguments at Qt, just in case.
qt_args.extend(args)
# Initialise the resources
qInitResources()
# Now create and actually run the application.

10
openlp/core/utils/__init__.py Normal file → Executable file
View File

@ -45,7 +45,10 @@ class AppLocation(object):
if dir_type == AppLocation.AppDir:
return os.path.abspath(os.path.split(sys.argv[0])[0])
elif dir_type == AppLocation.ConfigDir:
if sys.platform == u'win32':
if os.getenv(u'PORTABLE') is not None:
path = os.path.split(os.path.abspath(sys.argv[0]))[0]
path = os.path.join(path, os.getenv(u'PORTABLE'))
elif sys.platform == u'win32':
path = os.path.join(os.getenv(u'APPDATA'), u'openlp')
elif sys.platform == u'darwin':
path = os.path.join(os.getenv(u'HOME'), u'Library',
@ -58,7 +61,10 @@ class AppLocation(object):
path = os.path.join(os.getenv(u'HOME'), u'.openlp')
return path
elif dir_type == AppLocation.DataDir:
if sys.platform == u'win32':
if os.getenv(u'PORTABLE') is not None:
path = os.path.split(os.path.abspath(sys.argv[0]))[0]
path = os.path.join(path, os.getenv(u'PORTABLE'), u'data')
elif sys.platform == u'win32':
path = os.path.join(os.getenv(u'APPDATA'), u'openlp', u'data')
elif sys.platform == u'darwin':
path = os.path.join(os.getenv(u'HOME'), u'Library',