diff --git a/README.md b/README.md index 0afa8a518..1618de27f 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,11 @@ use with Kivy apps, but can be used independently. [![GitHub contributors](https://img.shields.io/github/contributors-anon/kivy/plyer)](https://github.com/kivy/plyer/graphs/contributors) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md) - ![PyPI - Version](https://img.shields.io/pypi/v/plyer) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/plyer) - [![coverage](https://coveralls.io/repos/kivy/plyer/badge.svg?branch=master)](https://coveralls.io/r/kivy/plyer?branch=master) -![Continuous Integration with Ubuntu](https://github.com/kivy/plyer/workflows/Continuous%20Integration%20with%20Ubuntu/badge.svg) +![Continuous Integration with Ubuntu](https://github.com/kivy/plyer/workflows/Continuous%20Integration%20with%20Ubuntu/badge.svg) ![Continuous Integration with OSX](https://github.com/kivy/plyer/workflows/Continuous%20Integration%20with%20OSX/badge.svg) ![Continuous Integration with Windows](https://github.com/kivy/plyer/workflows/Continuous%20Integration%20with%20Windows/badge.svg) ![Deploy to PyPI](https://github.com/kivy/plyer/workflows/Deploy%20to%20PyPI/badge.svg) @@ -29,54 +27,54 @@ implement the API in the easiest way, depending on the current platform. - On Android ([python-for-android](https://python-for-android.readthedocs.io/)), [PyJNIus](https://pypi.org/project/pyjnius/) is used. - On iOS ([kivy-ios](https://pypi.org/project/kivy-ios/)) and macOS, - [pyobjus](https://pypi.org/project/pyobjus/) is used. -- On Windows, macOS and Linux, other commonly found libraries and programs + [pyobjus](https://pypi.org/project/pyobjus/) is used. +- On Windows, macOS and Linux, other commonly found libraries and programs are used. - ## Supported APIs -| Platform | Android | iOS | Windows | macOS | Linux | -| ------------------------------ |:-------:|:---:|:-------:|:-----:|:-----:| -| Accelerometer | ✔ | ✔ | | ✔ | ✔ | -| Audio recording | ✔ | | ✔ | ✔ | | -| Barometer | ✔ | ✔ | | | | -| Battery | ✔ | ✔ | ✔ | ✔ | ✔ | -| Bluetooth | ✔ | | | ✔ | | -| Brightness | ✔ | ✔ | | | ✔ | -| Call | ✔ | ✔ | | | | -| Camera (taking picture) | ✔ | ✔ | | | | -| Compass | ✔ | ✔ | | | | -| CPU count | | | ✔ | ✔ | ✔ | -| Devicename | ✔ | | ✔ | ✔ | ✔ | -| Email (open mail client) | ✔ | ✔ | ✔ | ✔ | ✔ | -| Flash | ✔ | ✔ | | | | -| GPS | ✔ | ✔ | | | | -| Gravity | ✔ | ✔ | | | | -| Gyroscope | ✔ | ✔ | | | | -| Humidity | ✔ | | | | | -| IR Blaster | ✔ | | | | | -| Keystore | ✔ | ✔ | ✔ | ✔ | ✔ | -| Light | ✔ | | | | | -| Maps | | ✔ | | ✔ | | -| Native file chooser | ✔ | ✔ | ✔ | ✔ | ✔ | -| Notifications | ✔ | | ✔ | ✔ | ✔ | -| Orientation | ✔ | | | | ✔ | -| Proximity | ✔ | | | | | -| Screenshot | | | ✔ | ✔ | ✔ | -| SMS (send messages) | ✔ | ✔ | | ✔ | | -| Spatial Orientation | ✔ | ✔ | | | | -| Speech to text | ✔ | | | | | -| Storage Path | ✔ | ✔ | ✔ | ✔ | ✔ | -| Temperature | ✔ | | | | | -| Text to speech | ✔ | ✔ | ✔ | ✔ | ✔ | -| Unique ID | ✔ | ✔ | ✔ | ✔ | ✔ | -| Vibrator | ✔ | ✔ | | | | -| Wifi | | | ✔ | ✔ | ✔ | +| Platform | Android | iOS | Windows | macOS | Linux | +| ------------------------ | :-----: | :-: | :-----: | :---: | :---: | +| Accelerometer | ✔ | ✔ | | ✔ | ✔ | +| Audio recording | ✔ | | ✔ | ✔ | | +| Barometer | ✔ | ✔ | | | | +| Battery | ✔ | ✔ | ✔ | ✔ | ✔ | +| Bluetooth | ✔ | | | ✔ | | +| Brightness | ✔ | ✔ | | | ✔ | +| Call | ✔ | ✔ | | | | +| Camera (taking picture) | ✔ | ✔ | | | | +| Compass | ✔ | ✔ | | | | +| CPU count | | | ✔ | ✔ | ✔ | +| Devicename | ✔ | | ✔ | ✔ | ✔ | +| Email (open mail client) | ✔ | ✔ | ✔ | ✔ | ✔ | +| Flash | ✔ | ✔ | | | | +| GPS | ✔ | ✔ | | | | +| Gravity | ✔ | ✔ | | | | +| Gyroscope | ✔ | ✔ | | | | +| Humidity | ✔ | | | | | +| IR Blaster | ✔ | | | | | +| Keystore | ✔ | ✔ | ✔ | ✔ | ✔ | +| Light | ✔ | | | | | +| Maps | | ✔ | | ✔ | | +| Native file chooser | ✔ | ✔ | ✔ | ✔ | ✔ | +| Notifications | ✔ | | ✔ | ✔ | ✔ | +| Orientation | ✔ | | | | ✔ | +| Proximity | ✔ | | | | | +| Screenshot | | | ✔ | ✔ | ✔ | +| SMS (send messages) | ✔ | ✔ | | ✔ | | +| Spatial Orientation | ✔ | ✔ | | | | +| Speech to text | ✔ | | | | | +| Storage Path | ✔ | ✔ | ✔ | ✔ | ✔ | +| Sysinfo | ✔ | ✔ | ✔ | ✔ | ✔ | +| Temperature | ✔ | | | | | +| Text to speech | ✔ | ✔ | ✔ | ✔ | ✔ | +| Unique ID | ✔ | ✔ | ✔ | ✔ | ✔ | +| Vibrator | ✔ | ✔ | | | | +| Wifi | | | ✔ | ✔ | ✔ | ## Documentation -Full documentation, including details about the API, is available +Full documentation, including details about the API, is available [online](https://plyer.readthedocs.io/en/latest/). If you are not using the latest version of Plyer, earlier versions of the documentations are linked from there. @@ -90,43 +88,43 @@ if needed. ## License Plyer is [MIT licensed](LICENSE), actively developed by a great -community and is supported by many projects managed by the +community and is supported by many projects managed by the [Kivy Organization](https://www.kivy.org/about.html). ## Support Are you having trouble using Plyer or any of its related projects in the Kivy ecosystem? -Is there an error you don’t understand? Are you trying to figure out how to use +Is there an error you don’t understand? Are you trying to figure out how to use it? We have volunteers who can help! -The best channels to contact us for support are listed in the latest +The best channels to contact us for support are listed in the latest [Contact Us](https://github.com/kivy/plyer/blob/master/CONTACT.md) document. ## Contributing Plyer is part of the [Kivy](https://kivy.org) ecosystem - a large group of products used by many thousands of developers for free, but it -is built entirely by the contributions of volunteers. We welcome (and rely on) +is built entirely by the contributions of volunteers. We welcome (and rely on) users who want to give back to the community by contributing to the project. -Contributions can come in many forms. See the latest +Contributions can come in many forms. See the latest [Contribution Guidelines](https://github.com/kivy/plyer/blob/master/CONTRIBUTING.md) for how you can help us. ## Code of Conduct -In the interest of fostering an open and welcoming community, we as -contributors and maintainers need to ensure participation in our project and -our sister projects is a harassment-free and positive experience for everyone. -It is vital that all interaction is conducted in a manner conveying respect, +In the interest of fostering an open and welcoming community, we as +contributors and maintainers need to ensure participation in our project and +our sister projects is a harassment-free and positive experience for everyone. +It is vital that all interaction is conducted in a manner conveying respect, open-mindedness and gratitude. Please consult the [latest Code of Conduct](https://github.com/kivy/plyer/blob/master/CODE_OF_CONDUCT.md). ## Contributors -This project exists thanks to +This project exists thanks to [all the people who contribute](https://github.com/kivy/plyer/graphs/contributors). [[Become a contributor](CONTRIBUTING.md)]. @@ -134,22 +132,23 @@ This project exists thanks to ## Backers -Thank you to [all of our backers](https://opencollective.com/kivy)! +Thank you to [all of our backers](https://opencollective.com/kivy)! 🙏 [[Become a backer](https://opencollective.com/kivy#backer)] ## Sponsors -Special thanks to +Special thanks to [all of our sponsors, past and present](https://opencollective.com/kivy). -Support this project by +Support this project by [[becoming a sponsor](https://opencollective.com/kivy#sponsor)]. Here are our top current sponsors. Please click through to see their websites, -and support them as they support us. +and support them as they support us. + diff --git a/examples/sysinfo/buildozer.spec b/examples/sysinfo/buildozer.spec new file mode 100644 index 000000000..d5db48c71 --- /dev/null +++ b/examples/sysinfo/buildozer.spec @@ -0,0 +1,173 @@ +[app] + +# (str) Title of your application +title = Plyer Sysinfo Example + +# (str) Package name +package.name = sysinfoexample + +# (str) Package domain (needed for android/ios packaging) +package.domain = org.test + +# (str) Source code where the main.py live +source.dir = . + +# (list) Source files to include (let empty to include all the files) +source.include_exts = py,png,jpg,kv,atlas + +# (list) Source files to exclude (let empty to not exclude anything) +#source.exclude_exts = spec + +# (list) List of directory to exclude (let empty to not exclude anything) +#source.exclude_dirs = tests, bin + +# (list) List of exclusions using pattern matching +#source.exclude_patterns = license,images/*/*.jpg + +# (str) Application versioning (method 1) +# version.regex = __version__ = '(.*)' +# version.filename = %(source.dir)s/main.py + +# (str) Application versioning (method 2) +version = 1.0 + +# (list) Application requirements +requirements = kivy, plyer + +# (str) Presplash of the application +#presplash.filename = %(source.dir)s/data/presplash.png + +# (str) Icon of the application +#icon.filename = %(source.dir)s/data/icon.png + +# (str) Supported orientation (one of landscape, portrait or all) +orientation = portrait + +# (bool) Indicate if the application should be fullscreen or not +fullscreen = 0 + + +# +# Android specific +# + +# (list) Permissions +#android.permissions = + +# (int) Android API to use +#android.api = 14 + +# (int) Minimum API required (8 = Android 2.2 devices) +#android.minapi = 8 + +# (int) Android SDK version to use +#android.sdk = 21 + +# (str) Android NDK version to use +#android.ndk = 9 + +# (bool) Use --private data storage (True) or --dir public storage (False) +#android.private_storage = True + +# (str) Android NDK directory (if empty, it will be automatically downloaded.) +#android.ndk_path = + +# (str) Android SDK directory (if empty, it will be automatically downloaded.) +#android.sdk_path = + +# (str) Android entry point, default is ok for Kivy-based app +#android.entrypoint = org.renpy.android.PythonActivity + +# (list) List of Java .jar files to add to the libs so that pyjnius can access +# their classes. Don't add jars that you do not need, since extra jars can slow +# down the build process. Allows wildcards matching, for example: +# OUYA-ODK/libs/*.jar +#android.add_jars = foo.jar,bar.jar,path/to/more/*.jar + +# (list) List of Java files to add to the android project (can be java or a +# directory containing the files) +#android.add_src = + +# (str) python-for-android branch to use, if not master, useful to try +# not yet merged features. +#android.branch = master + +# (str) OUYA Console category. Should be one of GAME or APP +# If you leave this blank, OUYA support will not be enabled +#android.ouya.category = GAME + +# (str) Filename of OUYA Console icon. It must be a 732x412 png image. +#android.ouya.icon.filename = %(source.dir)s/data/ouya_icon.png + +# (str) XML file to include as an intent filters in tag +#android.manifest.intent_filters = + +# (list) Android additionnal libraries to copy into libs/armeabi +#android.add_libs_armeabi = libs/android/*.so + +# (bool) Indicate whether the screen should stay on +# Don't forget to add the WAKE_LOCK permission if you set this to True +#android.wakelock = False + +# (list) Android application meta-data to set (key=value format) +#android.meta_data = + +# (list) Android library project to add (will be added in the +# project.properties automatically.) +#android.library_references = + +# +# iOS specific +# + +# (str) Name of the certificate to use for signing the debug version +# Get a list of available identities: buildozer ios list_identities +#ios.codesign.debug = "iPhone Developer: ()" + +# (str) Name of the certificate to use for signing the release version +#ios.codesign.release = %(ios.codesign.debug)s + + +[buildozer] + +# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output)) +log_level = 2 + + +# ----------------------------------------------------------------------------- +# List as sections +# +# You can define all the "list" as [section:key]. +# Each line will be considered as a option to the list. +# Let's take [app] / source.exclude_patterns. +# Instead of doing: +# +# [app] +# source.exclude_patterns = license,data/audio/*.wav,data/images/original/* +# +# This can be translated into: +# +# [app:source.exclude_patterns] +# license +# data/audio/*.wav +# data/images/original/* +# + + +# ----------------------------------------------------------------------------- +# Profiles +# +# You can extend section / key with a profile +# For example, you want to deploy a demo version of your application without +# HD content. You could first change the title to add "(demo)" in the name +# and extend the excluded directories to remove the HD content. +# +# [app@demo] +# title = My Application (demo) +# +# [app:source.exclude_patterns@demo] +# images/hd/* +# +# Then, invoke the command line with the "demo" profile: +# +# buildozer --profile demo android debug diff --git a/examples/sysinfo/main.py b/examples/sysinfo/main.py new file mode 100644 index 000000000..7bb7054aa --- /dev/null +++ b/examples/sysinfo/main.py @@ -0,0 +1,133 @@ +from kivy.app import App +from kivy.uix.boxlayout import BoxLayout +from kivy.lang import Builder +from plyer import sysinfo +from kivy.properties import StringProperty, ListProperty + + +Builder.load_string(''' +: + GridLayout: + cols: 2 + Label: + text: "Model" + Label: + text: root.model_ + Label: + text: "Platform" + Label: + text: root.platform_ + Label: + text: "System" + Label: + text: root.system_ + Label: + text: "Processor" + Label: + text: root.processor_ + Label: + text: "Version" + Label: + text: root.version_ + Label: + text: "Architecture" + Label: + text: root.architecture_ + Label: + text: "Device" + Label: + text: root.device_ + Label: + text: "Manufacturer" + Label: + text: root.manufacturer_ + Label: + text: "Kernel" + Label: + text: root.kernel_ + Label: + text: "Storage" + Label: + text: root.storage_ + Label: + text: "Screen" + Label: + text: str(root.screen_) + +''') + + +class SysinfoInterface(BoxLayout): + + model_ = StringProperty() + platform_ = StringProperty() + system_ = StringProperty() + processor_ = StringProperty() + version_ = StringProperty() + architecture_ = StringProperty() + device_ = StringProperty() + manufacturer_ = StringProperty() + kernel_ = StringProperty() + storage_ = StringProperty() + screen_ = ListProperty() + + def __init__(self, **kwargs): + super(SysinfoInterface, self).__init__(**kwargs) + self.update() + + def update(self): + self.get_model() + self.get_platform() + self.get_system() + self.get_processor() + self.get_version() + self.get_architecture() + self.get_device_name() + self.get_manufacturer() + self.get_kernel_version() + self.get_storage_info() + self.get_screen_resolution() + + def get_model(self): + self.model_ = sysinfo.model_info() + + def get_platform(self): + self.platform_ = sysinfo.platform_info() + + def get_system(self): + self.system_ = sysinfo.system_name() + + def get_processor(self): + self.processor_ = sysinfo.processor_info() + + def get_version(self): + temp = sysinfo.version_info() + self.version_ = "{} {} {}".format(temp[0], temp[1], temp[2]) + + def get_architecture(self): + self.architecture_ = str(sysinfo.architecture_info()) + + def get_device_name(self): + self.device_ = sysinfo.device_name() + + def get_manufacturer(self): + self.manufacturer_ = sysinfo.manufacturer_name() + + def get_kernel_version(self): + self.kernel_ = sysinfo.kernel_version() + + def get_storage_info(self): + self.storage_ = sysinfo.storage_info() + + def get_screen_resolution(self): + self.screen_ = sysinfo.screen_resolution() + + +class SysinfoApp(App): + + def build(self): + return SysinfoInterface() + +if __name__ == "__main__": + app = SysinfoApp() + app.run() diff --git a/plyer/__init__.py b/plyer/__init__.py index a66d3e1d4..03724f165 100644 --- a/plyer/__init__.py +++ b/plyer/__init__.py @@ -6,11 +6,11 @@ __all__ = ( 'accelerometer', 'audio', 'barometer', 'battery', 'bluetooth', - 'brightness', 'call', 'camera', 'compass', 'cpu', 'email', 'filechooser', - 'flash', 'gps', 'gravity', 'gyroscope', 'humidity', 'irblaster', + 'brightness', 'call', 'camera', 'compass', 'cpu', 'devicename', 'email', + 'filechooser', 'flash', 'gps', 'gravity', 'gyroscope', 'humidity', 'irblaster', 'keystore', 'light', 'maps', 'notification', 'orientation', 'processors', - 'proximity', 'screenshot', 'sms', 'spatialorientation', 'storagepath', - 'stt', 'temperature', 'tts', 'uniqueid', 'vibrator', 'wifi', 'devicename' + 'proximity', 'screenshot', 'sms', 'sysinfo', 'spatialorientation', + 'storagepath', 'stt', 'temperature', 'tts', 'uniqueid', 'vibrator', 'wifi' ) __version__ = '2.2.0.dev0' @@ -22,9 +22,6 @@ #: Accelerometer proxy to :class:`plyer.facades.Accelerometer` accelerometer = Proxy('accelerometer', facades.Accelerometer) -#: Keyring proxy to :class::`plyer.facades.Keystore` -keystore = Proxy('keystore', facades.Keystore) - #: Audio proxy to :class:`plyer.facades.Audio` audio = Proxy('audio', facades.Audio) @@ -34,14 +31,26 @@ #: Battery proxy to :class:`plyer.facades.Battery` battery = Proxy('battery', facades.Battery) +#: Bluetooth proxy to :class:`plyer.facades.Bluetooth` +bluetooth = Proxy('bluetooth', facades.Bluetooth) + +#: Brightness proxy to :class:`plyer.facades.Brightness` +brightness = Proxy('brightness', facades.Brightness) + #: Call proxy to :class `plyer.facades.Call` call = Proxy('call', facades.Call) +#: Camera proxy to :class:`plyer.facades.Camera` +camera = Proxy('camera', facades.Camera) + #: Compass proxy to :class:`plyer.facades.Compass` compass = Proxy('compass', facades.Compass) -#: Camera proxy to :class:`plyer.facades.Camera` -camera = Proxy('camera', facades.Camera) +#: Processors proxy to :class:`plyer.facades.CPU` +cpu = Proxy('cpu', facades.CPU) + +#: devicename proxy to :class:`plyer.facades.DeviceName` +devicename = Proxy('devicename', facades.DeviceName) #: Email proxy to :class:`plyer.facades.Email` email = Proxy('email', facades.Email) @@ -49,6 +58,9 @@ #: FileChooser proxy to :class:`plyer.facades.FileChooser` filechooser = Proxy('filechooser', facades.FileChooser) +#: Flash proxy to :class:`plyer.facades.Flash` +flash = Proxy('flash', facades.Flash) + #: GPS proxy to :class:`plyer.facades.GPS` gps = Proxy('gps', facades.GPS) @@ -58,27 +70,54 @@ #: Gyroscope proxy to :class:`plyer.facades.Gyroscope` gyroscope = Proxy('gyroscope', facades.Gyroscope) +#: Humidity proxy to :class:`plyer.facades.Humidity` +humidity = Proxy('humidity', facades.Humidity) + #: IrBlaster proxy to :class:`plyer.facades.IrBlaster` irblaster = Proxy('irblaster', facades.IrBlaster) +#: Keyring proxy to :class::`plyer.facades.Keystore` +keystore = Proxy('keystore', facades.Keystore) + #: Light proxy to :class:`plyer.facades.Light` light = Proxy('light', facades.Light) -#: Orientation proxy to :class:`plyer.facades.Orientation` -orientation = Proxy('orientation', facades.Orientation) +#: Maps proxy to :class:`plyer.facades.Maps` +maps = Proxy('maps', facades.Maps) #: Notification proxy to :class:`plyer.facades.Notification` notification = Proxy('notification', facades.Notification) +#: Orientation proxy to :class:`plyer.facades.Orientation` +orientation = Proxy('orientation', facades.Orientation) + +#: Processors proxy to :class:`plyer.facades.Processors` +processors = Proxy('processors', facades.Processors) + #: Proximity proxy to :class:`plyer.facades.Proximity` proximity = Proxy('proximity', facades.Proximity) #: Sms proxy to :class:`plyer.facades.Sms` sms = Proxy('sms', facades.Sms) +#: Screenshot proxy to :class:`plyer.facades.Screenshot` +screenshot = Proxy('screenshot', facades.Screenshot) + +#: Sysinfo proxy to :class:`plyer.facades.Screenshot` +sysinfo = Proxy('sysinfo', facades.Sysinfo) + +#: SpatialOrientation proxy to :class:`plyer.facades.SpatialOrientation` +spatialorientation = Proxy('spatialorientation', facades.SpatialOrientation) + +#: StoragePath proxy to :class:`plyer.facades.StoragePath` +storagepath = Proxy('storagepath', facades.StoragePath) + #: Speech proxy to :class:`plyer.facades.STT` stt = Proxy('stt', facades.STT) +#: Temperature proxy to :class:`plyer.facades.Temperature` +temperature = Proxy('temperature', facades.Temperature) + #: TTS proxy to :class:`plyer.facades.TTS` tts = Proxy('tts', facades.TTS) @@ -88,40 +127,5 @@ #: Vibrator proxy to :class:`plyer.facades.Vibrator` vibrator = Proxy('vibrator', facades.Vibrator) -#: Flash proxy to :class:`plyer.facades.Flash` -flash = Proxy('flash', facades.Flash) - #: Wifi proxy to :class:`plyer.facades.Wifi` wifi = Proxy('wifi', facades.Wifi) - -#: Temperature proxy to :class:`plyer.facades.Temperature` -temperature = Proxy('temperature', facades.Temperature) - -#: Humidity proxy to :class:`plyer.facades.Humidity` -humidity = Proxy('humidity', facades.Humidity) -#: SpatialOrientation proxy to :class:`plyer.facades.SpatialOrientation` -spatialorientation = Proxy('spatialorientation', facades.SpatialOrientation) - -#: Brightness proxy to :class:`plyer.facades.Brightness` -brightness = Proxy('brightness', facades.Brightness) - -#: StoragePath proxy to :class:`plyer.facades.StoragePath` -storagepath = Proxy('storagepath', facades.StoragePath) - -#: Bluetooth proxy to :class:`plyer.facades.Bluetooth` -bluetooth = Proxy('bluetooth', facades.Bluetooth) - -#: Processors proxy to :class:`plyer.facades.Processors` -processors = Proxy('processors', facades.Processors) - -#: Processors proxy to :class:`plyer.facades.CPU` -cpu = Proxy('cpu', facades.CPU) - -#: Screenshot proxy to :class:`plyer.facades.Screenshot` -screenshot = Proxy('screenshot', facades.Screenshot) - -#: devicename proxy to :class:`plyer.facades.DeviceName` -devicename = Proxy('devicename', facades.DeviceName) - -#: Maps proxy to :class:`plyer.facades.Maps` -maps = Proxy('maps', facades.Maps) diff --git a/plyer/facades/__init__.py b/plyer/facades/__init__.py index 5363d9e89..c23f42d00 100644 --- a/plyer/facades/__init__.py +++ b/plyer/facades/__init__.py @@ -6,13 +6,13 @@ ''' -__all__ = ('Accelerometer', 'Audio', 'Barometer', 'Battery', 'Call', 'Camera', - 'Compass', 'Email', 'FileChooser', 'GPS', 'Gravity', 'Gyroscope', - 'IrBlaster', 'Light', 'Orientation', 'Notification', 'Proximity', - 'Sms', 'TTS', 'UniqueID', 'Vibrator', 'Wifi', 'Flash', 'CPU', - 'Temperature', 'Humidity', 'SpatialOrientation', 'Brightness', - 'Processors', 'StoragePath', 'Keystore', 'Bluetooth', 'Screenshot', - 'STT', 'DeviceName', 'Maps') +__all__ = ('Accelerometer', 'Audio', 'Barometer', 'Battery', 'Bluetooth', + 'Brightness', 'Call', 'Camera','CPU', 'Compass', 'DeviceName', + 'Email', 'FileChooser', 'Flash', 'GPS','Gravity', 'Gyroscope', + 'IrBlaster', 'Keystore', 'Light', 'Maps', 'Notification', + 'Orientation', 'Proximity', 'Sms', 'Sysinfo', 'SpatialOrientation', + 'Screenshot', 'StoragePath','STT', 'TTS', 'UniqueID', 'Vibrator', + 'Wifi', 'Temperature', 'Humidity', 'Processors', ) from plyer.facades.accelerometer import Accelerometer from plyer.facades.audio import Audio @@ -34,6 +34,7 @@ from plyer.facades.notification import Notification from plyer.facades.sms import Sms from plyer.facades.stt import STT +from plyer.facades.sysinfo import Sysinfo from plyer.facades.tts import TTS from plyer.facades.uniqueid import UniqueID from plyer.facades.vibrator import Vibrator diff --git a/plyer/facades/sysinfo.py b/plyer/facades/sysinfo.py new file mode 100644 index 000000000..365deb268 --- /dev/null +++ b/plyer/facades/sysinfo.py @@ -0,0 +1,138 @@ +''' +Sysinfo Facade. + ============= + +The :class:`Sysinfo` is to provides system information. +It currently provides model_info, system_name, platform_info, processor_info, +version_info, architecture_info, device_name, manufacturer_name, +kernel_version, storage_info and screen_resolution. + +Usage example +------------- +The following example explains the use case of Sysinfo class:: +#:Python + +from kivy.app import App +from plyer import sysinfo +from kivy.properties import StringProperty + + +class SysinfoInterface(BoxLayout): + + model_ = StringProperty() + + def __init__(self, **kwargs): + super(SysinfoInterface, self).__init__(**kwargs) + self.get_model() + + def get_model(self): + # calling the method to extract the model information of that device. + self.model_ = sysinfo.model_info() + + +class SysinfoApp(App): + + def build(self): + return SysinfoInterface() + +if __name__ == "__main__": + app = SysinfoApp() + app.run() + + +Implementing the UI in kivy language: +------------------------------------------- +#:kivy 1.9.1 + +: + GridLayout: + cols: 2 + Label: + text: "Model" + Label: + text: root.model_ +''' + + +class Sysinfo(object): + ''' Sysinfo facade. + ''' + + def model_info(self): + # returns the model name. + return self._model_info() + + def system_name(self): + # returns the name of system. + return self._system_name() + + def platform_info(self): + # returns platform name including version. + return self._platform_info() + + def processor_info(self): + # returns the processor details + return self._processor_info() + + def version_info(self): + # returns release, version and ptype. + return self._version_info() + + def architecture_info(self): + # returns architecture of device. + return self._architecture_info() + + def device_name(self): + # returns name of the device. + return self._device_name() + + def manufacturer_name(self): + # returns the manufacturer's name + return self._manufacturer_name() + + def kernel_version(self): + # returns the kernel name. + return self._kernel_version() + + def storage_info(self): + # returns the storage capacity o fthe system. + return self._storage_info() + + def screen_resolution(self): + # returns the screen's resolution like 1200x980. + return self._screen_resolution() + + # private + + def _model_info(self): + raise NotImplementedError() + + def _system_name(self): + raise NotImplementedError() + + def _platform_info(self): + raise NotImplementedError() + + def _processor_info(self): + raise NotImplementedError() + + def _version_info(self): + raise NotImplementedError() + + def _architecture_info(self): + raise NotImplementedError() + + def _device_name(self): + raise NotImplementedError() + + def _manufacturer_name(self): + raise NotImplementedError() + + def _kernel_version(self): + raise NotImplementedError() + + def _storage_info(self): + raise NotImplementedError() + + def _screen_resolution(self): + raise NotImplementedError() diff --git a/plyer/platforms/android/sysinfo.py b/plyer/platforms/android/sysinfo.py new file mode 100644 index 000000000..ae7bb9c20 --- /dev/null +++ b/plyer/platforms/android/sysinfo.py @@ -0,0 +1,101 @@ +from jnius import autoclass +from plyer.facades import Sysinfo + +Build = autoclass('android.os.Build') +BuildVersion = autoclass('android.os.Build$VERSION') +BuildVersionCodes = autoclass('android.os.Build$VERSION_CODES') +System = autoclass('java.lang.System') +Environment = autoclass('android.os.Environment') +StatsFs = autoclass('android.os.StatsFs') +DisplayMetrics = autoclass('android.util.DisplayMetrics') + + +class AndroidSysinfo(Sysinfo): + + def _model_info(self): + ''' + Returns the model info for example: + ''' + return Build.MODEL + + def _system_name(self): + ''' + Returns the system's OS name for example: + ''' + return System.getProperty("os.name") + + def _platform_info(self): + ''' + Returns platform's name for example: + ''' + return Build.DEVICE + + def _processor_info(self): + ''' + Returns the type of processor for example: + ''' + return Build.CPU_ABI + + def _version_info(self): + ''' + Returns the version of OS in a tuple for example: + ''' + sdkint = BuildVersion.SDK_INT + version = BuildVersion.RELEASE + try: + fields = BuildVersionCodes.class.getFields() + for field in fields: + fieldName = field.getName() + fieldValue = field.getInt() + + if (fieldValue == sdkint): + return ('Android', str(sdkint), fieldName) + except: + return ('Android', str(sdkint), "UNKNOWN") + + def _architecture_info(self): + ''' + Returns the architecture in a tuple for example: + ''' + return (Build.CPU_ABI, Build.CPU_ABI2) + + def _device_name(self): + ''' + Returns the device name for example: + ''' + return str(Build.MANUFACTURER) + " " + str(Build.MODEL) + + def _manufacturer_name(self): + ''' + Returns the manufacturer's name for example: + ''' + return Build.MANUFACTURER + + def _kernel_version(self): + ''' + Returns the kernel version for example: + ''' + return System.getProperty("os.version") + + def _storage_info(self): + ''' + Returns the amount of storage (RAM) in GB. for example: + ''' + stat = StatsFs(Environment.getDataDirectory().getPath()) + bytesAvailable = stat.getBlockSize() * stat.getBlockCount() + megAvailable = bytesAvailable / 1048576 + return str(megAvailable) + + def _screen_resolution(self): + ''' + Returns the screen resolution for example: + ''' + dm = DisplayMetrics() + getWindowManager.getDefaultDisplay().getMetrics(dm) + wid = int(dm.widthPixels) + hei = int(dm.heightPixels) + return (wid, hei) + + +def instance(): + return AndroidSysinfo() diff --git a/plyer/platforms/ios/libs/sysinfo.m b/plyer/platforms/ios/libs/sysinfo.m new file mode 100644 index 000000000..e4328d1b2 --- /dev/null +++ b/plyer/platforms/ios/libs/sysinfo.m @@ -0,0 +1,47 @@ +#import +#define MB (1024*1024) +#define GB (MB*1024) + + +@interface SizeClass: NSObject { +} +- (int) get_bit_size; +@end + + +@implementation SizeClass + +- (int) get_bit_size { + if (sizeof(void*) == 4) { + return 32; + } + else if (sizeof(void*) == 8){ + return 64; + } +} +@end + + +@interface StorageClass: NSObject { +} +- (double) get_total_space; +@end + + +@implementation StorageClass + +- (double)memoryFormatter:(long long)diskSpace { + double bytes = 1.0 * diskSpace; + double megabytes = bytes / MB; + double gigabytes = bytes / GB; + return gigabytes; +} + +- (double) get_total_space { + long long space = [[[[NSFileManager defaultManager] + attributesOfFileSystemForPath:NSHomeDirectory() error:nil] + objectForKey:NSFileSystemSize] longLongValue]; + return [self memoryFormatter:space]; + } + +@end diff --git a/plyer/platforms/ios/sysinfo.py b/plyer/platforms/ios/sysinfo.py new file mode 100644 index 000000000..95d3f0ae9 --- /dev/null +++ b/plyer/platforms/ios/sysinfo.py @@ -0,0 +1,102 @@ +''' +ios Sysinfo +----------- +''' + +from plyer.facades import Sysinfo +from pyobjus import autoclass +from pyobjus.dylib_manager import load_dylib, make_dylib +import sys +load_framework('/System/Library/Frameworks/UIKit.framework') +make_dylib('plyer/platforms/ios/libs/sysinfo.m', frameworks=['Foundation'], + out='sysinfo.dylib') +load_dylib('sysinfo.dylib') +UIDevice = autoclass('UIDevice') +UIScreen = autoclass('UIScreen') +NSProcessInfo = autoclass('NSProcessInfo') + + +class IosSysinfo(Sysinfo): + + def __init__(self, **kwargs): + super(IosSysinfo, self).__init__(**kwargs) + self.device = UIDevice.currentDevice() + + def _model_info(self): + ''' + Returns the model info for example: + ''' + return self.device.model + + def _system_name(self): + ''' + Returns the system's OS name for example: + ''' + return self.device.systemName + + def _platform_info(self): + ''' + Returns platform's name for example: + ''' + return sys.platform + + def _processor_info(self): + ''' + Returns the type of processor for example: + ''' + return " " + + def _version_info(self): + ''' + Returns the version of OS in a tuple for example: + ''' + return (self.device.systemVersion, " ", " ") + + def _architecture_info(self): + ''' + Returns the architecture in a tuple for example: + ''' + sizeClass = autoclass('SizeClass') + instance = sizeClass.alloc().init() + bit = instance.get_bit_size() + return ("{}".format(bit), " ") + + def _device_name(self): + ''' + Returns the device name for example: + ''' + return self.device.name + + def _manufacturer_name(self): + ''' + Returns the manufacturer's name for example: + ''' + return "Apple Inc." + + def _kernel_version(self): + ''' + Returns the kernel version for example: + ''' + processinfo = NSProcessInfo() + return processinfo.operatingSystemVersionString + + def _storage_info(self): + ''' + Returns the amount of storage (RAM) in GB. for example: + ''' + Storage = autoclass('StorageClass') + instance = Storage.alloc().init() + return str(instance.get_total_space()) + + def _screen_resolution(self): + ''' + Returns the screen resolution for example: + ''' + screen = UIScreen.mainScreen().bounds + width = screen.size.width + height = screen.size.height + return (height, width) + + +def instance(): + return IosSysinfo() diff --git a/plyer/platforms/linux/sysinfo.py b/plyer/platforms/linux/sysinfo.py new file mode 100644 index 000000000..d67268239 --- /dev/null +++ b/plyer/platforms/linux/sysinfo.py @@ -0,0 +1,105 @@ +import platform +import subprocess +from subprocess import Popen, PIPE +from plyer.facades import Sysinfo + + +class LinuxSysinfo(Sysinfo): + + def _model_info(self): + ''' + Returns the model info for example: "VirtualBox" + ''' + command = 'cat /sys/devices/virtual/dmi/id/product_name '.split() + p = Popen(command, stderr=PIPE, stdout=PIPE) + sp = p.communicate()[0] + return sp + + def _system_name(self): + ''' + Returns the system's OS name for example: "Linux" + ''' + return platform.system() + + def _platform_info(self): + ''' + Returns platform's name for example: + "Lunix-4.2.0-36-generic-x86_64-with-Ubuntu-15.10-wily" + ''' + return platform.platform() + + def _processor_info(self): + ''' + Returns the type of processor for example: "x86_64" + ''' + return platform.processor() + + def _version_info(self): + ''' + Returns the version of OS in a tuple for example: + "Ubuntu 15.10 wily" + ''' + return platform.dist() + + def _architecture_info(self): + ''' + Returns the architecture in a tuple for example: "('64bit', 'ELF')" + ''' + return platform.architecture() + + def _device_name(self): + ''' + Returns the device name for example: "kuldeep-virtualbox" + ''' + return platform.uname()[1] + + def _manufacturer_name(self): + ''' + Returns the manufacturer's name for example: "innotek GmnH" + ''' + command = 'cat /sys/devices/virtual/dmi/id/sys_vendor '.split() + p = Popen(command, stderr=PIPE, stdout=PIPE) + sp = p.communicate()[0] + return sp + + def _kernel_version(self): + ''' + Returns the kernel version for example: "4.2.0-32-generic" + ''' + return platform.uname()[2] + + def _storage_info(self): + ''' + Returns the amount of storage (RAM) in GB. for example: "1.43 GB" + ''' + meminfo = {} + + with open('/proc/meminfo') as f: + for line in f: + meminfo[line.split(':')[0]] = line.split(':')[1].strip() + try: + memory, unit = meminfo['MemTotal'].split(' ') + if (unit.lower() == "kb"): + return str(round(int(memory) / (1024.0 * 1024.0), 2)) + " GB" + elif (unit.lower() == "mb"): + return str(round(int(memory) / (1024.0), 2)) + " GB" + elif (unit.lower() == "gb"): + return str(int(memory)) + " GB" + except: + return str(meminfo['MemTotal']) + + def _screen_resolution(self): + ''' + Returns the screen resolution for example: "[1920, 975]" + ''' + sd = Popen('xrandr | grep "\*" | cut -d" " -f4', + shell=True, + stdout=PIPE).communicate()[0] + + a = sd.split('x')[0] + b = sd.split('x')[1].split('\n')[0] + return (int(a), int(b)) + + +def instance(): + return LinuxSysinfo() diff --git a/plyer/platforms/macosx/sysinfo.py b/plyer/platforms/macosx/sysinfo.py new file mode 100644 index 000000000..cf21535ba --- /dev/null +++ b/plyer/platforms/macosx/sysinfo.py @@ -0,0 +1,101 @@ +import platform +import subprocess +from subprocess import Popen, PIPE +from plyer.facades import Sysinfo + + +class OSXSysinfo(Sysinfo): + + def _model_info(self): + ''' + Returns the model info for example: "MacBookPro11,4" + ''' + mi = Popen("system_profiler SPHardwareDataType | grep Model\ " + + "Identifier", + shell=True, + stdout=PIPE).communicate()[0] + mi = mi.decode('utf-8').split('Model Identifier: ')[1][:-1] + return mi + + def _system_name(self): + ''' + Returns the system's OS name for example: "Darwin" + ''' + return platform.system() + + def _platform_info(self): + ''' + Returns platform's name for ecample: + "Darwin-15.5.0-x86_64-i386-64bit" + ''' + return platform.platform() + + def _processor_info(self): + ''' + Returns the type of processor for example: "i386" + ''' + return platform.processor() + + def _version_info(self): + ''' + Returns the version of OS in a tuple for example: + "10.11.5 (",",") x84_64" + ''' + return platform.mac_ver() + + def _architecture_info(self): + ''' + Returns the architecture in a tuple for example: "('64bit', ")" + ''' + return platform.architecture() + + def _device_name(self): + ''' + Returns the device name for example: "Kuldeeps-MacBook-Pro.local" + ''' + return platform.uname()[1] + + def _manufacturer_name(self): + ''' + Returns the manufacturer's name for example: "Apple Inc." + ''' + mn = Popen('system_profiler SPHardwareDataType|grep Chip', + shell=True, + stdout=PIPE).communicate()[0] + + mn = mn.decode('utf-8').split('Chip: ') + mn = mn[1].split('\n') + return mn[0].split(' ')[0] + + def _kernel_version(self): + ''' + Returns the kernel version for example: "15.5.0" + ''' + return platform.uname()[2] + + def _storage_info(self): + ''' + Returns the amount of storage (RAM) in GB. for example: "16 GB" + ''' + si = Popen('system_profiler SPHardwareDataType | grep Memory', + shell=True, + stdout=PIPE).communicate()[0] + si = si.split('Memory: ')[1].split(' ')[0] + return str(si) + " GB" + + def _screen_resolution(self): + ''' + Returns the screen resolution for example: "[2880, 1800]" + ''' + sd = Popen('system_profiler SPDisplaysDataType | grep Resolution', + shell=True, + stdout=PIPE).communicate()[0].decode('utf-8') + sd = sd.split('Resolution:')[1] + sd = sd.split(' ') + sd1 = sd[1] + sd2 = sd[3] + return (int(sd1), int(sd2)) + + +def instance(): + return OSXSysinfo() diff --git a/plyer/platforms/win/libs/win_api_defs.py b/plyer/platforms/win/libs/win_api_defs.py index dcf116b6f..1079c16f9 100755 --- a/plyer/platforms/win/libs/win_api_defs.py +++ b/plyer/platforms/win/libs/win_api_defs.py @@ -6,7 +6,7 @@ 'DefWindowProcW', 'get_WNDCLASSEXW', 'GetModuleHandleW', 'RegisterClassExW', 'UpdateWindow', 'LoadImageW', 'Shell_NotifyIconW', 'DestroyIcon', 'UnregisterClassW', - 'DestroyWindow', 'LoadIconW', 'get_PATH') + 'DestroyWindow', 'LoadIconW', 'get_PATH', 'GetSystemMetrics') import ctypes from ctypes import Structure, windll, sizeof, POINTER, WINFUNCTYPE @@ -45,6 +45,10 @@ def get_DLLVERSIONINFO(*largs): return version_info +def GetSystemMetrics(*largs): + return windll.User32.GetSystemMetrics(largs[0]) + + def MAKEDLLVERULL(major, minor, build, sp): return (major << 48) | (minor << 32) | (build << 16) | sp diff --git a/plyer/platforms/win/sysinfo.py b/plyer/platforms/win/sysinfo.py new file mode 100644 index 000000000..80831f48c --- /dev/null +++ b/plyer/platforms/win/sysinfo.py @@ -0,0 +1,129 @@ +import platform +import os +import re +from subprocess import Popen, PIPE +from plyer.facades import Sysinfo +from plyer.platforms.win.libs import win_api_defs + + +class WindowsSysinfo(Sysinfo): + + values = {} + + def _ensure_sysinfo(self): + ''' + Helping private method for extracting system information. + ''' + + cache = os.popen2("SYSTEMINFO") + source = cache[1].read() + sysOpts = ["System Manufacturer", "System Model", + "Total Physical Memory"] + + for opt in sysOpts: + self.values[opt] = [item.strip() for item in + re.findall("%s:\w*(.*?)\n" % (opt), + source, re.IGNORECASE)][0] + return self.values + + def _model_info(self): + ''' + Returns Model information for example: "HP 2000 Notebook PC" + ''' + if 'System Model' in self.values: + return self.values['System Model'] + return self._ensure_sysinfo()['System Model'] + + def _system_name(self): + ''' + Returns System's OS name for example: "Windows" + ''' + return platform.system() + + def _platform_info(self): + ''' + Returns the platform's name for example: "Windows-8-6.2.9200" + ''' + return platform.platform() + + def _processor_info(self): + ''' + Returns the type of processor for example: + "Intel64 Family 6 Model 42 Stepping 7, GenuineIntel" + ''' + return platform.processor() + + def _version_info(self): + ''' + Returns the version of OS in a tuple for example: + "8 6.2.9200 " + ''' + return platform.win32_ver() + + def _architecture_info(self): + ''' + Returns the architecture in a tuple, for example: + "('32bit', "WindowsPE")"" + ''' + return platform.architecture() + + def _device_name(self): + ''' + Returns the device's name, for example: "DESKTOP-8UFTHDN" + ''' + return platform.uname()[1] + + def _manufacturer_name(self, **kwargs): + ''' + Returns manufacturer's name, for example: "Hewlett-Packard" + ''' + if 'System Manufacturer' in self.values: + return self.values['System Manufacturer'] + return self._ensure_sysinfo()['System Manufacturer'] + + def _kernel_version(self): + ''' + Returns the kernel version, for example: "8" + ''' + return platform.uname()[2] + + def _storage_info(self): + ''' + Returns the amount of storage (RAM) in GB for example: "3.9 GB" + + Note: The returned output from `os.popen2("SYSTEMINFO")` is string, + with `,`(commas) between integer values(in MB) but the output should + be same for each platform, hence in GB. + ''' + try: + if 'Total Physical Memory' in self.values: + storage = self.values['Total Physical Memory'] + else: + storage = self._ensure_sysinfo()['Total Physical Memory'] + memory, unit = storage.split(' ') + try: + temp = '' + for i in memory.split(','): + temp = temp + i + memory = temp + except: + pass + if (unit.lower() == "kb"): + return str(round(int(memory) / (1024.0 * 1024.0), 2)) + " GB" + elif (unit.lower() == "mb"): + return str(round(int(memory) / 1024.0, 2)) + " GB" + elif (unit.lower() == "gb"): + return str(int(memory)) + " GB" + except: + return self._ensure_sysinfo()['Total Physical Memory'] + + def _screen_resolution(self): + ''' + Returns the screen resolution for example: "[1366, 768]" + ''' + return (win_api_defs.GetSystemMetrics(0), + win_api_defs.GetSystemMetrics(1)) + + +def instance(): + return WindowsSysinfo()