-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
131 lines (114 loc) · 4.49 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
''' hwiopy: A common API for hardware input/output access.
hwiopy, "hardware input/output, python", is a general purpose IO library
intended to provide a common, simple python API to physical systems,
particularly ones running embedded linux. The hope is to allow a single,
unified codebase to run on multiple hardware platforms with minimal (if any)
modification. Early development targets include the Beaglebone Black and
Raspberry Pi.
'''
# Global dependencies
import subprocess
from warnings import warn
# Bootstrap setuptools
import ez_setup
# Dunno why I need this but I think I do?
# try:
# del pkg_resources, setuptools
# except NameError:
# pass
# Carry on then
ez_setup.use_setuptools()
# Import global dependencies required for setup.py
from setuptools import setup, find_packages
metadata = dict(
name = 'hwiopy',
version = '0.1.2',
description = 'A common API for hardware input/output access.',
long_description = 'hwiopy, "hardware input/output, python", '
'is a general purpose IO library intended to provide a common, simple '
'python API to physical systems, particularly ones running embedded '
'linux. The hope is to allow a single, unified codebase to run on '
'multiple hardware platforms with minimal (if any) modification. Early '
'development targets include the Beaglebone Black and Raspberry Pi.',
url = 'https://github.com/Badg/hwiopy',
author = 'Nick Badger',
author_email = '[email protected]',
license = 'GNU LGPL v2.1',
classifiers = [
'Development Status :: 2 - Pre-Alpha',
'Intended Audience :: Developers',
'Intended Audience :: Education',
'Intended Audience :: Science/Research',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.3',
'Topic :: Home Automation',
'Topic :: Scientific/Engineering',
'Topic :: Software Development :: Embedded Systems',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: System :: Hardware'
],
keywords = 'hardware io input output embedded',
packages = find_packages(exclude=['doc', 'test']),
install_requires = [],
package_data = {
# Include any .json files in the maps directory
'hwiopy': ['maps/*.json', 'overlays/*', 'setup_utils/*'],
})
def get_platform():
''' Figures out what platform the library is being installed onto for
deciding what install script to run.
'''
# This will complain about not being sudo but it shouldn't matter
try:
# Get the system hardware string and convert it into a string
hw_str = subprocess.check_output(['lshw'],
stderr=subprocess.DEVNULL).decode()
hw_list = hw_str.split('\n')
# Quick. Dirty. Whatevs. Make better later.
# Try to autodetect the hardware platform. Currently only works on the
# beaglebone black. Currently also pretty damn janky.
am355 = None
beaglebone = None
for line in hw_list:
if line.lower().find('am335') >= 0:
am355 = True
if line.lower().find('beaglebone') >= 0:
beaglebone = True
# If we found both am355 and beaglebone, then it's a BBB
if am355 and beaglebone:
return {'name': 'bbb', 'system': 'AM335x'}
else:
return False
# If that doesn't work, we're just going to go with "platform unknown!"
except OSError:
return False
def setup_device(platform_info):
''' Handle creation of any necessary device tree overlays, etc.
'''
# First figure out what platform we're on
# Currently this only does specialized code on the BBB
if platform_info['name'] == 'bbb':
# Grab the platform-specific setup library
import platform_setup
platform_setup.bbb_setup.do()
# Return True for successful config
def setup_generic():
''' Handles setting up of a generic device.
'''
warn(RuntimeWarning('Could not autodetect platform. Continuing with '
'standard installation.'))
return True
if __name__ == '__main__':
import sys
# First make sure we're installing.
if sys.argv[1] == 'install':
# Get the platform.
platform_info = get_platform()
# If unknown, returns False.
if not platform_info:
setup_generic()
# Otherwise, we have information to go off of.
else:
setup_device(platform_info)
# Now call setup.
setup(**metadata)