Repository navigation
Expand file tree
/
Copy pathdeploy.py
More file actions
executable file
·86 lines (67 loc) · 2.59 KB
/
Copy pathdeploy.py
File metadata and controls
executable file
·86 lines (67 loc) · 2.59 KB
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
#!/usr/bin/env python3
'''
Description - An auto-generated stub description.
'''
import argparse
import logging
import os
from fabric.api import cd
from fabric.api import env
from fabric.api import put
from fabric.api import run
from fabric.api import sudo
logger = logging.getLogger(__name__)
DEPLOY_DIR = '/opt/Piduino'
ARDUINO_SUBDIR = 'arduino'
RASPI_SUBDIR = 'pi'
ARDUINO_INSTALL_DIR = '/opt/arduino/current/'
def parse_args(argv=None):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
'hostname',
help='The hostname (or ip address) of the target Raspberry Pi')
parser.add_argument(
'--project_dir',
required=False,
default=os.getcwd(),
help='The directory containing the required Python, ' \
'Arduino, and requirements3.txt files')
# parser.add_argument('--bar', required=False)
# If `argv` is None, `parse_args` will default to using `sys.argv`
return parser.parse_args(args=argv)
def main(argv=None):
args = parse_args(argv)
# do some work
args.project_dir = os.path.abspath(args.project_dir)
project_name = os.path.basename(args.project_dir)
logger.info('Deploying project: %s', project_name)
env.user = 'root'
env.host_string = '{}:22'.format(args.hostname)
run('mkdir -p {}'.format(DEPLOY_DIR))
with cd(DEPLOY_DIR):
run('rm -rf {}/{} | true'.format(DEPLOY_DIR, project_name))
put(args.project_dir, DEPLOY_DIR)
put(os.path.abspath('arduino/libraries'), DEPLOY_DIR)
with cd(os.path.join(DEPLOY_DIR, project_name)):
run('mkdir -p build')
run('pwd; ~/Go/bin/arduino-builder ' \
'--hardware {arduino_dir}/hardware '\
'--tools {arduino_dir}/hardware/tools/ ' \
'--tools {arduino_dir}/tools-builder/ ' \
'--libraries {arduino_dir}/libraries/ ' \
'--libraries {piduino_dir}/libraries ' \
'-fqbn arduino:avr:nano:cpu=atmega328 ' \
'--build-path $PWD/build/ ' \
'--verbose arduino/arduino.ino'.format(
arduino_dir=ARDUINO_INSTALL_DIR,
piduino_dir=DEPLOY_DIR))
sudo('avrdude ' \
'-p atmega328p ' \
'-C ~/GitHub/Piduino/avrdude_gpio.conf ' \
'-c pi_1 -v -U flash:w:build/arduino.ino.hex:i')
with cd(os.path.join(DEPLOY_DIR, project_name, 'pi')):
run('pipenv --python 3.5.3 install')
run('pipenv run python3 main.py')
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
main()