1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#!/usr/bin/python -tt
# vim: sw=4 ts=4 expandtab ai
#
# Mnemosyne. Learning tool based on spaced repetition technique
#
# Copyright (C) 2008 Pomni Development Team <pomni@googlegroups.com>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License version 2 as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
#
"""
Main
"""
import sys
import os
# add mnemosyne directory to Python path in debug mode
if os.path.basename(sys.argv[0]).endswith("debug"):
sys.path.insert(0, "../../")
sys.path.insert(0, "../")
# turn on lazy imports
from mnemosyne.maemo_ui import importer
importer.install()
from optparse import OptionParser
from mnemosyne.maemo_ui.factory import app_factory
from mnemosyne.maemo_ui.dbfixer import DBFixer
from mnemosyne.version import version
# register OSSO DBUS service if applicable
try:
import osso
except ImportError:
pass
else:
SERV = osso.Context("org.mnemosyneproj.mnemosyne", version, False)
def parse_commandline(argv):
""" Parse commandline, check options """
parser = OptionParser(usage = "%prog [options]")
parser.add_option("-u", "--ui", help="ui type", default="hildon")
parser.add_option("-d", "--datadir", help="data directory")
parser.add_option("-m", "--mode", help="working mode. "\
"'main', 'input', 'review', 'statistics' or 'configure'")
return parser.parse_args(argv)
def main(argv):
""" Main """
opts, argv = parse_commandline(argv)
if opts.datadir:
basedir = os.path.abspath(opts.datadir)
elif "MYDOCSDIR" in os.environ and os.path.exists(os.path.join(\
os.environ["MYDOCSDIR"], ".documents")):
basedir = os.path.join(os.environ['MYDOCSDIR'], ".documents/mnemosyne")
elif os.path.exists(os.path.join(os.getcwdu(), ".mnemosyne")):
basedir = os.path.abspath(os.path.join(os.getcwdu(), ".mnemosyne"))
else:
basedir = os.path.join(os.environ['HOME'], ".mnemosyne")
app = app_factory(opts.ui)
app.initialise(basedir)
app.main_widget().start(opts.mode)
app.finalise()
if __name__ == "__main__":
sys.exit(main(sys.argv))
# Local Variables:
# mode: python
# py-indent-offset: 4
# indent-tabs-mode: nil
# tab-width: 4
# End:
|