reorgranize again
This commit is contained in:
parent
d0ba477db8
commit
764a91f0d7
10 changed files with 121 additions and 63 deletions
1
data/testing/0.9-alpha.1/meta-v1.json
Normal file
1
data/testing/0.9-alpha.1/meta-v1.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"label": "0.9-alpha.1", "id": 1, "timestamp": 1718613854, "file": "realweather-0.9-SNAPSHOT.jar", "sha256": "131f03c7f4407ee874f5a05419639fad8160a2975749916cdbbb185b62dd55c7"}
|
1
data/testing/0.9-alpha.2/changelog.txt
Normal file
1
data/testing/0.9-alpha.2/changelog.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
no changes
|
1
data/testing/0.9-alpha.2/meta-v1.json
Normal file
1
data/testing/0.9-alpha.2/meta-v1.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"label": "0.9-alpha.2", "id": 2, "timestamp": 1718614497, "file": "realweather-0.9-SNAPSHOT.jar", "sha256": "131f03c7f4407ee874f5a05419639fad8160a2975749916cdbbb185b62dd55c7"}
|
BIN
data/testing/0.9-alpha.2/realweather-0.9-SNAPSHOT.jar
Normal file
BIN
data/testing/0.9-alpha.2/realweather-0.9-SNAPSHOT.jar
Normal file
Binary file not shown.
1
data/testing/latest/meta-v1.json
Normal file
1
data/testing/latest/meta-v1.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"label": "0.9-alpha.2", "id": 2, "timestamp": 1718614497, "file": "realweather-0.9-SNAPSHOT.jar", "sha256": "131f03c7f4407ee874f5a05419639fad8160a2975749916cdbbb185b62dd55c7"}
|
|
@ -1 +0,0 @@
|
||||||
{"label": "0.9-alpha.1", "id": 1, "timestamp": 1718539114, "file": "realweather-0.9-SNAPSHOT.jar"}
|
|
166
release.py
166
release.py
|
@ -1,20 +1,14 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import json, os, time
|
import json, os, time, tempfile, shutil
|
||||||
from typing import Tuple
|
from hashlib import sha256
|
||||||
|
|
||||||
meta_file_name = 'meta-v1.json'
|
META_FILENAME = 'meta-v1.json'
|
||||||
latest_file_name = 'latest-v1.json'
|
BASE_DIR = 'data'
|
||||||
latest_file_path = os.path.join('latest', latest_file_name)
|
WAITING_DIR = 'pending'
|
||||||
|
TEMP_DIR = tempfile.TemporaryDirectory()
|
||||||
|
|
||||||
def confirm(prompt: str) -> bool:
|
# file scanner functions
|
||||||
confirmed = input(prompt + ' (Y/N) ')
|
|
||||||
return confirmed.lower() == 'y'
|
|
||||||
|
|
||||||
def load_latest_data() -> dict:
|
|
||||||
if os.path.isfile(latest_file_path):
|
|
||||||
return json.loads(open(latest_file_path).read())
|
|
||||||
return {'id': 0}
|
|
||||||
|
|
||||||
def match_name(filename: str, extension: str=None, exact_name: str=None):
|
def match_name(filename: str, extension: str=None, exact_name: str=None):
|
||||||
if exact_name is not None:
|
if exact_name is not None:
|
||||||
|
@ -23,7 +17,7 @@ def match_name(filename: str, extension: str=None, exact_name: str=None):
|
||||||
return filename.lower().endswith(extension.lower())
|
return filename.lower().endswith(extension.lower())
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def scan_for_file(ask: bool=False, extension: str=None, exact_name: str=None) -> Tuple[str]:
|
def scan_for_file(ask: bool=False, extension: str=None, exact_name: str=None) -> tuple[str]:
|
||||||
for file in os.scandir():
|
for file in os.scandir():
|
||||||
if file.is_dir(): continue
|
if file.is_dir(): continue
|
||||||
if not match_name(file.name, extension, exact_name): continue
|
if not match_name(file.name, extension, exact_name): continue
|
||||||
|
@ -35,7 +29,7 @@ def scan_for_file(ask: bool=False, extension: str=None, exact_name: str=None) ->
|
||||||
return (file.path, file.name)
|
return (file.path, file.name)
|
||||||
return (None, None)
|
return (None, None)
|
||||||
|
|
||||||
def wait_for_file(waiting_dir: str, extension: str=None, exact_name: str=None) -> Tuple[str]:
|
def wait_for_file(waiting_dir: str, extension: str=None) -> tuple[str]:
|
||||||
print(f"Please put a {extension} file in {waiting_dir}")
|
print(f"Please put a {extension} file in {waiting_dir}")
|
||||||
while True:
|
while True:
|
||||||
files = [i for i in os.scandir(waiting_dir)]
|
files = [i for i in os.scandir(waiting_dir)]
|
||||||
|
@ -48,7 +42,7 @@ def wait_for_file(waiting_dir: str, extension: str=None, exact_name: str=None) -
|
||||||
filepath = file.path
|
filepath = file.path
|
||||||
filename = file.name
|
filename = file.name
|
||||||
|
|
||||||
if match_name(filename, extension, exact_name):
|
if match_name(filename, extension):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
os.remove(filepath)
|
os.remove(filepath)
|
||||||
|
@ -56,65 +50,123 @@ def wait_for_file(waiting_dir: str, extension: str=None, exact_name: str=None) -
|
||||||
|
|
||||||
return (filepath, filename)
|
return (filepath, filename)
|
||||||
|
|
||||||
def write_metadata(metadata: dict):
|
def just_find_file(name: str) -> tuple[str]:
|
||||||
dir = metadata['label']
|
spl = name.split('.')
|
||||||
|
extension = spl[-1]
|
||||||
|
exact_name = name[:-len(extension)-1] if len(spl) > 1 else None
|
||||||
|
|
||||||
|
filepath, filename = scan_for_file(True, extension, exact_name)
|
||||||
|
if filepath is None:
|
||||||
|
try:
|
||||||
|
os.makedirs(WAITING_DIR, exist_ok=True)
|
||||||
|
filepath, filename = wait_for_file(WAITING_DIR, extension)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
os.rmdir(WAITING_DIR)
|
||||||
|
return
|
||||||
|
|
||||||
|
if filepath is not None:
|
||||||
|
tpath = os.path.join(TEMP_DIR.name, filename)
|
||||||
|
shutil.move(filepath, tpath)
|
||||||
|
filepath = tpath
|
||||||
|
|
||||||
|
return (filepath, filename)
|
||||||
|
|
||||||
|
# directory util fnctions
|
||||||
|
|
||||||
|
def make_path(channel: str, version: str=None, filename: str=None) -> str:
|
||||||
|
args = [channel, version, filename]
|
||||||
|
args = [i for i in args if i is not None]
|
||||||
|
return os.path.join(BASE_DIR, *args)
|
||||||
|
|
||||||
|
def list_channels() -> list[str]:
|
||||||
|
return next(os.walk(BASE_DIR))[1]
|
||||||
|
|
||||||
|
# verificatoin functions
|
||||||
|
|
||||||
|
def channel_exists(channel: str) -> bool:
|
||||||
|
"""Checks if channel exists"""
|
||||||
|
return os.path.isdir(make_path(channel))
|
||||||
|
|
||||||
|
def check_version_exists(version: str) -> str | None:
|
||||||
|
"""
|
||||||
|
Check if version exists in any channel.
|
||||||
|
If yes, returns that channel, otherwise None
|
||||||
|
"""
|
||||||
|
for channel in list_channels():
|
||||||
|
if os.path.isdir(make_path(channel, version)):
|
||||||
|
return channel
|
||||||
|
|
||||||
|
# metadata functions
|
||||||
|
|
||||||
|
def load_latest_data(channel: str) -> dict:
|
||||||
|
path = make_path(channel, 'latest', META_FILENAME)
|
||||||
|
if os.path.isfile(path):
|
||||||
|
return json.loads(open(path).read())
|
||||||
|
return {'id': 0}
|
||||||
|
|
||||||
|
def write_metadata(channel: str, metadata: dict):
|
||||||
|
version = metadata['label']
|
||||||
metadata = json.dumps(metadata)
|
metadata = json.dumps(metadata)
|
||||||
for filepath in [os.path.join('releases', dir, meta_file_name), latest_file_path]:
|
for filepath in [make_path(channel, version, META_FILENAME), make_path(channel, 'latest', META_FILENAME)]:
|
||||||
file = open(filepath, 'w')
|
with open(filepath, 'w') as file:
|
||||||
file.write(metadata)
|
file.write(metadata)
|
||||||
file.close()
|
|
||||||
|
# other
|
||||||
|
|
||||||
|
def confirm(prompt: str) -> bool:
|
||||||
|
confirmed = input(prompt + ' (Y/N) ')
|
||||||
|
return confirmed.lower() == 'y'
|
||||||
|
|
||||||
|
def hash_file(filepath: str) -> str:
|
||||||
|
with open(filepath, 'rb') as file:
|
||||||
|
return sha256(file.read()).hexdigest()
|
||||||
|
|
||||||
|
# main
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
latest_data = load_latest_data()
|
channel = input('Channel? ({}) '.format(', '.join(list_channels())))
|
||||||
if latest_data['id'] > 0:
|
if not channel_exists(channel):
|
||||||
print(f"Current release: {latest_data['label']}")
|
print(f"Channel {channel} doesn't exist")
|
||||||
print(f"Released {time.strftime('%d.%m.%Y %H:%M', time.localtime(latest_data['timestamp']))}")
|
return
|
||||||
print('')
|
|
||||||
|
|
||||||
version = input('New version? ')
|
version = input('New version? ')
|
||||||
|
exists_in = check_version_exists(version)
|
||||||
|
if exists_in is not None:
|
||||||
|
print(f"This version already exists in channel {exists_in}. Choose a different version.")
|
||||||
|
return
|
||||||
|
|
||||||
if os.path.isdir(version):
|
jar_filepath, jar_filename = just_find_file('jar')
|
||||||
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?')
|
changelog = confirm('Do you want to include a changelog?')
|
||||||
if changelog:
|
if changelog:
|
||||||
cfilepath, cfilename = scan_for_file(ask=True, exact_name='changelog.txt')
|
chlog_filepath, chlog_filename = just_find_file('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)
|
#
|
||||||
|
|
||||||
|
latest_data = load_latest_data(channel)
|
||||||
|
hash = hash_file(jar_filepath)
|
||||||
|
|
||||||
|
version_dir = make_path(channel, version)
|
||||||
|
|
||||||
|
os.makedirs(make_path(channel, 'latest'), exist_ok=True)
|
||||||
os.mkdir(version_dir)
|
os.mkdir(version_dir)
|
||||||
os.rename(filepath, os.path.join(version_dir, filename))
|
shutil.move(jar_filepath, os.path.join(version_dir, jar_filename))
|
||||||
if changelog: os.rename(cfilepath, os.path.join(version_dir, 'changelog.txt'))
|
if changelog: shutil.move(chlog_filepath, os.path.join(version_dir, 'changelog.txt'))
|
||||||
|
|
||||||
try:
|
|
||||||
os.rmdir('pending')
|
|
||||||
except FileNotFoundError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
metadata = {
|
metadata = {
|
||||||
'label': version,
|
'label': version,
|
||||||
'id': latest_data['id'] + 1,
|
'id': latest_data['id'] + 1,
|
||||||
'timestamp': int(time.time()),
|
'timestamp': int(time.time()),
|
||||||
'file': filename
|
'file': jar_filename,
|
||||||
|
'sha256': hash
|
||||||
}
|
}
|
||||||
write_metadata(metadata)
|
|
||||||
|
write_metadata(channel, metadata)
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.rmdir(WAITING_DIR)
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
|
||||||
print("Done, don't forget to commit and push")
|
print("Done, don't forget to commit and push")
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
{"label": "0.9-alpha.1", "id": 1, "timestamp": 1718539114, "file": "realweather-0.9-SNAPSHOT.jar"}
|
|
12
reset.py
12
reset.py
|
@ -1,7 +1,10 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from os import remove, mkdir
|
from os import remove, mkdir, path
|
||||||
|
|
||||||
|
BASE_DIR = 'data'
|
||||||
|
CHANNELS = ['release', 'testing']
|
||||||
|
|
||||||
confirmation = input('If you really want to delete all releases, type CONFIRM: ')
|
confirmation = input('If you really want to delete all releases, type CONFIRM: ')
|
||||||
|
|
||||||
|
@ -9,8 +12,9 @@ if confirmation != 'CONFIRM':
|
||||||
print('Cancelled')
|
print('Cancelled')
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
for dir in ['releases', 'latest']:
|
rmtree(BASE_DIR, ignore_errors=True)
|
||||||
rmtree(dir)
|
mkdir(BASE_DIR)
|
||||||
mkdir(dir)
|
for channel in CHANNELS:
|
||||||
|
mkdir(path.join(BASE_DIR, channel))
|
||||||
|
|
||||||
print('Reset complete')
|
print('Reset complete')
|
||||||
|
|
Loading…
Reference in a new issue