~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: mbp at sourcefrog
  • Date: 2005-03-23 23:52:10 UTC
  • Revision ID: mbp@sourcefrog.net-20050323235210-5464746b93c39ed0
more notes on darcs

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
# along with this program; if not, write to the Free Software
17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
 
19
 
import os, types, re, time
 
19
import os, types, re, time, types
20
20
from stat import S_ISREG, S_ISDIR, S_ISLNK, ST_MODE, ST_SIZE
21
21
 
22
 
from errors import bailout, BzrError
23
 
from trace import mutter
 
22
from errors import bailout
24
23
 
25
24
def make_readonly(filename):
26
25
    """Make a filename read-only."""
55
54
    elif S_ISLNK(mode):
56
55
        return 'symlink'
57
56
    else:
58
 
        raise BzrError("can't handle file kind with mode %o of %r" % (mode, f)) 
 
57
        bailout("can't handle file kind with mode %o of %r" % (mode, f)) 
59
58
 
60
59
 
61
60
 
118
117
 
119
118
 
120
119
 
121
 
def fingerprint_file(f):
122
 
    import sha
123
 
    s = sha.new()
124
 
    b = f.read()
125
 
    s.update(b)
126
 
    size = len(b)
127
 
    return {'size': size,
128
 
            'sha1': s.hexdigest()}
129
 
 
130
 
 
131
 
 
132
120
def username():
133
121
    """Return email-style username.
134
122
 
164
152
    return '<%s@%s>' % (getpass.getuser(), socket.getfqdn())
165
153
 
166
154
 
167
 
_EMAIL_RE = re.compile(r'[\w+.-]+@[\w+.-]+')
168
155
def user_email():
169
156
    """Return just the email component of a username."""
170
157
    e = os.environ.get('BZREMAIL') or os.environ.get('EMAIL')
171
158
    if e:
172
 
        m = _EMAIL_RE.search(e)
 
159
        import re
 
160
        m = re.search(r'[\w+.-]+@[\w+.-]+', e)
173
161
        if not m:
174
162
            bailout('%r is not a reasonable email address' % e)
175
163
        return m.group(0)
198
186
def local_time_offset(t=None):
199
187
    """Return offset of local zone from GMT, either at present or at time t."""
200
188
    # python2.3 localtime() can't take None
201
 
    if t == None:
 
189
    if t is None:
202
190
        t = time.time()
203
191
        
204
192
    if time.localtime(t).tm_isdst and time.daylight:
210
198
def format_date(t, offset=0, timezone='original'):
211
199
    ## TODO: Perhaps a global option to use either universal or local time?
212
200
    ## Or perhaps just let people set $TZ?
 
201
    import time
 
202
    
213
203
    assert isinstance(t, float)
214
204
    
215
205
    if timezone == 'utc':
268
258
    BzrError: ("sorry, '..' not allowed in path", [])
269
259
    """
270
260
    assert isinstance(p, types.StringTypes)
271
 
    ps = [f for f in p.split('/') if (f != '.' and f != '')]
 
261
    ps = [f for f in p.split('/') if f != '.']
272
262
    for f in ps:
273
263
        if f == '..':
274
264
            bailout("sorry, %r not allowed in path" % f)
277
267
def joinpath(p):
278
268
    assert isinstance(p, list)
279
269
    for f in p:
280
 
        if (f == '..') or (f == None) or (f == ''):
 
270
        if (f == '..') or (f is None) or (f == ''):
281
271
            bailout("sorry, %r not allowed in path" % f)
282
272
    return '/'.join(p)
283
273