722
721
_format_date(t, offset, timezone, date_fmt, show_offset)
723
722
date_str = time.strftime(date_fmt, tt)
724
723
if not isinstance(date_str, unicode):
725
date_str = date_str.decode(get_user_encoding(), 'replace')
724
date_str = date_str.decode(bzrlib.user_encoding, 'replace')
726
725
return date_str + offset_str
728
727
def _format_date(t, offset, timezone, date_fmt, show_offset):
927
926
shutil.copyfile(src, dest)
929
# Look Before You Leap (LBYL) is appropriate here instead of Easier to Ask for
930
# Forgiveness than Permission (EAFP) because:
931
# - root can damage a solaris file system by using unlink,
932
# - unlink raises different exceptions on different OSes (linux: EISDIR, win32:
933
# EACCES, OSX: EPERM) when invoked on a directory.
930
934
def delete_any(path):
931
"""Delete a file, symlink or directory.
933
Will delete even if readonly.
936
_delete_file_or_dir(path)
937
except (OSError, IOError), e:
938
if e.errno in (errno.EPERM, errno.EACCES):
939
# make writable and try again
942
except (OSError, IOError):
944
_delete_file_or_dir(path)
949
def _delete_file_or_dir(path):
950
# Look Before You Leap (LBYL) is appropriate here instead of Easier to Ask for
951
# Forgiveness than Permission (EAFP) because:
952
# - root can damage a solaris file system by using unlink,
953
# - unlink raises different exceptions on different OSes (linux: EISDIR, win32:
954
# EACCES, OSX: EPERM) when invoked on a directory.
935
"""Delete a file or directory."""
955
936
if isdir(path): # Takes care of symlinks
1044
if len(head) <= len(base) and head != base:
1045
raise errors.PathNotChild(rp, base)
1024
while len(head) >= len(base):
1046
1025
if head == base:
1048
head, tail = split(head)
1027
head, tail = os.path.split(head)
1031
raise errors.PathNotChild(rp, base)
1053
return pathjoin(*reversed(s))
1846
1827
termios.tcsetattr(fd, termios.TCSADRAIN, settings)
1850
if sys.platform == 'linux2':
1851
def _local_concurrency():
1853
prefix = 'processor'
1854
for line in file('/proc/cpuinfo', 'rb'):
1855
if line.startswith(prefix):
1856
concurrency = int(line[line.find(':')+1:]) + 1
1858
elif sys.platform == 'darwin':
1859
def _local_concurrency():
1860
return subprocess.Popen(['sysctl', '-n', 'hw.availcpu'],
1861
stdout=subprocess.PIPE).communicate()[0]
1862
elif sys.platform[0:7] == 'freebsd':
1863
def _local_concurrency():
1864
return subprocess.Popen(['sysctl', '-n', 'hw.ncpu'],
1865
stdout=subprocess.PIPE).communicate()[0]
1866
elif sys.platform == 'sunos5':
1867
def _local_concurrency():
1868
return subprocess.Popen(['psrinfo', '-p',],
1869
stdout=subprocess.PIPE).communicate()[0]
1870
elif sys.platform == "win32":
1871
def _local_concurrency():
1872
# This appears to return the number of cores.
1873
return os.environ.get('NUMBER_OF_PROCESSORS')
1875
def _local_concurrency():
1880
_cached_local_concurrency = None
1882
def local_concurrency(use_cache=True):
1883
"""Return how many processes can be run concurrently.
1885
Rely on platform specific implementations and default to 1 (one) if
1886
anything goes wrong.
1888
global _cached_local_concurrency
1889
if _cached_local_concurrency is not None and use_cache:
1890
return _cached_local_concurrency
1893
concurrency = _local_concurrency()
1894
except (OSError, IOError):
1897
concurrency = int(concurrency)
1898
except (TypeError, ValueError):
1901
_cached_concurrency = concurrency