Przeglądaj źródła

included vehicle and board options, organised directories

willpiper 4 lat temu
rodzic
commit
db8a963981
2 zmienionych plików z 73 dodań i 28 usunięć
  1. 55 26
      app.py
  2. 18 2
      templates/index.html

+ 55 - 26
app.py

@@ -6,6 +6,7 @@ import urllib.request
 import gzip
 from io import BytesIO
 import time
+import json
 
 from flask import Flask # using flask as the framework
 from flask import render_template
@@ -68,11 +69,26 @@ def compressFiles(fileList, uuidkey):
 def index():
     return render_template('index.html')
 
+def run_build(taskfile):
+    # run a build with parameters from task
+    task = json.loads(open(taskfile).read())
+    builddir = '/tmp/build'
+    subprocess.run(['./waf', 'configure', 
+                    '--board', task['board'], 
+                    '--out', builddir, 
+                    '--extra-hwdef', task['extra_hwdef']],
+                    cwd = task['sourcedir'])
+    subprocess.run(['./waf', 'clean'], cwd = task['sourcedir'])
+    subprocess.run(['./waf', task['vehicle']], cwd = task['sourcedir'])
+
+
 @app.route('/generate', methods=['GET', 'POST'])
 def generate():
     if request.method == 'POST':
-        # request.form['username']
         features = []
+        task = {}
+
+        # fetch features from user input
         for i in range(1,8):
             value = request.form["option" + str(i)]
             features.append(value)
@@ -82,36 +98,49 @@ def generate():
 
         print("features: ", features)
 
-        print("running...")
-
-        file = open('extra_hwdef.dat',"w")
-        
+        # create extra_hwdef.dat file and obtain md5sum
+        file = open('buildqueue/extra_hwdef.dat',"w")
         file.write(extra_hwdef)
         file.close()
+        md5sum = subprocess.check_output(['md5sum', 'buildqueue/extra_hwdef.dat'],
+                                            encoding = 'utf-8')
+        md5sum = md5sum[:len(md5sum)-29]
+        os.remove('buildqueue/extra_hwdef.dat')
 
-        git_hash = subprocess.check_output(['git', 'rev-parse', 'master'])
-        git_hash = git_hash[:len(git_hash)-1]
+        # define source and app directories
+        sourcedir = os.path.abspath('../ardupilot/')
+        appdir = os.path.abspath(os.curdir)
 
-        md5sum = subprocess.check_output(['md5sum', 'extra_hwdef.dat'])
-        md5sum = md5sum[:len(md5sum)-18]
+        # obtain git-hash of source
+        git_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD'], 
+                                            cwd = sourcedir,
+                                            encoding = 'utf-8')
+        git_hash = git_hash[:len(git_hash)-1]
 
-        builddir = '/tmp/build'
-        sourcedir = '../ardupilot/'
-        appdir = os.path.abspath(os.curdir)
-        board = 'Beastf7'
-        subprocess.run(['./waf', 'configure', 
-                        '--board', board, 
-                        '--out', builddir, 
-                        '--extra-hwdef', os.path.join(appdir, 'extra_hwdef.dat')],
-                        cwd = sourcedir)
-        subprocess.run(['./waf', 'copter'], cwd = sourcedir)
-
-        print("git hash: ", git_hash)
-        print("md5sum: ", md5sum)
-        print("token: ", git_hash+md5sum)
-
-        # UUID for this terrain generation
-        uuidkey = str(uuid.uuid1())
+        # create directories using concatenated token of git-hash and md5sum of hwdef
+        token = git_hash + "-" + md5sum
+        extra_hwdef_dir = os.path.join(appdir, 'buildqueue/{}'.format(token))
+        if not os.path.isdir(extra_hwdef_dir):
+            os.mkdir(extra_hwdef_dir)
+        file = open('{}/extra_hwdef.dat'.format(extra_hwdef_dir),"w")
+        file.write(extra_hwdef)
+        file.close()
+        
+        # fill dictionary of variables and create json file
+        task['hwdef_md5sum'] = md5sum
+        task['git_hash'] = git_hash
+        task['sourcedir'] = sourcedir
+        task['extra_hwdef'] = os.path.join(extra_hwdef_dir, 'extra_hwdef.dat')
+        task['board'] = request.form["board"]
+        task['vehicle'] = request.form["vehicle"]
+        jfile = open('q.json', "w")
+        jfile.write(json.dumps(task))
+        jfile.close()
+
+        print(task)
+
+        # run build
+        run_build('q.json')
 
 
         # remove duplicates

+ 18 - 2
templates/index.html

@@ -5,12 +5,28 @@
         <title>ArduPilot Custom Firmware Builder</title>
         <h1>ArduPilot Custom Firmware Builder</h1>
 
-        <p>Please select features to be included in the reduced firmware build.</p>
+        <p>Please select the required options for the reduced firmware build.</p>
         
         <!--<p>To download entire continents of terrain data, see <a href=https://terrain.ardupilot.org/data/continents/>here<a>.</p>-->
 
-        <h2>Available Features</h2>
         <form action="/generate" method="post">
+            <label for="vehicle">Choose a vehicle:</label>
+            <select name="vehicle">
+                <option value="copter">Copter</option>
+                <option value="plane">Plane</option>
+                <option value="rover">Rover</option>
+                <option value="sub">Sub</option>
+            </select>
+            <br><br>
+            <label for="board">Choose a board:</label>
+            <select name="board">
+                <option value="aero">aero</option>
+                <option value="airbotf4">airbotf4</option>
+                <option value="bbbmini">bbbmini</option>
+                <option value="BeastF7">BeastF7</option>
+                <option value="BeastH7">BeastH7</option>
+            </select>
+            <br><br>
             <input type="checkbox" name="option1" value="define HAL_NAVEKF2_AVAILABLE 1">
             <input type="hidden" name="option1" value="define HAL_NAVEKF2_AVAILABLE 0"> EKF2
             <br>