-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Blooym/update-appstream-file
- Loading branch information
Showing
3 changed files
with
118 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,55 @@ | ||
import yaml | ||
import sys | ||
import xml.etree.ElementTree as ET | ||
from datetime import date | ||
|
||
if len(sys.argv) != 4: | ||
print(f'Usage: python3 {sys.argv[0]} <config file> <new tag number> <new commit hash>') | ||
print("Ran with args: " + str(sys.argv)) | ||
if len(sys.argv) != 5: | ||
print(f'Usage: python3 {sys.argv[0]} <manifest file> <appstream file> <new tag> <new commit>') | ||
sys.exit(1) | ||
|
||
fileName = sys.argv[1] | ||
newTag = sys.argv[2] | ||
newCommit = sys.argv[3] | ||
manifestFile = sys.argv[1] | ||
appstreamFile = sys.argv[2] | ||
newTag = sys.argv[3] | ||
newCommit = sys.argv[4] | ||
|
||
# Read the given file and try to parse it to update its tag and commit. | ||
with open(fileName, 'r') as f: | ||
config = yaml.safe_load(f) | ||
success = False | ||
# Read the manifest file and update the tag and commit | ||
with open(manifestFile, 'r') as f: | ||
yamlFile = yaml.safe_load(f) | ||
manifestUpdateSuccess = False | ||
try: | ||
for module in config['modules']: | ||
for module in yamlFile['modules']: | ||
if module['name'] == 'xivlauncher': | ||
for source in module['sources']: | ||
if source['url'] == 'https://github.com/goatcorp/XIVLauncher.Core.git': | ||
source['tag'] = newTag | ||
source['commit'] = newCommit | ||
with open(fileName, 'w') as f: | ||
yaml.dump(config, f) | ||
success = True | ||
with open(manifestFile, 'w') as f: | ||
yaml.dump(yamlFile, f) | ||
manifestUpdateSuccess = True | ||
break; | ||
except KeyError: | ||
pass | ||
|
||
if success is False: | ||
print('Error: failed to update XIVLauncher.Core commit and tag.. exiting') | ||
if manifestUpdateSuccess is False: | ||
print('Error: failed to update XIVLauncher.Core manifest.. exiting') | ||
sys.exit(1) | ||
|
||
print(f'Updated XIVLauncher.Core tag to {newTag} and commit to {newCommit} in {fileName}') | ||
# Read the appstream file and update the tag and commit | ||
with open(appstreamFile, 'r') as f: | ||
tree = ET.parse(f) | ||
root = tree.getroot() | ||
appstreamUpdateSuccess = False | ||
for component in root: | ||
if component.tag == 'releases': | ||
for release in component: | ||
release.set('date', date.today().strftime("%Y-%m-%d")) | ||
release.set('version', newTag) | ||
tree.write(appstreamFile) | ||
appstreamUpdateSuccess = True | ||
break | ||
if appstreamUpdateSuccess is False: | ||
print('Error: failed to update appstream file.. exiting') | ||
sys.exit(1) | ||
|
||
print(f'Updated {manifestFile} and {appstreamFile} to tag {newTag} and commit {newCommit} on {date.today().strftime("%Y-%m-%d")}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters