Browse Source

initial commit

Brennen Bearnes 9 months ago
commit
0b994dcdd3
7 changed files with 230 additions and 0 deletions
  1. 74
    0
      CODE_OF_CONDUCT.md
  2. 21
    0
      LICENSE
  3. 0
    0
      README.rst
  4. 84
    0
      adafruit_platformdetect.py
  5. 0
    0
      requirements.txt
  6. 46
    0
      setup.py
  7. 5
    0
      test/detect.py

+ 74
- 0
CODE_OF_CONDUCT.md View File

@@ -0,0 +1,74 @@
1
+# Contributor Covenant Code of Conduct
2
+
3
+## Our Pledge
4
+
5
+In the interest of fostering an open and welcoming environment, we as
6
+contributors and maintainers pledge to making participation in our project and
7
+our community a harassment-free experience for everyone, regardless of age, body
8
+size, disability, ethnicity, gender identity and expression, level of experience,
9
+nationality, personal appearance, race, religion, or sexual identity and
10
+orientation.
11
+
12
+## Our Standards
13
+
14
+Examples of behavior that contributes to creating a positive environment
15
+include:
16
+
17
+* Using welcoming and inclusive language
18
+* Being respectful of differing viewpoints and experiences
19
+* Gracefully accepting constructive criticism
20
+* Focusing on what is best for the community
21
+* Showing empathy towards other community members
22
+
23
+Examples of unacceptable behavior by participants include:
24
+
25
+* The use of sexualized language or imagery and unwelcome sexual attention or
26
+advances
27
+* Trolling, insulting/derogatory comments, and personal or political attacks
28
+* Public or private harassment
29
+* Publishing others' private information, such as a physical or electronic
30
+  address, without explicit permission
31
+* Other conduct which could reasonably be considered inappropriate in a
32
+  professional setting
33
+
34
+## Our Responsibilities
35
+
36
+Project maintainers are responsible for clarifying the standards of acceptable
37
+behavior and are expected to take appropriate and fair corrective action in
38
+response to any instances of unacceptable behavior.
39
+
40
+Project maintainers have the right and responsibility to remove, edit, or
41
+reject comments, commits, code, wiki edits, issues, and other contributions
42
+that are not aligned to this Code of Conduct, or to ban temporarily or
43
+permanently any contributor for other behaviors that they deem inappropriate,
44
+threatening, offensive, or harmful.
45
+
46
+## Scope
47
+
48
+This Code of Conduct applies both within project spaces and in public spaces
49
+when an individual is representing the project or its community. Examples of
50
+representing a project or community include using an official project e-mail
51
+address, posting via an official social media account, or acting as an appointed
52
+representative at an online or offline event. Representation of a project may be
53
+further defined and clarified by project maintainers.
54
+
55
+## Enforcement
56
+
57
+Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+reported by contacting the project team at support@adafruit.com. All
59
+complaints will be reviewed and investigated and will result in a response that
60
+is deemed necessary and appropriate to the circumstances. The project team is
61
+obligated to maintain confidentiality with regard to the reporter of an incident.
62
+Further details of specific enforcement policies may be posted separately.
63
+
64
+Project maintainers who do not follow or enforce the Code of Conduct in good
65
+faith may face temporary or permanent repercussions as determined by other
66
+members of the project's leadership.
67
+
68
+## Attribution
69
+
70
+This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+[homepage]: http://contributor-covenant.org
74
+[version]: http://contributor-covenant.org/version/1/4/

+ 21
- 0
LICENSE View File

@@ -0,0 +1,21 @@
1
+The MIT License (MIT)
2
+
3
+Copyright (c) 2018 Adafruit Industries
4
+
5
+Permission is hereby granted, free of charge, to any person obtaining a copy
6
+of this software and associated documentation files (the "Software"), to deal
7
+in the Software without restriction, including without limitation the rights
8
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+copies of the Software, and to permit persons to whom the Software is
10
+furnished to do so, subject to the following conditions:
11
+
12
+The above copyright notice and this permission notice shall be included in all
13
+copies or substantial portions of the Software.
14
+
15
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+SOFTWARE.

+ 0
- 0
README.rst View File


+ 84
- 0
adafruit_platformdetect.py View File

@@ -0,0 +1,84 @@
1
+# Copyright (c) 2014-2018 Adafruit Industries
2
+# Author: Tony DiCola, Limor Fried, Brennen Bearnes
3
+
4
+# Permission is hereby granted, free of charge, to any person obtaining a copy
5
+# of this software and associated documentation files (the "Software"), to deal
6
+# in the Software without restriction, including without limitation the rights
7
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+# copies of the Software, and to permit persons to whom the Software is
9
+# furnished to do so, subject to the following conditions:
10
+
11
+# The above copyright notice and this permission notice shall be included in all
12
+# copies or substantial portions of the Software.
13
+
14
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+# SOFTWARE.
21
+
22
+"""
23
+Attempt to detect the current platform.
24
+"""
25
+import sys
26
+import platform
27
+import re
28
+
29
+class PlatformDetect:
30
+
31
+    def is_raspberrypi(self):
32
+        return true
33
+
34
+    def is_linux(self):
35
+        return true
36
+
37
+    def pi_revision_code(self):
38
+        """Detect the version of the Raspberry Pi.  Returns either 1, 2 or
39
+        None depending on if it's a Raspberry Pi 1 (model A, B, A+, B+),
40
+        Raspberry Pi 2 (model B+), or not a Raspberry Pi.
41
+        """
42
+        # Check /proc/cpuinfo for the Hardware field value.
43
+        # 2708 is Pi 1
44
+        # 2709 is Pi 2
45
+        # 2835 is Pi 3 (or greater) on 4.9.x kernel
46
+        # Anything else is not a Pi.
47
+        with open('/proc/cpuinfo', 'r') as infile:
48
+            cpuinfo = infile.read()
49
+        # Match a line like 'Hardware   : BCM2709'
50
+        match = re.search(r'^Hardware\s+:\s+(\w+)$', cpuinfo,
51
+                          flags=re.MULTILINE | re.IGNORECASE)
52
+
53
+        if not match:
54
+            # Couldn't find the hardware, assume it isn't a pi.
55
+            return None
56
+
57
+        if match.group(1) not in ('BCM2708', 'BCM2709', 'BCM2835'):
58
+            # Something else, not a pi.
59
+            return None
60
+
61
+        rev_match = re.search(r'^Revision\s+:\s+(\w+)$', cpuinfo,
62
+                              flags=re.MULTILINE | re.IGNORECASE)
63
+        if rev_match:
64
+            return rev_match.group(1)
65
+
66
+        return None
67
+
68
+#   0002    B   1.0     256 MB  Egoman
69
+#   0003    B   1.0     256 MB  Egoman
70
+#   0004    B   2.0     256 MB  Sony UK
71
+#   0005    B   2.0     256 MB  Qisda
72
+#   0006    B   2.0     256 MB  Egoman
73
+#   0007    A   2.0     256 MB  Egoman
74
+#   0008    A   2.0     256 MB  Sony UK
75
+#   0009    A   2.0     256 MB  Qisda
76
+#   000d    B   2.0     512 MB  Egoman
77
+#   000e    B   2.0     512 MB  Sony UK
78
+#   000f    B   2.0     512 MB  Egoman
79
+#   0010    B+  1.0     512 MB  Sony UK
80
+#   0011    CM1     1.0     512 MB  Sony UK
81
+#   0012    A+  1.1     256 MB  Sony UK
82
+#   0013    B+  1.2     512 MB  Embest
83
+#   0014    CM1     1.0     512 MB  Embest
84
+#   0015    A+  1.1     256 MB / 512 MB     Embest

+ 0
- 0
requirements.txt View File


+ 46
- 0
setup.py View File

@@ -0,0 +1,46 @@
1
+#!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
3
+
4
+# Note: To use the 'upload' functionality of this file, you must:
5
+#   $ pip install twine
6
+
7
+import io
8
+import os
9
+import sys
10
+
11
+from setuptools import setup, find_packages
12
+
13
+here = os.path.abspath(os.path.dirname(__file__))
14
+
15
+# Import the README and use it as the long-description.
16
+# Note: this will only work if 'README.md' is present in your MANIFEST.in file!
17
+with io.open(os.path.join(here, 'README.rst'), encoding='utf-8') as f:
18
+    long_description = '\n' + f.read()
19
+
20
+setup(
21
+    name='Adafruit-PlatformDetect',
22
+    use_scm_version=True,
23
+    setup_requires=["setuptools_scm"],
24
+    description='Platform detection for use by libraries like Adafruit-Blinka.',
25
+    long_description=long_description,
26
+    long_description_content_type='text/x-rst',
27
+    author='Adafruit Industries',
28
+    author_email='circuitpython@adafruit.com',
29
+    python_requires='>=3.4.0',
30
+    url='https://github.com/adafruit/Adafruit_Python_PlatformDetect',
31
+    package_dir={'': 'src'},
32
+    packages=find_packages("src"),
33
+    # If your package is a single module, use this instead of 'packages':
34
+    py_modules=['adafruit_platformdetect'],
35
+    install_requires=[],
36
+    license='MIT',
37
+    classifiers=[
38
+        # Trove classifiers
39
+        # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
40
+        'License :: OSI Approved :: MIT License',
41
+        'Programming Language :: Python',
42
+        'Programming Language :: Python :: 3',
43
+        'Programming Language :: Python :: 3.4',
44
+        'Programming Language :: Python :: Implementation :: MicroPython',
45
+    ],
46
+)

+ 5
- 0
test/detect.py View File

@@ -0,0 +1,5 @@
1
+from adafruit_platformdetect import PlatformDetect
2
+
3
+detect = PlatformDetect()
4
+
5
+print(detect.pi_revision_code())

Loading…
Cancel
Save