forked from KyleBenson/scale_client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup_mesh.py
executable file
·82 lines (72 loc) · 2.58 KB
/
setup_mesh.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
#!/usr/bin/env python
import time
import os, errno
from setuptools import setup, find_packages
# Generic info about package
NAME = "scale_client"
VERSION = "0.3"
DESC = "Safe Community Awareness and Alerting Network (SCALE) client"
AUTHOR = "Kyle Benson"
AUTHOR_EMAIL = "[email protected]"
URL = "https://github.com/KyleBenson/scale_client"
# Specific information about package contents
# PACKAGES = ["scale_client", "scale_client.core",
# "scale_client.sensors", "scale_client.event_sinks",
# "scale_client.applications"]
PACKAGE_DATA = {"scale_client": ["config/*"]}
DAEMON_LOCATION = "/etc/init.d"
CONFIG_LOCATION = "/etc/scale/client"
data_files = []
# Setup mesh network with Batman and Avahi script
SETUP_MESH_NETWORK_SCRIPT = os.getcwd() + "/scripts/network/setup_mesh_network.sh"
# Gather requires info from requirements.txt
with open('requirements.txt') as F:
requirements = [l.strip() for l in F.readlines() if not l.startswith("#")]
# Make config location
# http://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else: raise
try:
mkdir_p(CONFIG_LOCATION)
except OSError:
pass
try:
with open(CONFIG_LOCATION + "/mesh_pi_config.yml", "a") as F:
pass
data_files.append((CONFIG_LOCATION, ["scale_client/config/mesh_pi_config.yml"]))
except IOError:
print "Can't access config location. Skipping config example installation..."
# Setup mesh network for the SCALE client
try:
subprocess.call(SETUP_MESH_NETWORK_SCRIPT, shell=True)
time.sleep(10)
# Sleep for 10 seconds to make sure Batman and Avahi Ip assignment
# have been setup properly before starting scale daemon
except IOError:
print "Failed to setup mesh network for the pi"
# Check whether we will be able to install the daemon or not
try:
with open(DAEMON_LOCATION + "/scale_daemon", 'a') as F:
pass
data_files.append((DAEMON_LOCATION, ["scripts/scale_daemon"]))
subprocess.call("update-rc.d scale_daemon defaults", shell=True)
subprocess.call("/etc/init.d/scale_daemon start", shell=True)
except IOError:
print "Can't access daemon location. Skipping daemon installation..."
setup(name=NAME,
version=VERSION,
description=DESC,
author=AUTHOR,
author_email=AUTHOR_EMAIL,
url=URL,
# packages=PACKAGES,
packages=find_packages(),
package_data=PACKAGE_DATA,
data_files=data_files,
install_requires=requirements,
)