~ubuntu-branches/ubuntu/utopic/pyscrabble/utopic

« back to all changes in this revision

Viewing changes to .pc/installation.patch/pyscrabble/db.py

  • Committer: Bazaar Package Importer
  • Author(s): Magnus Holmgren
  • Date: 2011-04-25 21:58:25 UTC
  • Revision ID: james.westby@ubuntu.com-20110425215825-wk0w127t7mgjrbjy
Tags: 1.6.2-5
* Convert package to source format 3.0 (quilt), meaning renaming the
  patches and converting their headers as well as dropping
  README.source.
* Convert to using dh_python2 (Closes: #616983).
* Run setup.py with --install-layout=deb to get filesystem layout right.
* Bump Debhelper compat level to 7.
* pyscrabble-server.README.Debian: Clarify that pyscrabble-server is not
  intended to be run from the command line directly (Closes: #611833).
* hosts.patch: Improve the code for adding new entries to the Additional
  Hosts list:
  * Fix C&P bug that caused the Game port to be validated twice but the 
    Web port not at all.  
  * Pre-fill the default port numbers to help the user (Closes: #566666).
  * Don't destroy the dialog until the entered values have been extracted.
* Increase Standards-Version to 3.9.2 without changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from pyscrabble import constants
 
2
from pyscrabble import manager
 
3
from ZODB import FileStorage, DB as _DB
 
4
import transaction
 
5
 
 
6
class DB(object):
 
7
    '''
 
8
    Database class
 
9
    '''
 
10
    
 
11
    def __init__(self):
 
12
        '''
 
13
        Initialize the connection to the DB
 
14
        '''
 
15
        r = manager.ResourceManager()
 
16
        path = r["config"][constants.DB_LOCATION]
 
17
        
 
18
        storage = FileStorage.FileStorage(path)    
 
19
        db = _DB(storage)
 
20
        self._conn = db.open()
 
21
        self._root = self._conn.root()
 
22
    
 
23
    def __getattr__(self, key):
 
24
        '''
 
25
        Retrive a key from the database
 
26
        
 
27
        @param key: Key
 
28
        '''
 
29
        if key.startswith('_'):
 
30
            return object.__getattr__(self, key)
 
31
        
 
32
        if not self._root.has_key(key):
 
33
            self._root[key] = {}
 
34
            self.sync()
 
35
        return self._root[key]
 
36
    
 
37
    def __setattr__(self, key, value):
 
38
        '''
 
39
        Add a key to the database
 
40
        
 
41
        @param key: Key
 
42
        @param value: Value
 
43
        '''
 
44
        if key.startswith('_'):
 
45
            object.__setattr__(self, key, value)
 
46
        else:
 
47
            self._root[key] = value
 
48
    
 
49
    def __delattr__(self, key):
 
50
        '''
 
51
        Delete a key from the database
 
52
        
 
53
        @param key: key
 
54
        '''
 
55
        if key.startswith('_'):
 
56
            object.__delattr__(self, key)
 
57
        else:
 
58
            del self._root[key]
 
59
    
 
60
    def sync(self):
 
61
        '''
 
62
        Commit any open transactions
 
63
        '''
 
64
        self._root._p_changed = True
 
65
        transaction.commit()
 
66
    
 
67
    def close(self):
 
68
        '''
 
69
        Close the database
 
70
        '''
 
71
        self.sync()
 
72
        try :
 
73
            self._conn.close()
 
74
        except KeyError:
 
75
            pass
 
76
        
 
77
        
 
78
    
 
 
b'\\ No newline at end of file'