Skip to content

Commit

Permalink
feat: show head commit of local agac repo
Browse files Browse the repository at this point in the history
r3tr0ananas committed Aug 4, 2024
1 parent 154e4be commit 12f86de
Showing 3 changed files with 23 additions and 10 deletions.
22 changes: 16 additions & 6 deletions api/agac.py
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
import subprocess

from .image import Image
from .constants import GIT_PATH, ALLOWED_FILE_EXTENSIONS
from .constants import GIT_PATH, ALLOWED_FILE_EXTENSIONS

__all__ = ("Agac",)

@@ -19,7 +19,7 @@ class Agac:
def __init__(self) -> None:
self._repo_path = Path(GIT_PATH)

self.__update_repo()
self.head_commit = self.__update_repo()
self.images, self.categories = self.__phrase_images()

def get_random(self, categorie: str = None) -> Image:
@@ -42,7 +42,7 @@ def __update_repo(self):
)

process = subprocess.Popen(
["git", "pull"],
["git", "pull"],
text = True,
stdout = subprocess.PIPE,
cwd = self._repo_path
@@ -51,10 +51,20 @@ def __update_repo(self):
process.wait()
output, _ = process.communicate()

if not process.returncode == 0:
print("Git Error")
if not process.returncode == 0:
print(f"ERROR: {output}")

print(f"Git Output: {output}")
hash_process = subprocess.Popen(
["git", "rev-parse", "HEAD"],
text = True,
stdout = subprocess.PIPE,
cwd = self._repo_path
)

hash_process.wait()
hash, _ = hash_process.communicate()

return hash.replace("\n", "")

def __phrase_images(self) -> Union[List[Image], Dict[str, List[Image]]]:
images = []
6 changes: 4 additions & 2 deletions api/constants.py
Original file line number Diff line number Diff line change
@@ -3,10 +3,12 @@
__all__ = (
"GIT_PATH",
"GIT_REPO_URL",
"ALLOWED_FILE_EXTENSIONS"
"CACHE_PATH",
"ALLOWED_FILE_EXTENSIONS",
"RATE_LIMIT"
)

ALLOWED_FILE_EXTENSIONS = [".png", ".jpeg", ".jpg"]
ALLOWED_FILE_EXTENSIONS = [".png", ".jpeg", ".jpg", ".webp"]
GIT_PATH = config("GIT_PATH", default = "./assets/repo", cast = str)
CACHE_PATH = config("CACHE_PATH", default = "./assets/cache", cast = str)
GIT_REPO_URL = config("GIT_REPO_URL", default = "https://github.com/THEGOLDENPRO/anime-girls-and-computers", cast = str)
5 changes: 3 additions & 2 deletions api/main.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
from .constants import RATE_LIMIT
from . import __version__, errors

ROOT_PATH = (lambda x: x if x is not None else "")(environ.get("ROOT_PATH"))
ROOT_PATH = environ.get("ROOT_PATH", "")

TAGS_METADATA = [
{
@@ -79,7 +79,8 @@ async def info():
"""Returns repository information like image count and etc."""
return {
"version": __version__,
"image_count": len(agac.images)
"image_count": len(agac.images),
"agac_head_commit": agac.head_commit
}

@app.get(

0 comments on commit 12f86de

Please sign in to comment.