721
722
_format_date(t, offset, timezone, date_fmt, show_offset)
722
723
date_str = time.strftime(date_fmt, tt)
723
724
if not isinstance(date_str, unicode):
724
date_str = date_str.decode(bzrlib.user_encoding, 'replace')
725
date_str = date_str.decode(get_user_encoding(), 'replace')
725
726
return date_str + offset_str
727
728
def _format_date(t, offset, timezone, date_fmt, show_offset):
1827
1828
termios.tcsetattr(fd, termios.TCSADRAIN, settings)
1832
if sys.platform == 'linux2':
1833
def _local_concurrency():
1835
prefix = 'processor'
1836
for line in file('/proc/cpuinfo', 'rb'):
1837
if line.startswith(prefix):
1838
concurrency = int(line[line.find(':')+1:]) + 1
1840
elif sys.platform == 'darwin':
1841
def _local_concurrency():
1842
return subprocess.Popen(['sysctl', '-n', 'hw.availcpu'],
1843
stdout=subprocess.PIPE).communicate()[0]
1844
elif sys.platform[0:7] == 'freebsd':
1845
def _local_concurrency():
1846
return subprocess.Popen(['sysctl', '-n', 'hw.ncpu'],
1847
stdout=subprocess.PIPE).communicate()[0]
1848
elif sys.platform == 'sunos5':
1849
def _local_concurrency():
1850
return subprocess.Popen(['psrinfo', '-p',],
1851
stdout=subprocess.PIPE).communicate()[0]
1852
elif sys.platform == "win32":
1853
def _local_concurrency():
1854
# This appears to return the number of cores.
1855
return os.environ.get('NUMBER_OF_PROCESSORS')
1857
def _local_concurrency():
1862
_cached_local_concurrency = None
1864
def local_concurrency(use_cache=True):
1865
"""Return how many processes can be run concurrently.
1867
Rely on platform specific implementations and default to 1 (one) if
1868
anything goes wrong.
1870
global _cached_local_concurrency
1871
if _cached_local_concurrency is not None and use_cache:
1872
return _cached_local_concurrency
1875
concurrency = _local_concurrency()
1876
except (OSError, IOError):
1879
concurrency = int(concurrency)
1880
except (TypeError, ValueError):
1883
_cached_concurrency = concurrency