kopia lustrzana https://github.com/jamescoxon/dl-fldigi
check based on all old git IDs instead
rodzic
501f86909b
commit
cb85bd7950
|
@ -1,46 +1,54 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
# Copyright 2012 Daniel Richman
|
# Copyright 2012 Daniel Richman
|
||||||
|
# Copyright 2015 Adam Greig
|
||||||
# DL-Fldigi update check server
|
# DL-Fldigi update check server
|
||||||
|
|
||||||
import os.path
|
import os
|
||||||
import yaml
|
import yaml
|
||||||
|
import os.path
|
||||||
|
import subprocess
|
||||||
from flask import Flask, abort, request, jsonify
|
from flask import Flask, abort, request, jsonify
|
||||||
|
|
||||||
app_dir = os.path.dirname(__file__)
|
|
||||||
config_file = os.path.join(app_dir, "config.yml")
|
|
||||||
config = {}
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
def load_config():
|
# Load config from file
|
||||||
global config
|
app_dir = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
config_file = os.path.join(app_dir, "config.yml")
|
||||||
|
config = yaml.load(open(config_file))
|
||||||
|
|
||||||
|
# Swap to directory containing this script, to ensure we're inside
|
||||||
|
# the git repository.
|
||||||
|
os.chdir(app_dir)
|
||||||
|
|
||||||
|
|
||||||
|
def git_rev_parse(name):
|
||||||
|
arg = name + "^{}"
|
||||||
|
commit = subprocess.check_output(["git", "rev-parse", "--verify", arg])
|
||||||
|
return commit.strip()
|
||||||
|
|
||||||
|
|
||||||
|
def git_rev_list(commit):
|
||||||
|
commits = subprocess.check_output(["git", "rev-list", commit])
|
||||||
|
return set(commits.split("\n")[1:])
|
||||||
|
|
||||||
|
# Store commits considered old
|
||||||
|
old_commits = git_rev_list(git_rev_parse(config['latest_release']))
|
||||||
|
|
||||||
mtime = os.stat(config_file).st_mtime
|
|
||||||
if mtime != config.get("_mtime", None):
|
|
||||||
with open(config_file) as f:
|
|
||||||
config = yaml.load(f)
|
|
||||||
config["_mtime"] = mtime
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def check():
|
def check():
|
||||||
load_config()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
platform = request.args["platform"]
|
|
||||||
commit = request.args["commit"]
|
commit = request.args["commit"]
|
||||||
expect = config["expect"][platform]
|
|
||||||
|
|
||||||
if isinstance(expect, list) and commit in expect:
|
if commit in old_commits:
|
||||||
return ""
|
|
||||||
elif isinstance(expect, basestring) and expect == commit:
|
|
||||||
return ""
|
|
||||||
else:
|
|
||||||
return jsonify(config["update"])
|
return jsonify(config["update"])
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# bad platform or missing arg
|
# bad platform or missing arg
|
||||||
abort(400)
|
abort(400)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run()
|
app.run(debug=True)
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
update:
|
update:
|
||||||
url: "http://ukhas.org.uk/projects:dl-fldigi"
|
url: "http://ukhas.org.uk/projects:dl-fldigi"
|
||||||
text: "There is a new version of dl-fldigi available!"
|
text: "There is a new version of dl-fldigi available!"
|
||||||
expect:
|
latest_release: "DL3.1"
|
||||||
win32: "that would be self description"
|
|
||||||
linux: "which is unfortunately not possible"
|
|
||||||
macosx:
|
|
||||||
- "well, technically it is,"
|
|
||||||
- "but I don't have a super computer"
|
|
||||||
|
|
Ładowanie…
Reference in New Issue