-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsession.py
69 lines (48 loc) · 1.95 KB
/
session.py
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
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
" Provides a central place for obtaining common info."
import os
import locale
import bsddb
import xdg.BaseDirectory
from PyQt4 import QtCore
from config import PyChmViewerConfig
class Session(object):
" A central place with common info across whole app."
organization = u"PyChmViewer"
application = u"PyChmViewer"
description = u"A CHM reader written in PyQt"
version = u"0.1.2"
license = u"GPLv2"
homepage = u"http://www.github.com/adaptee/pychmviewer"
authors = [
(u"Xinyu.Xiang(John)", u"[email protected]", "2009 - 2009"),
(u"Jekyll Wu" , u"[email protected]" , "2010 - ") ,
]
def __init__(self):
self.config_dir = self._getConfigDir()
self.config = self._getConfig()
self.snapshot = self._getSnapshot()
self.system_encoding = locale.getdefaultlocale()[1]
QtCore.QCoreApplication.setOrganizationName(self.organization)
QtCore.QCoreApplication.setApplicationName(self.application)
self.qsettings = QtCore.QSettings()
def _getConfigDir(self):
" Get the location of config dir"
config_dir = os.path.join( xdg.BaseDirectory.xdg_config_home,
self.application)
if not os.path.exists(config_dir):
os.mkdir(config_dir)
return config_dir
def _getConfig(self):
" Get the config object."
config_path = os.path.join(self.config_dir, "pychmviewer.cfg" )
return PyChmViewerConfig(config_path)
def _getSnapshot(self):
" Get the snapshot of last session."
snapshot_path = os.path.join( self.config_dir, "snapshot.db" )
try:
return bsddb.hashopen(snapshot_path)
except bsddb.db.DBNoSuchFileError:
# a dummy database
return { }