~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: mbp at sourcefrog
  • Date: 2005-04-04 13:10:26 UTC
  • Revision ID: mbp@sourcefrog.net-20050404131026-628553cc03687658
new 'renames' command

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
 
164
163
    return '<%s@%s>' % (getpass.getuser(), socket.getfqdn())
165
164
 
166
165
 
167
 
_EMAIL_RE = re.compile(r'[\w+.-]+@[\w+.-]+')
168
166
def user_email():
169
167
    """Return just the email component of a username."""
170
168
    e = os.environ.get('BZREMAIL') or os.environ.get('EMAIL')
171
169
    if e:
172
 
        m = _EMAIL_RE.search(e)
 
170
        import re
 
171
        m = re.search(r'[\w+.-]+@[\w+.-]+', e)
173
172
        if not m:
174
173
            bailout('%r is not a reasonable email address' % e)
175
174
        return m.group(0)
198
197
def local_time_offset(t=None):
199
198
    """Return offset of local zone from GMT, either at present or at time t."""
200
199
    # python2.3 localtime() can't take None
201
 
    if t == None:
 
200
    if t is None:
202
201
        t = time.time()
203
202
        
204
203
    if time.localtime(t).tm_isdst and time.daylight:
210
209
def format_date(t, offset=0, timezone='original'):
211
210
    ## TODO: Perhaps a global option to use either universal or local time?
212
211
    ## Or perhaps just let people set $TZ?
 
212
    import time
 
213
    
213
214
    assert isinstance(t, float)
214
215
    
215
216
    if timezone == 'utc':
268
269
    BzrError: ("sorry, '..' not allowed in path", [])
269
270
    """
270
271
    assert isinstance(p, types.StringTypes)
271
 
    ps = [f for f in p.split('/') if (f != '.' and f != '')]
 
272
    ps = [f for f in p.split('/') if f != '.']
272
273
    for f in ps:
273
274
        if f == '..':
274
275
            bailout("sorry, %r not allowed in path" % f)
277
278
def joinpath(p):
278
279
    assert isinstance(p, list)
279
280
    for f in p:
280
 
        if (f == '..') or (f == None) or (f == ''):
 
281
        if (f == '..') or (f is None) or (f == ''):
281
282
            bailout("sorry, %r not allowed in path" % f)
282
283
    return '/'.join(p)
283
284