Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Mar 14, 2024
1 parent 4db439f commit d54c822
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 179 deletions.
18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
# Flipper Zero Update Indexer and Uploader

## Start localy
## Start locally
```bash
INDEXER_FIRMWARE_GITHUB_TOKEN= \
INDEXER_QFLIPPER_GITHUB_TOKEN= \
INDEXER_GITHUB_ORGANIZATION= \
INDEXER_QFLIPPER_GITHUB_REPO= \
INDEXER_FIRMWARE_GITHUB_REPO= \
INDEXER_BLACKMAGIC_GITHUB_TOKEN= \
INDEXER_BLACKMAGIC_GITHUB_REPO= \
INDEXER_TOKEN= \
INDEXER_BASE_URL= \
INDEXER_FILES_DIR= \
make run
```

Expand All @@ -31,7 +23,6 @@ Get latest release
# format: 127.0.0.1:8000/{directory}/{channel}/{target}/{type}
# if target contains '/' (slash) replace it by '-' dash symbol
curl 127.0.0.1:8000/firmware/release/f7/updater_json
curl 127.0.0.1:8000/qFlipper/release/windows-amd64/installer
```

Trigger reindex
Expand All @@ -47,10 +38,3 @@ Upload files
-F "[email protected]" \
127.0.0.1:8000/firmware/uploadfiles
```

Upload files without reindex
```bash
curl -L -H "Token: YOUR_TOKEN" \
-F "[email protected]" \
127.0.0.1:8000/toolchain/uploadfilesraw
```
5 changes: 0 additions & 5 deletions indexer/src/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
title="Development Channel",
description="Latest builds, might sometimes be unstable",
)
# release_candidate_channel = Channel(
# id="release-candidate",
# title="Release Candidate Channel",
# description="This is going to be released soon, undergoing QA tests now",
# )
release_channel = Channel(
id="release",
title="Stable Release Channel",
Expand Down
6 changes: 3 additions & 3 deletions indexer/src/directories.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def latest_request(directory, channel, target, file_type):
of a specific version
Args:
directory: Repository name
channel: Channel type (release, rc, dev)
channel: Channel type (release, dev)
target: Operating System (linux, mac, win)
file_type: File Type
Expand All @@ -59,13 +59,13 @@ async def latest_request(directory, channel, target, file_type):
response_class=FileResponse,
status_code=200,
)
async def latest_request(directory, channel, file_name):
async def file_request(directory, channel, file_name):
"""
A method for retrieving a file from the repository
of a specific version
Args:
directory: Repository name
channel: Channel type (release, rc, dev)
channel: Channel type (release, dev)
file_name: File Name
Returns:
Expand Down
83 changes: 1 addition & 82 deletions indexer/src/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,6 @@ def get_release_version(self) -> Version:
except StopIteration:
return None

def get_rc_version(self) -> Version:
releases = self.__repo.get_releases()
if releases.totalCount == 0:
logging.warning(f"No release-candidates found for {self.__repo.full_name}!")
return None
try:
last_release = next(filter(lambda c: c.prerelease, releases))
return Version(
version=last_release.title,
changelog=last_release.body,
timestamp=int(last_release.created_at.timestamp()),
)
except StopIteration:
return None


class FileParser(BaseModel):
target: str = ""
Expand All @@ -156,73 +141,7 @@ def getSHA256(self, filepath: str) -> str:
return sha256

def parse(self, filename: str) -> None:
regex = re.compile(r"^flipper-z-(\w+)-(\w+)-mntm-([0-9]+(-rc)?|(dev-\w+))\.(\w+)$")
match = regex.match(filename)
if not match:
exception_msg = f"Unknown file {filename}"
logging.exception(exception_msg)
raise Exception(exception_msg)
self.target = match.group(1)
self.type = match.group(2) + "_" + match.group(6)


class qFlipperFileParser(FileParser):
def parse(self, filename: str) -> None:
regex = re.compile(
r"^(qFlipper\w*)(-.+)*-([0-9.a]+(-rc\d+)?|(dev-\w+-\w+))\.(\w+)$"
)
match = regex.match(filename)
if not match:
return
arch = match.group(2)
extention = match.group(6)
if extention == "dmg":
target = "macos"
file_type = "dmg"
elif extention == "zip":
target = "windows"
file_type = "portable"
elif extention == "AppImage":
target = "linux"
file_type = "AppImage"
elif extention == "exe":
target = "windows"
file_type = "installer"
else:
exception_msg = f"Unknown file extention {extention}"
logging.exception(exception_msg)
raise Exception(exception_msg)
if extention == "dmg": # MacOS case
jsonArch = "amd64"
else:
arch = arch.split("-")[1]
if arch in ["64bit", "x86_64"]:
jsonArch = "amd64"
else:
exception_msg = f"Cannot parse target, arch = {arch}"
logging.exception(exception_msg)
raise Exception(exception_msg)
self.target = target + "/" + jsonArch
self.type = file_type


class blackmagicFileParser(FileParser):
def parse(self, filename: str) -> None:
regex = re.compile(
r"^blackmagic-firmware-(\w+)-(\w+)-([0-9.]+(-rc)?|(dev-\w+-\w+))\.(\w+)$"
)
match = regex.match(filename)
if not match:
exception_msg = f"Unknown file {filename}"
logging.exception(exception_msg)
raise Exception(exception_msg)
self.target = match.group(1)
self.type = match.group(2) + "_" + match.group(6)


class vgmFileParser(FileParser):
def parse(self, filename: str) -> None:
regex = re.compile(r"^vgm-(\w+)-(\w+)-([0-9.]+(-rc)?|(dev-\w+-\w+))\.(\w+)$")
regex = re.compile(r"^flipper-z-(\w+)-(\w+)-mntm-([0-9]+()?|(dev-\w+))\.(\w+)$")
match = regex.match(filename)
if not match:
exception_msg = f"Unknown file {filename}"
Expand Down
35 changes: 3 additions & 32 deletions indexer/src/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def parse_dev_channel(
Args:
channel: Channel model (-> dev)
directory: Save directory
file_parser: The method by which the file piercing will take place (qFlipper, FileParser)
file_parser: The method by which the file piercing will take place (FileParser)
Returns:
New channel with added version
Expand All @@ -84,7 +84,7 @@ def parse_release_channel(
Args:
channel: Channel model (-> release)
directory: Save directory
file_parser: The method by which the file piercing will take place (qFlipper, FileParser)
file_parser: The method by which the file piercing will take place (FileParser)
Returns:
New channel with added version
Expand All @@ -96,38 +96,14 @@ def parse_release_channel(
return channel


def parse_rc_channel(
channel: Channel,
directory: str,
file_parser: FileParser,
indexer_github: IndexerGithub,
) -> Channel:
"""
Method for creating a new version with a file
and adding it to the rc channel
Args:
channel: Channel model (-> release-candidate)
directory: Save directory
file_parser: The method by which the file piercing will take place (qFlipper, FileParser)
Returns:
New channel with added version
"""
version = indexer_github.get_rc_version()
if version:
version = add_files_to_version(version, file_parser, directory, version.version)
channel.add_version(version)
return channel


def parse_github_channels(
directory: str, file_parser: FileParser, indexer_github: IndexerGithub
) -> dict:
"""
Method for creating a new index with channels
Args:
directory: Save directory
file_parser: The method by which the file piercing will take place (qFlipper, FileParser)
file_parser: The method by which the file piercing will take place (FileParser)
Returns:
New index with added channels
Expand All @@ -146,9 +122,4 @@ def parse_github_channels(
indexer_github,
)
)
# json.add_channel(
# parse_rc_channel(
# copy.deepcopy(release_candidate_channel), directory, file_parser, indexer_github
# )
# )
return json.dict()
32 changes: 5 additions & 27 deletions indexer/src/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from .parsers import parse_github_channels
from .models import *
from .settings import settings
from .models import qFlipperFileParser, blackmagicFileParser, vgmFileParser


class RepositoryIndex:
Expand Down Expand Up @@ -73,8 +72,8 @@ def delete_unlinked_directories(self):

def reindex(self):
"""
Method for starting reindexing. We get three channels - dev, release,
rc from the main repository in the git. We run through all 3 channels,
Method for starting reindexing. We get three channels - dev, release
from the main repository in the git. We run through all 3 channels,
each channel has different versions inside. We create models for all
versions and stuff them with the path to the artifacts.
Expand Down Expand Up @@ -103,7 +102,7 @@ def get_file_from_latest_version(
A method to get a file in the latest version of the
current directory by its target and type
Args:
channel: Channel type (release, rc, dev)
channel: Channel type (release, dev)
target: Operating System (linux, mac, win)
file_type: File Type
Expand Down Expand Up @@ -141,7 +140,7 @@ def get_file_path(
A method to get a file in the latest version of the
current directory by its target and type
Args:
channel: Channel type (release, rc, dev)
channel: Channel type (release, dev)
file_name: File Name
Returns:
Expand All @@ -157,27 +156,6 @@ def get_file_path(
github_repo=settings.firmware_github_repo,
github_org=settings.github_org,
),
# "qFlipper": RepositoryIndex(
# directory="qFlipper",
# github_token=settings.qFlipper_github_token,
# github_repo=settings.qFlipper_github_repo,
# github_org=settings.github_org,
# file_parser=qFlipperFileParser,
# ),
# "blackmagic-firmware": RepositoryIndex(
# directory="blackmagic-firmware",
# github_token=settings.blackmagic_github_token,
# github_repo=settings.blackmagic_github_repo,
# github_org=settings.github_org,
# file_parser=blackmagicFileParser,
# ),
# "vgm-firmware": RepositoryIndex(
# directory="vgm-firmware",
# github_token=settings.vgm_github_token,
# github_repo=settings.vgm_github_repo,
# github_org=settings.github_org,
# file_parser=vgmFileParser,
# ),
}

raw_file_upload_directories = ["toolchain"]
raw_file_upload_directories = []
12 changes: 0 additions & 12 deletions indexer/src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ class Settings(BaseModel):
kubernetes_pod: str = None
firmware_github_token: str
firmware_github_repo: str
# qFlipper_github_token: str
# qFlipper_github_repo: str
# blackmagic_github_token: str
# blackmagic_github_repo: str
# vgm_github_token: str
# vgm_github_repo: str
private_paths: List[str]


Expand All @@ -43,11 +37,5 @@ class Settings(BaseModel):
kubernetes_pod=os.getenv("HOSTNAME"),
firmware_github_token=os.getenv("INDEXER_FIRMWARE_GITHUB_TOKEN"),
firmware_github_repo="Momentum-Firmware",
# qFlipper_github_token=os.getenv("INDEXER_QFLIPPER_GITHUB_TOKEN"),
# qFlipper_github_repo=os.getenv("INDEXER_QFLIPPER_GITHUB_REPO"),
# blackmagic_github_token=os.getenv("INDEXER_BLACKMAGIC_GITHUB_TOKEN"),
# blackmagic_github_repo=os.getenv("INDEXER_BLACKMAGIC_GITHUB_REPO"),
# vgm_github_token=os.getenv("INDEXER_VGM_GITHUB_TOKEN"),
# vgm_github_repo=os.getenv("INDEXER_VGM_GITHUB_REPO"),
private_paths=["reindex", "uploadfiles", "uploadfilesraw"],
)
2 changes: 1 addition & 1 deletion nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ http {
fancyindex_localtime on;
fancyindex_ignore "nginx-theme";
}
location ~ ^/(qFlipper|firmware|blackmagic-firmware|vgm-firmware|toolchain)/ {
location ~ ^/(firmware)/ {
more_set_headers 'Cache-Control: no-cache, max-age=0, s-max-age=0, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
Expand Down

0 comments on commit d54c822

Please sign in to comment.