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

« back to all changes in this revision

Viewing changes to lib/common/svn.py

  • Committer: wagrant
  • Date: 2008-07-16 01:26:48 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:884
common.svn: Add a wrapper object to make a pysvn listing object look
            like the result of os.stat.
fileservice_lib: Factor out the last bit of statting duplication, this
                 time from the pysvn listing bit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# Author: William Grant
20
20
# Date:   16/07/2008
21
21
 
 
22
import stat
 
23
 
22
24
import pysvn
23
25
 
24
26
def revision_from_string(r_str):
38
40
        except:
39
41
            pass
40
42
    return None
 
43
 
 
44
class PysvnListStatWrapper:
 
45
    '''Wrap a pysvn listing object to look somewhat like a result of
 
46
       os.stat.
 
47
    '''
 
48
    def __init__(self, pysvn_list):
 
49
        self.pysvn_list = pysvn_list
 
50
 
 
51
    def __getattr__(self, name):
 
52
        try:
 
53
            if name == 'st_mode':
 
54
                # Special magic needed.
 
55
                if self.pysvn_list.kind == pysvn.node_kind.dir:
 
56
                    return stat.S_IFDIR
 
57
                else:
 
58
                    return stat.S_IFREG
 
59
                return value
 
60
            return getattr(self.pysvn_list,
 
61
                           {'st_mtime': 'time',
 
62
                            'st_size': 'size',
 
63
                           }[name])
 
64
        except AttributeError, KeyError:
 
65
            raise AttributeError, name