new system
This commit is contained in:
parent
6014e420e5
commit
ca6744f9e0
8 changed files with 135 additions and 2 deletions
|
@ -1 +0,0 @@
|
||||||
{"label": "0.9-alpha.1", "id": 1, "timestamp": 1718114820, "file": "realweather-0.9a1.jar"}
|
|
Binary file not shown.
1
latest
1
latest
|
@ -1 +0,0 @@
|
||||||
0.9-alpha.1
|
|
1
latest.json
Normal file
1
latest.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"label": "0.9-alpha.1", "id": 1, "timestamp": 1718449299, "file": "realweather-0.9-SNAPSHOT.jar"}
|
118
release.py
Executable file
118
release.py
Executable file
|
@ -0,0 +1,118 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import json, os, time
|
||||||
|
from typing import Tuple
|
||||||
|
|
||||||
|
def confirm(prompt: str) -> bool:
|
||||||
|
confirmed = input(prompt + ' (Y/N) ')
|
||||||
|
return confirmed.lower() == 'y'
|
||||||
|
|
||||||
|
def load_latest_data() -> dict:
|
||||||
|
if os.path.isfile('latest.json'):
|
||||||
|
return json.loads(open('latest.json').read())
|
||||||
|
return {'id': 0}
|
||||||
|
|
||||||
|
def match_name(filename: str, extension: str=None, exact_name: str=None):
|
||||||
|
if exact_name is not None:
|
||||||
|
return filename == exact_name
|
||||||
|
elif extension is not None:
|
||||||
|
return filename.lower().endswith(extension.lower())
|
||||||
|
return True
|
||||||
|
|
||||||
|
def scan_for_file(ask: bool=False, extension: str=None, exact_name: str=None) -> Tuple[str]:
|
||||||
|
for file in os.scandir():
|
||||||
|
if file.is_dir(): continue
|
||||||
|
if not match_name(file.name, extension, exact_name): continue
|
||||||
|
|
||||||
|
if ask:
|
||||||
|
if not confirm(f"Found {file.name} in the current directory, do you want to proceed with it?"):
|
||||||
|
return (None, None)
|
||||||
|
|
||||||
|
return (file.path, file.name)
|
||||||
|
return (None, None)
|
||||||
|
|
||||||
|
def wait_for_file(waiting_dir: str, extension: str=None, exact_name: str=None) -> Tuple[str]:
|
||||||
|
print(f"Please put a {extension} file in {waiting_dir}")
|
||||||
|
while True:
|
||||||
|
files = [i for i in os.scandir(waiting_dir)]
|
||||||
|
|
||||||
|
if len(files) == 0:
|
||||||
|
time.sleep(0.5)
|
||||||
|
continue
|
||||||
|
|
||||||
|
file = files[0]
|
||||||
|
filepath = file.path
|
||||||
|
filename = file.name
|
||||||
|
|
||||||
|
if match_name(filename, extension, exact_name):
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
os.remove(filepath)
|
||||||
|
print(f"Not a {extension} file: {filename}")
|
||||||
|
|
||||||
|
return (filepath, filename)
|
||||||
|
|
||||||
|
def write_metadata(metadata: dict):
|
||||||
|
dir = metadata['label']
|
||||||
|
metadata = json.dumps(metadata)
|
||||||
|
for filepath in [os.path.join('releases', dir, 'meta.json'), 'latest.json']:
|
||||||
|
file = open(filepath, 'w')
|
||||||
|
file.write(metadata)
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
def main():
|
||||||
|
latest_data = load_latest_data()
|
||||||
|
if latest_data['id'] > 0:
|
||||||
|
print(f"Current release: {latest_data['label']}")
|
||||||
|
print(f"Released {time.strftime('%d.%m.%Y %H:%M', time.localtime(latest_data['timestamp']))}")
|
||||||
|
print('')
|
||||||
|
|
||||||
|
version = input('New version? ')
|
||||||
|
|
||||||
|
if os.path.isdir(version):
|
||||||
|
raise FileExistsError()
|
||||||
|
|
||||||
|
filepath, filename = scan_for_file(ask=True, extension='jar')
|
||||||
|
|
||||||
|
if filepath is None:
|
||||||
|
os.makedirs('pending', exist_ok=True)
|
||||||
|
try:
|
||||||
|
filepath, filename = wait_for_file('pending', 'jar')
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
os.rmdir('pending')
|
||||||
|
return
|
||||||
|
|
||||||
|
changelog = confirm('Do you want to include a changelog?')
|
||||||
|
if changelog:
|
||||||
|
cfilepath, cfilename = scan_for_file(ask=True, exact_name='changelog.txt')
|
||||||
|
if cfilepath is None:
|
||||||
|
try:
|
||||||
|
os.makedirs('pending', exist_ok=True)
|
||||||
|
cfilepath, cfilename = wait_for_file('pending', 'txt')
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
os.rmdir('pending')
|
||||||
|
return
|
||||||
|
|
||||||
|
version_dir = os.path.join('releases', version)
|
||||||
|
|
||||||
|
os.mkdir(version_dir)
|
||||||
|
os.rename(filepath, os.path.join(version_dir, filename))
|
||||||
|
if changelog: os.rename(cfilepath, os.path.join(version_dir, 'changelog.txt'))
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.rmdir('pending')
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
metadata = {
|
||||||
|
'label': version,
|
||||||
|
'id': latest_data['id'] + 1,
|
||||||
|
'timestamp': int(time.time()),
|
||||||
|
'file': filename
|
||||||
|
}
|
||||||
|
write_metadata(metadata)
|
||||||
|
|
||||||
|
print("Done, don't forget to commit and push")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
1
releases/0.9-alpha.1/meta.json
Normal file
1
releases/0.9-alpha.1/meta.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"label": "0.9-alpha.1", "id": 1, "timestamp": 1718449299, "file": "realweather-0.9-SNAPSHOT.jar"}
|
BIN
releases/0.9-alpha.1/realweather-0.9-SNAPSHOT.jar
Normal file
BIN
releases/0.9-alpha.1/realweather-0.9-SNAPSHOT.jar
Normal file
Binary file not shown.
15
reset.py
Executable file
15
reset.py
Executable file
|
@ -0,0 +1,15 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from shutil import rmtree
|
||||||
|
from os import remove, mkdir
|
||||||
|
|
||||||
|
confirmation = input('If you really want to delete all releases, type CONFIRM: ')
|
||||||
|
if confirmation != 'CONFIRM':
|
||||||
|
print('Cancelled')
|
||||||
|
exit()
|
||||||
|
|
||||||
|
remove('latest.json')
|
||||||
|
rmtree('releases')
|
||||||
|
mkdir('releases')
|
||||||
|
|
||||||
|
print('Reset complete')
|
Loading…
Reference in a new issue