191
191
except IOError, e:
192
192
# RBC 20060103 abstraction leakage: the paramiko SFTP clients rename
193
# function raises an IOError with errno == None when a rename fails.
193
# function raises an IOError with errno is None when a rename fails.
194
194
# This then gets caught here.
195
195
if e.errno not in (None, errno.ENOENT, errno.ENOTDIR):
197
197
except Exception, e:
198
if (not hasattr(e, 'errno')
198
if (getattr(e, 'errno', None) is None
199
199
or e.errno not in (errno.ENOENT, errno.ENOTDIR)):
555
555
def local_time_offset(t=None):
556
556
"""Return offset of local zone from GMT, either at present or at time t."""
557
557
# python2.3 localtime() can't take None
561
561
if time.localtime(t).tm_isdst and time.daylight:
596
596
return time.strftime('%Y%m%d%H%M%S', time.gmtime(when))
599
def format_delta(delta):
600
"""Get a nice looking string for a time delta.
602
:param delta: The time difference in seconds, can be positive or negative.
603
positive indicates time in the past, negative indicates time in the
604
future. (usually time.time() - stored_time)
605
:return: String formatted to show approximate resolution
611
direction = 'in the future'
615
if seconds < 90: # print seconds up to 90 seconds
617
return '%d second %s' % (seconds, direction,)
619
return '%d seconds %s' % (seconds, direction)
621
minutes = int(seconds / 60)
622
seconds -= 60 * minutes
627
if minutes < 90: # print minutes, seconds up to 90 minutes
629
return '%d minute, %d second%s %s' % (
630
minutes, seconds, plural_seconds, direction)
632
return '%d minutes, %d second%s %s' % (
633
minutes, seconds, plural_seconds, direction)
635
hours = int(minutes / 60)
636
minutes -= 60 * hours
643
return '%d hour, %d minute%s %s' % (hours, minutes,
644
plural_minutes, direction)
645
return '%d hours, %d minute%s %s' % (hours, minutes,
646
plural_minutes, direction)
601
649
"""Return size of given open file."""
677
725
assert isinstance(p, list)
679
if (f == '..') or (f == None) or (f == ''):
727
if (f == '..') or (f is None) or (f == ''):
680
728
raise BzrError("sorry, %r not allowed in path" % f)
681
729
return pathjoin(*p)
870
919
def supports_executable():
871
920
return sys.platform != "win32"
923
def set_or_unset_env(env_variable, value):
924
"""Modify the environment, setting or removing the env_variable.
926
:param env_variable: The environment variable in question
927
:param value: The value to set the environment to. If None, then
928
the variable will be removed.
929
:return: The original value of the environment variable.
931
orig_val = os.environ.get(env_variable)
933
if orig_val is not None:
934
del os.environ[env_variable]
936
if isinstance(value, unicode):
937
value = value.encode(bzrlib.user_encoding)
938
os.environ[env_variable] = value
874
942
_validWin32PathRE = re.compile(r'^([A-Za-z]:[/\\])?[^:<>*"?\|]*$')
1032
1100
_cached_user_encoding = locale.getpreferredencoding()
1033
1101
except locale.Error, e:
1034
1102
sys.stderr.write('bzr: warning: %s\n'
1035
' Could not what text encoding to use.\n'
1103
' Could not determine what text encoding to use.\n'
1036
1104
' This error usually means your Python interpreter\n'
1037
1105
' doesn\'t support the locale set by $LANG (%s)\n'
1038
1106
" Continuing with ascii encoding.\n"