Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 625e715e authored by Nicola Corna's avatar Nicola Corna
Browse files

Add an option to generate the OpenDelta's builds JSON file

parent fba75880
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -91,6 +91,12 @@ ENV DELETE_OLD_ZIPS 0
# Delete old deltas in $DELTA_DIR, keep only the N latest one (0 to disable)
ENV DELETE_OLD_DELTAS 0

# Create a JSON file that indexes the build zips at the end of the build process
# (for the updates in OpenDelta). The file will be created in $ZIP_DIR with the
# specified name; leave empty to skip it.
# Requires ZIP_SUBDIR.
ENV OPENDELTA_BUILDS_JSON ''

# Create Volume entry points
############################
VOLUME $SRC_DIR
+1 −0
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@ docker run \
    -e "BUILD_DELTA=true" \
    -e "DELETE_OLD_ZIPS=3" \
    -e "DELETE_OLD_DELTAS=10" \
    -e "OPENDELTA_BUILDS_JSON=builds.json" \
    -v "/home/user/ccache:/srv/ccache" \
    -v "/home/user/source:/srv/src" \
    -v "/home/user/public/full:/srv/zips" \
+9 −0
Original line number Diff line number Diff line
@@ -187,6 +187,15 @@ if ! [ -z "$DEVICE_LIST" ]; then
    fi
  done

  # Create the OpenDelta's builds JSON file
  if ! [ -z "$OPENDELTA_BUILDS_JSON" ]; then
    echo ">> [$(date)] Creating OpenDelta's builds JSON file (ZIP_DIR/$OPENDELTA_BUILDS_JSON)" >> $DOCKER_LOG
    if [ "$ZIP_SUBDIR" != true ]; then
      echo ">> [$(date)] WARNING: OpenDelta requires zip builds separated per device! You should set ZIP_SUBDIR to true" >> $DOCKER_LOG
    fi
    /usr/bin/python /root/opendelta_builds_json.py $ZIP_DIR -o $ZIP_DIR/$OPENDELTA_BUILDS_JSON
  fi

  # Clean the src directory if requested
  if [ "$CLEAN_SRCDIR" = true ]; then
    rm -Rf "$SRC_DIR/*"
+49 −0
Original line number Diff line number Diff line
#!/usr/bin/env python

# Copyright (C) 2017 Nicola Corna <nicola@corna.info>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from sys import argv
from argparse import ArgumentParser
import os
import json

if __name__ == "__main__":
    parser = ArgumentParser(description='Generate an OpenDelta\'s builds.json '
                                        'file')
    parser.add_argument('path', metavar='PATH', type=str, help='the directory '
                        'containing the zips')
    parser.add_argument('-o', "--output", type=str, help='output file; '
                        'if unspecified, print to stdout')
    args = parser.parse_args()

    data = {}
    builddirs = ['./' + s for s in os.listdir(args.path)]
    for builddir in builddirs:
        try:
            builds = os.listdir(os.path.join(args.path, builddir))
            data[builddir] = [dict() for x in range(len(builds))]
            for i in range(0, len(builds)):
                data[builddir][i]["filename"] = builds[i]
                data[builddir][i]["timestamp"] = int(os.path.getmtime(
                    os.path.join(args.path, builddir, builds[i])))
        except OSError:
            pass

    if args.output:
        with open(args.output, "w") as f:
            f.write(json.dumps(data, separators=(',',':')))
    else:
        print(json.dumps(data, separators=(',',':')))