Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthurSonzogni <sonzogniarthur@gmail.com>2020-04-29 16:45:05 +0300
committerArthurSonzogni <sonzogniarthur@gmail.com>2020-06-28 14:34:26 +0300
commit29433267e8e2dab0a63fe2098f34c31ef6140a5a (patch)
tree570a7b67f6825f02e66187e26063adee3e375e76 /update.py
Initial commit without calling 'update.py'
Diffstat (limited to 'update.py')
-rwxr-xr-xupdate.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/update.py b/update.py
new file mode 100755
index 0000000..443d900
--- /dev/null
+++ b/update.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python3
+
+import sys, os
+import json
+import subprocess
+import urllib.request
+import hashlib
+
+# Go to the directory this script is stored in
+os.chdir(os.path.dirname(os.path.realpath(__file__)))
+
+# Download release data
+releases = json.loads(str(urllib.request.urlopen('https://api.github.com/repos/nlohmann/json/releases').read(), 'utf-8'))
+
+# Fetch all releases and the corresponding URL
+release_url_map = []
+for release in releases:
+ for asset in release['assets']:
+ if asset['name'] == 'json.hpp':
+ release_url_map.append((release['tag_name'], asset['browser_download_url'], release['body']))
+
+# List all git tags
+process = subprocess.Popen(['git', 'tag'], stdout=subprocess.PIPE)
+tags, _ = process.communicate()
+tags = set(filter(None, str(tags, 'utf-8').split("\n")))
+print("Releases already contained in this repository are " + str(tags))
+
+# Go over the release_url_map in reverse order; if a release is not yet a Git
+# tag, download the file, commit and add a tag
+did_update = False
+for tag, url, body in release_url_map[::-1]:
+ if not tag in tags:
+ print("Downloading release " + tag + " from " + url)
+ os.makedirs('./include', mode=0o777, exist_ok=True)
+ os.makedirs('./include/nlohmann', mode=0o777, exist_ok=True)
+ data = urllib.request.urlopen(url).read();
+ with open('./include/nlohmann/json.hpp', 'wb') as f:
+ f.write(data)
+
+ # Try to download the json_fwd.hpp header -- only exists since release
+ # v3.1.0
+ has_json_fwd = False
+ try:
+ json_fwd_url = 'https://github.com/nlohmann/json/raw/{}/include/nlohmann/json_fwd.hpp'.format(tag);
+ print("Trying to download " + json_fwd_url)
+ data = urllib.request.urlopen(json_fwd_url).read();
+ with open('./include/nlohmann/json_fwd.hpp', 'wb') as f:
+ f.write(data)
+ has_json_fwd = True
+ except:
+ pass
+
+ subprocess.call(['git', 'add', './include/nlohmann/json.hpp'])
+ if has_json_fwd:
+ subprocess.call(['git', 'add', './include/nlohmann/json_fwd.hpp'])
+ subprocess.call(['git', 'commit', '-m', 'Upstream release ' + tag])
+ subprocess.call(['git', 'tag', '-a', tag, '-m', body])
+
+ did_update = True
+
+# Push the updated Git repository
+if did_update:
+ subprocess.call(['git', 'push', '--tags'])
+ subprocess.call(['git', 'push'])