summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDamien Regad <dregad@mantisbt.org>2020-08-02 16:05:37 +0200
committerDamien Regad <dregad@mantisbt.org>2020-08-02 16:05:37 +0200
commit42f3971afdc851424e896c6da5a17ed0a23170e7 (patch)
tree9a932957a09b8c4bcd32d10743db3da4f50b3f93 /scripts
parent6f1ccb4ff104669b7be33c075cbed365a7c4a332 (diff)
downloadadodb-42f3971afdc851424e896c6da5a17ed0a23170e7.tar.gz
adodb-42f3971afdc851424e896c6da5a17ed0a23170e7.tar.bz2
adodb-42f3971afdc851424e896c6da5a17ed0a23170e7.zip
Use SourceForge API to set file info
The script is now capable of updating the default file to download from the SourceForge files section, based on the uploaded file's extension. Introduces a config file for maintenance scripts, in YAML format, named env.yml. It is used to store the SourceForge API key.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/.gitignore3
-rw-r--r--scripts/env.yml.sample7
-rwxr-xr-xscripts/uploadrelease.py72
3 files changed, 82 insertions, 0 deletions
diff --git a/scripts/.gitignore b/scripts/.gitignore
index 3e0e62b2..43d23186 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -1,2 +1,5 @@
+# ADOdb scripts config file
+/env.yml
+
# Python byte code
*.pyc
diff --git a/scripts/env.yml.sample b/scripts/env.yml.sample
new file mode 100644
index 00000000..fce3840d
--- /dev/null
+++ b/scripts/env.yml.sample
@@ -0,0 +1,7 @@
+# ADOdb maintenance scripts configuration file
+# Rename this file to 'env.yml' and update variables below as appropriate.
+
+# SourceForge API key
+# Get it from https://sourceforge.net/auth/preferences/
+# under "Releases API Key"
+api_key:
diff --git a/scripts/uploadrelease.py b/scripts/uploadrelease.py
index 9f6f0aee..e8d673c1 100755
--- a/scripts/uploadrelease.py
+++ b/scripts/uploadrelease.py
@@ -7,17 +7,24 @@ from distutils.version import LooseVersion
import getopt
import getpass
import glob
+import json
import os
from os import path
import re
+import requests
import subprocess
import sys
+import yaml
# Directories and files to exclude from release tarballs
# for debugging, set to a local dir e.g. "localhost:/tmp/sf-adodb/"
sf_files = "frs.sourceforge.net:/home/frs/project/adodb/"
+# SourceForge Release API base URL
+# https://sourceforge.net/p/forge/documentation/Using%20the%20Release%20API/
+sf_api_url = 'https://sourceforge.net/projects/adodb/files/{}/'
+
# rsync command template
rsync_cmd = "rsync -vP --rsh ssh {opt} {src} {usr}@{dst}"
@@ -127,6 +134,25 @@ def sourceforge_target_dir(version):
return directory
+def load_env():
+ global api_key
+
+ # Load the config file
+ env_file = path.join(path.dirname(path.abspath(__file__)), 'env.yml')
+ try:
+ stream = file(env_file, 'r')
+ y = yaml.safe_load(stream)
+ except IOError:
+ print("ERROR: Environment file {} not found".format(env_file))
+ sys.exit(3)
+ except yaml.parser.ParserError as e:
+ print("ERROR: Invalid Environment file")
+ print(e)
+ sys.exit(3)
+
+ api_key = y['api_key']
+
+
def process_command_line():
''' Retrieve command-line options and set global variables accordingly
'''
@@ -186,13 +212,59 @@ def upload_release_files():
)
+def set_sourceforge_file_info():
+ print("Updating uploaded files information")
+
+ base_url = sf_api_url.format(
+ sourceforge_target_dir(get_release_version())
+ )
+ headers = {'Accept': 'application/json"'}
+
+ # Loop through uploaded files
+ for file in glob.glob('adodb-*'):
+ print(" " + file)
+
+ # Determine defaults based on file extension
+ ext = file.split('.', 3)[3]
+ if ext == 'zip':
+ defaults = ['windows']
+ elif ext == 'tar.gz':
+ defaults = ['linux', 'mac', 'bsd', 'solaris', 'others']
+ else:
+ print("WARNING: Unknown extension for file " + file)
+ continue
+
+ # SourceForge API request
+ global api_key
+ url = path.join(base_url, file)
+ payload = {
+ 'default': defaults,
+ 'api_key': api_key
+ }
+ req = requests.put(url, headers=headers, params=payload)
+
+ # Print results
+ if req.status_code == requests.codes.ok:
+ result = json.loads(req.text)['result']
+ print(" Download default for: " + result['x_sf']['default'])
+ else:
+ if req.status_code == requests.codes.unauthorized:
+ err = "access denied"
+ else:
+ err = "SourceForge API call failed"
+ print("ERROR: {} - check API key".format(err))
+ break
+
+
def main():
+ load_env()
process_command_line()
# Start upload process
print "ADOdb release upload script"
upload_release_files()
+ set_sourceforge_file_info()
#end main()