-
Notifications
You must be signed in to change notification settings - Fork 425
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #394 from salil-gtm/master
Number Of Processors for Linux Platform
- Loading branch information
Showing
5 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
''' | ||
Number of Processors | ||
======= | ||
Simple Example | ||
--------------- | ||
To get battery status:: | ||
>>> from plyer import processors | ||
>>> processors.status | ||
{'Number_of_Processors': '4'} | ||
Supported Platforms | ||
------------------- | ||
Linux | ||
''' | ||
|
||
|
||
class Processors(object): | ||
''' | ||
Number of Processors info facade. | ||
''' | ||
|
||
@property | ||
def status(self): | ||
''' | ||
Property that contains a dict with the following fields: | ||
* **Number_of_Processors** *(int)*: Number of Processors in the system | ||
.. warning:: | ||
If any of the fields is not readable, it is set as | ||
None. | ||
''' | ||
return self.get_state() | ||
|
||
def get_state(self): | ||
return self._get_state() | ||
|
||
# private | ||
|
||
def _get_state(self): | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from subprocess import Popen, PIPE | ||
from plyer.facades import Processors | ||
from plyer.utils import whereis_exe | ||
|
||
from os import environ | ||
|
||
|
||
class LinuxProcessors(Processors): | ||
def _get_state(self): | ||
old_lang = environ.get('LANG') | ||
environ['LANG'] = 'C' | ||
|
||
status = {"Number_of_Processors": None} | ||
|
||
dev = "--all" | ||
nproc_process = Popen( | ||
["nproc", dev], | ||
stdout=PIPE | ||
) | ||
output = nproc_process.communicate()[0] | ||
|
||
environ['LANG'] = old_lang | ||
|
||
if not output: | ||
return status | ||
|
||
status['Number_of_Processors'] = output.rstrip() | ||
|
||
return status | ||
|
||
|
||
def instance(): | ||
import sys | ||
if whereis_exe('nproc'): | ||
return LinuxProcessors() | ||
sys.stderr.write("nproc not found.") | ||
return Processors() |