Răsfoiți Sursa

Add option to select branches

Michelle Rossouw 3 ani în urmă
părinte
comite
f12f25321d
2 a modificat fișierele cu 29 adăugiri și 6 ștergeri
  1. 17 6
      app.py
  2. 12 0
      templates/index.html

+ 17 - 6
app.py

@@ -23,6 +23,8 @@ appdir = os.path.dirname(__file__)
 
 VEHICLES = [ 'Copter', 'Plane', 'Rover', 'Sub', 'Tracker' ]
 default_vehicle = 'Copter'
+BRANCHES = ['upstream/master', 'upstream/Plane-4.2', 'upstream/Copter-4.2', 'upstream/Rover-4.2']
+default_branch = 'upstream/master'
 
 def get_boards_from_ardupilot_tree():
     '''return a list of boards to build'''
@@ -293,14 +295,14 @@ def status_thread():
             pass
         time.sleep(3)
 
-def update_source():
+def update_source(branch):
     '''update submodules and ardupilot git tree.  Returns new source git hash'''
-    app.logger.info('Fetching ardupilot upstream')
-    subprocess.run(['git', 'fetch', 'upstream'],
+    app.logger.info('Fetching ardupilot remote')
+    subprocess.run(['git', 'fetch', branch.split('/', 1)[0]],
                    cwd=sourcedir)
     app.logger.info('Updating ardupilot git tree')
     subprocess.run(['git', 'reset', '--hard',
-                    'upstream/master'],
+                    branch],
                        cwd=sourcedir)
     app.logger.info('Updating submodules')
     subprocess.run(['git', 'submodule',
@@ -355,7 +357,7 @@ app.logger.info('Initial fetch')
 global SOURCE_GIT_HASH
 global BUILD_OPTIONS
 global BOARDS
-SOURCE_GIT_HASH = update_source()
+SOURCE_GIT_HASH = update_source(default_branch)
 # get build options from source:
 BUILD_OPTIONS = get_build_options_from_ardupilot_tree()
 BOARDS = get_boards_from_ardupilot_tree()
@@ -363,7 +365,11 @@ BOARDS = get_boards_from_ardupilot_tree()
 @app.route('/generate', methods=['GET', 'POST'])
 def generate():
     try:
-        new_git_hash = update_source()
+        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
@@ -443,6 +449,7 @@ def generate():
             # create build.log
             build_log_info = ('Vehicle: ' + vehicle +
                 '\nBoard: ' + board +
+                '\nBranch:' + branch +
                 '\nSelected Features:\n' + feature_list +
                 '\n\nWaiting for build to start...\n\n')
             app.logger.info('Creating build.log')
@@ -504,6 +511,9 @@ def get_build_categories(BUILD_OPTIONS):
 def get_vehicles():
     return (VEHICLES, default_vehicle)
 
+def get_branches():
+    return (BRANCHES, default_branch)
+
 @app.route('/')
 def home():
     app.logger.info('Rendering index.html')
@@ -511,6 +521,7 @@ def home():
     return render_template('index.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))
 

+ 12 - 0
templates/index.html

@@ -39,6 +39,18 @@
         <p>Please select the required options for the custom firmware build, then hit 'Generate'.</p>
 
         <form action="/generate" method="post">
+            <label for="branch">Choose a branch:
+                <select name="branch">
+                    {% for branch in get_branches()[0] %}
+                    {% if branches == get_branches()[1] %}
+                    <option value="{{branch}}" selected>{{branch}}</option>
+                    {% else %}
+                    <option value="{{branch}}">{{branch}}</option>
+                    {% endif %}
+                    {% endfor %}
+                </select>
+            </label>
+            <p></p>
             <label for="vehicle">Choose a vehicle:
                 <select name="vehicle">
                     {% for vehicle in get_vehicles()[0] %}