فهرست منبع

Display correct board and build options for chosen branch

Michelle Rossouw 3 سال پیش
والد
کامیت
ad86906a40
3فایلهای تغییر یافته به همراه167 افزوده شده و 85 حذف شده
  1. 27 19
      app.py
  2. 3 66
      templates/index.html
  3. 137 0
      templates/index2.html

+ 27 - 19
app.py

@@ -25,6 +25,7 @@ VEHICLES = [ 'Copter', 'Plane', 'Rover', 'Sub', 'Tracker', 'Blimp', 'Heli']
 default_vehicle = 'Copter'
 BRANCHES = ['upstream/master', 'upstream/Plane-4.2', 'upstream/Copter-4.2', 'upstream/Rover-4.2']
 default_branch = 'upstream/master'
+chosen_branch = default_branch
 
 def get_boards_from_ardupilot_tree():
     '''return a list of boards to build'''
@@ -297,6 +298,7 @@ def status_thread():
 
 def update_source(branch):
     '''update submodules and ardupilot git tree.  Returns new source git hash'''
+    app.logger.info('Updating to new branch: '+branch)
     app.logger.info('Fetching ardupilot remote')
     subprocess.run(['git', 'fetch', branch.split('/', 1)[0]],
                    cwd=sourcedir)
@@ -365,23 +367,8 @@ BOARDS = get_boards_from_ardupilot_tree()
 @app.route('/generate', methods=['GET', 'POST'])
 def generate():
     try:
-        branch = request.form['branch']
-        if not branch in BRANCHES:
-            raise Exception("bad branch")
-
-        new_git_hash = update_source(branch)
-
-        global SOURCE_GIT_HASH
-        global BUILD_OPTIONS
-        global BOARDS
-        if new_git_hash == SOURCE_GIT_HASH:
-            app.logger.info('Source git hash unchanged')
-        else:
-            app.logger.info('Source git hash changed; refreshing')
-            SOURCE_GIT_HASH = new_git_hash
-            # get build options from source:
-            BUILD_OPTIONS = get_build_options_from_ardupilot_tree()
-            BOARDS = get_boards_from_ardupilot_tree()
+        global chosen_branch
+        app.logger.info('Generate: Chosen branch is %s' % chosen_branch)
 
         # fetch features from user input
         extra_hwdef = []
@@ -449,7 +436,7 @@ def generate():
             # create build.log
             build_log_info = ('Vehicle: ' + vehicle +
                 '\nBoard: ' + board +
-                '\nBranch:' + branch +
+                '\nBranch:' + chosen_branch +
                 '\nSelected Features:\n' + feature_list +
                 '\n\nWaiting for build to start...\n\n')
             app.logger.info('Creating build.log')
@@ -519,9 +506,30 @@ def home():
     app.logger.info('Rendering index.html')
     global BUILD_OPTIONS
     return render_template('index.html',
+                           get_branches=get_branches)
+
+@app.route('/index2', methods=['GET', 'POST'])
+def home2():
+    app.logger.info('Rendering index2.html')
+    global chosen_branch
+    chosen_branch = request.form['branch']
+    if not chosen_branch in BRANCHES:
+        raise Exception("bad branch")
+    new_git_hash = update_source(chosen_branch)
+    global SOURCE_GIT_HASH
+    global BUILD_OPTIONS
+    global BOARDS
+    if new_git_hash == SOURCE_GIT_HASH:
+        app.logger.info('Source git hash unchanged')
+    else:
+        app.logger.info('Source git hash changed; refreshing')
+        SOURCE_GIT_HASH = new_git_hash
+        # get build options from source:
+        BUILD_OPTIONS = get_build_options_from_ardupilot_tree()
+        BOARDS = get_boards_from_ardupilot_tree()
+    return render_template('index2.html',
                            get_boards=get_boards,
                            get_vehicles=get_vehicles,
-                           get_branches=get_branches,
                            get_build_options=lambda x : get_build_options(BUILD_OPTIONS, x),
                            get_build_categories=lambda : get_build_categories(BUILD_OPTIONS))
 

+ 3 - 66
templates/index.html

@@ -21,7 +21,6 @@
     <meta property="og:image" content="https://ardupilot.org/application/files/6315/7552/1962/ArduPilot-Motto.png">
 
     <link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='styles/main.css') }}">
-    <script type="text/javascript" src="{{ url_for('static', filename='js/CollapsibleLists.js')}}"></script>
 </head>
 
 <body onload="javascript: reload()">
@@ -36,9 +35,9 @@
         <br><b>This site is EXPERIMENTAL</b>
 
 
-        <p>Please select the required options for the custom firmware build, then hit 'Generate'.</p>
+        <p>Please select the branch to build, then hit 'Next'.</p>
 
-        <form action="/generate" method="post">
+        <form action="/index2" method="post">
             <label for="branch">Choose a branch:
                 <select name="branch">
                     {% for branch in get_branches()[0] %}
@@ -50,55 +49,8 @@
                     {% endfor %}
                 </select>
             </label>
-            <p></p>
-            <label for="vehicle">Choose a vehicle:
-                <select name="vehicle">
-                    {% for vehicle in get_vehicles()[0] %}
-                    {% if vehicle == get_vehicles()[1] %}
-                    <option value="{{vehicle}}" selected>{{vehicle}}</option>
-                    {% else %}
-                    <option value="{{vehicle}}">{{vehicle}}</option>
-                    {% endif %}
-                    {% endfor %}
-                </select>
-            </label>
-            <p></p>
-            <label for="board">Choose a board:
-                <select name="board">
-                    {% for board in get_boards()[0] %}
-                    {% if board == get_boards()[1] %}
-                    <option value="{{board}}" selected>{{board}}</option>
-                    {% else %}
-                    <option value="{{board}}">{{board}}</option>
-                    {% endif %}
-                    {% endfor %}
-                </select>
-            </label>
-            <p></p>
-            <label for="board">Select Features:
-                <ul class="collapsibleList">
-                    {% for c in get_build_categories() %}
-                    <li>{{c}}
-                        <ul>
-                            {% for f in get_build_options(c) %}
-                            <li>
-                                {% if f.default == 1 %}
-                                <input onclick='dependencies(this, "{{f.label}}", "{{f.dependency}}");' type="checkbox"
-                                       name="{{f.label}}" id="{{f.label}}" value="1" checked>
-                                {% else %}
-                                <input onclick='dependencies(this, "{{f.label}}", "{{f.dependency}}");' type="checkbox"
-                                       name="{{f.label}}" id="{{f.label}}" value="1">
-                                {% endif %}
-                                {{f.description}}
-                            </li>
-                            {% endfor %}
-                        </ul>
-                    </li>
-                    {% endfor %}
-                </ul>
-            </label>
             <br>
-            <input type="submit" value="Generate">
+            <input type="submit" value="Next">
         </form>
     </div>
     <hr>
@@ -106,8 +58,6 @@
     <div id="build_status"></div>
     <br/>
     <script>
-        CollapsibleLists.apply();
-
         function reload() {
             var output = document.getElementById('build_status');
             var xhr = new XMLHttpRequest();
@@ -127,19 +77,6 @@
             xhr.send();
         }
 
-        function dependencies(cb, f_label, f_dependency1) {
-            switch (cb.name) {
-                case f_label:
-                    const f_dependency = f_dependency1.split(",")
-                    var arrayLength = f_dependency.length;
-                    for (var i = 0; i < arrayLength; i++) {
-                        if (document.getElementById(f_dependency[i]).checked == false) {
-                            document.getElementById(f_dependency[i]).checked = cb.checked;
-                        }
-                    }
-                    break;
-            }
-        }
     </script>
 </div>
 </body>

+ 137 - 0
templates/index2.html

@@ -0,0 +1,137 @@
+<!doctype html>
+<html lang="en">
+
+<head>
+    <meta charset="utf-8">
+    <title>ArduPilot Custom Firmware Builder</title>
+    <meta name="description"
+          content="ArduPilot Custom Firmware Builder. It allows to build custom ArduPilot firmware by selecting the wanted features.">
+    <meta name="author" content="ArduPilot Team">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+
+    <!-- OG Meta Tags to improve the way the post looks when you share the page on LinkedIn, Facebook, Google+ -->
+    <meta property="og:site_name" content="ArduPilot"/>
+    <meta property="og:site" content=""/>
+    <meta property="og:title" content="ArduPilot Custom Firmware Builder"/>
+    <meta property="og:description"
+          content="ArduPilot Custom Firmware Builder. It allows to build custom ArduPilot firmware by selecting the wanted features."/>
+    <!-- description shown in the actual shared post -->
+    <meta property="og:type" content="website">
+    <meta property="og:url" content="https://custom.ardupilot.org/">
+    <meta property="og:image" content="https://ardupilot.org/application/files/6315/7552/1962/ArduPilot-Motto.png">
+
+    <link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='styles/main.css') }}">
+    <script type="text/javascript" src="{{ url_for('static', filename='js/CollapsibleLists.js')}}"></script>
+</head>
+
+<body onload="javascript: reload()">
+<div id="main">
+    <a href="https://custom.ardupilot.org/">
+        <div id="logo">
+        </div>
+    </a>
+
+    <div id="menu">
+        <h2>ArduPilot Custom Firmware Builder</h2>
+        <br><b>This site is EXPERIMENTAL</b>
+
+
+        <p>Please select the required options for the custom firmware build, then hit 'Generate'.</p>
+
+        <form action="/generate" method="post">
+            <label for="vehicle">Choose a vehicle:
+                <select name="vehicle">
+                    {% for vehicle in get_vehicles()[0] %}
+                    {% if vehicle == get_vehicles()[1] %}
+                    <option value="{{vehicle}}" selected>{{vehicle}}</option>
+                    {% else %}
+                    <option value="{{vehicle}}">{{vehicle}}</option>
+                    {% endif %}
+                    {% endfor %}
+                </select>
+            </label>
+            <p></p>
+            <label for="board">Choose a board:
+                <select name="board">
+                    {% for board in get_boards()[0] %}
+                    {% if board == get_boards()[1] %}
+                    <option value="{{board}}" selected>{{board}}</option>
+                    {% else %}
+                    <option value="{{board}}">{{board}}</option>
+                    {% endif %}
+                    {% endfor %}
+                </select>
+            </label>
+            <p></p>
+            <label for="board">Select Features:
+                <ul class="collapsibleList">
+                    {% for c in get_build_categories() %}
+                    <li>{{c}}
+                        <ul>
+                            {% for f in get_build_options(c) %}
+                            <li>
+                                {% if f.default == 1 %}
+                                <input onclick='dependencies(this, "{{f.label}}", "{{f.dependency}}");' type="checkbox"
+                                       name="{{f.label}}" id="{{f.label}}" value="1" checked>
+                                {% else %}
+                                <input onclick='dependencies(this, "{{f.label}}", "{{f.dependency}}");' type="checkbox"
+                                       name="{{f.label}}" id="{{f.label}}" value="1">
+                                {% endif %}
+                                {{f.description}}
+                            </li>
+                            {% endfor %}
+                        </ul>
+                    </li>
+                    {% endfor %}
+                </ul>
+            </label>
+            <br>
+            <input type="submit" value="Generate">
+        </form>
+    </div>
+    <hr>
+    <p>Exisiting builds (click on the status of a build to view it):</p>
+    <div id="build_status"></div>
+    <br/>
+    <script>
+        CollapsibleLists.apply();
+
+        function reload() {
+            var output = document.getElementById('build_status');
+            var xhr = new XMLHttpRequest();
+            xhr.open('GET', "/builds/status.html");
+
+            // disable cache, thanks to: https://stackoverflow.com/questions/22356025/force-cache-control-no-cache-in-chrome-via-xmlhttprequest-on-f5-reload
+            xhr.setRequestHeader("Cache-Control", "no-cache, no-store, max-age=0");
+            xhr.setRequestHeader("Expires", "Tue, 01 Jan 1980 1:00:00 GMT");
+            xhr.setRequestHeader("Pragma", "no-cache");
+
+            xhr.onload = function () {
+                if (xhr.status === 200) {
+                    output.innerHTML = xhr.responseText;
+                }
+                setTimeout(reload, 5000)
+            }
+            xhr.send();
+        }
+
+        function dependencies(cb, f_label, f_dependency1) {
+            switch (cb.name) {
+                case f_label:
+                    const f_dependency = f_dependency1.split(",")
+                    var arrayLength = f_dependency.length;
+                    for (var i = 0; i < arrayLength; i++) {
+                        if (document.getElementById(f_dependency[i]).checked == false) {
+                            document.getElementById(f_dependency[i]).checked = cb.checked;
+                        }
+                    }
+                    break;
+            }
+        }
+    </script>
+</div>
+</body>
+
+<hr>
+<footer>Created by Will Piper, <a href=https://github.com/ArduPilot/CustomBuild>Source Code</a>.</footer>
+</html>