Project

Profile

Help

How to connect?
Download (2.52 KB) Statistics View on GitHub Reload from mirrored respository
| Branch: | Tag: | Revision:

github / tools / upload_build.py @ e379f35a

1
"""This script upload a newly-build version of CocoMUD for Windows.
2

3
The Download wiki page on Redmine are updated.
4

5
Requirements:
6
    This script needs 'python-redmine', which you can obtain with
7
        pip install python-redmine
8

9
"""
10

    
11
import argparse
12
from json import dumps
13
import os
14
import re
15
import sys
16
from urllib import request
17

    
18
from redminelib import Redmine
19
from redminelib.exceptions import ResourceNotFoundError
20

    
21
# Create an argument parser
22
parser = argparse.ArgumentParser(
23
        description="upload a new CocoMUD build")
24
parser.add_argument("key", help="the API key to upload to Redmine")
25
args = parser.parse_args()
26

    
27
# Configure the system
28
key = args.key
29

    
30
# Connects to the REST API
31
redmine = Redmine("https://cocomud.plan.io", key=key)
32

    
33
# Check that the file exists
34
path = os.path.abspath("../src/build/CocoMUD.zip")
35
if not os.path.exists(path):
36
    print("The file {} cannot be found.".format(path))
37
    sys.exit(1)
38

    
39
# Then upload this file
40
print("Retrieving the Download wiki page on 'cocomud-client'...")
41
page = redmine.wiki_page.get("Download", project_id="cocomud-client")
42
print("Uploading {}...".format(path))
43
text = page.text
44
page.uploads = [{"path": path, "filename": "CocoMUD.zip"}]
45
page.text = text
46
print("Saving the page...", page.save())
47

    
48
# Get the new resource URL
49
url = list(page.attachments)[-1].content_url
50

    
51
# Retrieve the version number
52
with open("../src/version.py", encoding="utf-8") as file:
53
    content = file.read()
54

    
55
version = content.partition("=")[2].strip()
56

    
57
# Now we get ALL wiki pages with the title 'Download' and replace the URL
58
for project in redmine.project.all():
59
    identifier = project.identifier
60

    
61
    # Try to get the 'Download' page
62
    try:
63
        page = redmine.wiki_page.get("Download", project_id=identifier)
64
    except ResourceNotFoundError:
65
        pass
66
    else:
67
        print("Updating the Download page for the {} project...".format(
68
                identifier))
69
        text = page.text
70
        text = re.sub(r"https\://cocomud\.plan\.io/attachments/" \
71
                r"download/\d+/CocoMUD\.zip", url, text)
72
        text = re.sub(r"\+\*\d+\*\+", "+*" + version + "*+", text)
73
        page.text = text
74
        success = page.save()
75
        if success:
76
            print("Correctly saved the wiki page.")
77
        else:
78
            print("Error while saving the wiki page.")
79

    
80
# Update the build information in the custom field
81
build = dumps({version: {"windows": url}})
82
print("Updating the custom field")
83
redmine.project.update(resource_id=2,
84
        custom_fields=[{"id": 3, "value": build}])
85
print("URL", url)
(2-2/2)