-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·43 lines (34 loc) · 1.25 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
#!/usr/bin/python
import os
import subprocess
pipPkg = ['requests', 'paho-mqtt']
dirs = ['log']
def installPipPkg(package):
procInstall = subprocess.Popen(['pip', 'install', package], stderr=subprocess.PIPE)
procInstallPipe = procInstall.communicate()
if '--upgrade' in str(procInstallPipe):
print('Upgrading PIP to the latest version')
procUpgrade = subprocess.Popen(['pip', 'install', '--upgrade', 'pip'])
def checkPipPkg(pkg):
procList = subprocess.Popen(['pip', 'freeze'], stdout=subprocess.PIPE)
procGrep = subprocess.Popen(['grep', pkg], stdin=procList.stdout, stdout=subprocess.PIPE)
procList.stdout.close()
procGrepPipe = procGrep.communicate()[0]
if procGrepPipe:
return True
else:
return False
print('Checking / Installing required packages')
for pkg in pipPkg:
if not checkPipPkg(pkg):
print('Installing package %s' %pkg)
installPipPkg(pkg)
else:
print('Package %s installed already' %pkg)
print('Creating directories')
for directory in dirs:
os.system('mkdir ' + directory)
print('Renaming config template file')
os.system('mv config/config-template.json config/config.json')
print('Creating empty wlans.json file')
os.system('echo "{}" > wlans.json')