~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to lib/common/interpret.py

  • Committer: drtomc
  • Date: 2008-03-03 08:08:07 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:632
Get the user id from a cached copy of database info.
This doesn't completely fix the current difficulties
in getting content published, but if the content is
correctly marked as published, then this fix gets things
working as expected.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
# This can be resolved but needs careful sanitisation. See fixup_environ.
29
29
 
30
30
from common import studpath
 
31
from common import db
31
32
import conf
32
33
import functools
33
34
 
42
43
 
43
44
CGI_BLOCK_SIZE = 65535
44
45
 
 
46
uids = {}
 
47
 
 
48
def get_uid(login):
 
49
    """Get the unix uid corresponding to the given login name.
 
50
       If it is not in the dictionary of uids, then consult the
 
51
       database and retrieve an update of the user table."""
 
52
    global uids
 
53
    if login in uids:
 
54
        return uids[login]
 
55
 
 
56
    conn = db.DB()
 
57
    res = conn.get_all('login', ['login', 'unixid'])
 
58
    def repack(flds):
 
59
        return (flds['login'], flds['unixid'])
 
60
    uids = dict(map(repack,res))
 
61
 
 
62
    return uids[login]
 
63
 
45
64
def interpret_file(req, owner, jail_dir, filename, interpreter):
46
65
    """Serves a file by interpreting it using one of IVLE's builtin
47
66
    interpreters. All interpreters are intended to run in the user's jail. The
72
91
    # (Note: files are executed by their owners, not the logged in user.
73
92
    # This ensures users are responsible for their own programs and also
74
93
    # allows them to be executed by the public).
75
 
    uid = req.user.unixid
 
94
    uid = get_uid(owner)
76
95
 
77
96
    # Split up req.path again, this time with respect to the jail
78
97
    (working_dir, _) = os.path.split(filename_abs)