mirror of
https://github.com/beetbox/beets.git
synced 2025-12-30 04:22:40 +01:00
move cpu_count to util module; credit @storrgie
This commit is contained in:
parent
6b7d9a6f40
commit
526e82feaf
3 changed files with 29 additions and 27 deletions
|
|
@ -524,3 +524,29 @@ def plurality(objs):
|
|||
res = obj
|
||||
|
||||
return res, max_freq
|
||||
|
||||
def cpu_count():
|
||||
"""Return the number of hardware thread contexts (cores or SMT
|
||||
threads) in the system.
|
||||
"""
|
||||
# Adapted from observing the soundconverter project:
|
||||
# https://github.com/kassoulet/soundconverter
|
||||
if sys.platform == 'win32':
|
||||
try:
|
||||
num = int(os.environ['NUMBER_OF_PROCESSORS'])
|
||||
except (ValueError, KeyError):
|
||||
num = 0
|
||||
elif sys.platform == 'darwin':
|
||||
try:
|
||||
num = int(os.popen('sysctl -n hw.ncpu').read())
|
||||
except ValueError:
|
||||
num = 0
|
||||
else:
|
||||
try:
|
||||
num = os.sysconf('SC_NPROCESSORS_ONLN')
|
||||
except (ValueError, OSError, AttributeError):
|
||||
num = 0
|
||||
if num >= 1:
|
||||
return num
|
||||
else:
|
||||
return 1
|
||||
|
|
|
|||
|
|
@ -29,31 +29,6 @@ DEVNULL = open(os.devnull, 'wb')
|
|||
conf = {}
|
||||
|
||||
|
||||
def _cpu_count():
|
||||
""" Returns the number of CPUs in the system.
|
||||
Code was adapted from observing the soundconverter project:
|
||||
https://github.com/kassoulet/soundconverter
|
||||
"""
|
||||
if sys.platform == 'win32':
|
||||
try:
|
||||
num = int(os.environ['NUMBER_OF_PROCESSORS'])
|
||||
except (ValueError, KeyError):
|
||||
num = 0
|
||||
elif sys.platform == 'darwin':
|
||||
try:
|
||||
num = int(os.popen('sysctl -n hw.ncpu').read())
|
||||
except ValueError:
|
||||
num = 0
|
||||
else:
|
||||
try:
|
||||
num = os.sysconf('SC_NPROCESSORS_ONLN')
|
||||
except (ValueError, OSError, AttributeError):
|
||||
num = 0
|
||||
if num >= 1:
|
||||
return num
|
||||
else:
|
||||
return 1
|
||||
|
||||
|
||||
def encode(source, dest):
|
||||
log.info('Started encoding ' + source)
|
||||
|
|
@ -144,7 +119,7 @@ class ConvertPlugin(BeetsPlugin):
|
|||
def configure(self, config):
|
||||
conf['dest'] = ui.config_val(config, 'convert', 'dest', None)
|
||||
conf['threads'] = ui.config_val(config, 'convert', 'threads',
|
||||
_cpu_count())
|
||||
util.cpu_count())
|
||||
conf['flac'] = ui.config_val(config, 'convert', 'flac', 'flac')
|
||||
conf['lame'] = ui.config_val(config, 'convert', 'lame', 'lame')
|
||||
conf['opts'] = ui.config_val(config, 'convert',
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ Changelog
|
|||
-----------------------
|
||||
|
||||
* New plugin: :doc:`/plugins/convert` transcodes music and embeds album art
|
||||
while copying to a separate directory. Thanks to Jakob Schnitzer.
|
||||
while copying to a separate directory. Thanks to Jakob Schnitzer and Andrew G.
|
||||
Dunn.
|
||||
* New plugin: :doc:`/plugins/fuzzy_search` lets you find albums and tracks using
|
||||
fuzzy string matching so you don't have to type (or even remember) their exact
|
||||
names. Thanks to Philippe Mongeau.
|
||||
|
|
|
|||
Loading…
Reference in a new issue