Add alpha and beta versions
This commit is contained in:
345
beta1/gitea_analyzer_app/main.py
Normal file
345
beta1/gitea_analyzer_app/main.py
Normal file
@@ -0,0 +1,345 @@
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
|
||||
from api import get_repo_data, get_commits, get_code_lines
|
||||
from parser import parse_repo_info, parse_authors
|
||||
from storage import (
|
||||
register_user,
|
||||
check_user,
|
||||
get_repositories,
|
||||
add_repository,
|
||||
delete_repository,
|
||||
)
|
||||
|
||||
|
||||
class GiteaAnalyzerApp:
|
||||
def __init__(self):
|
||||
self.root = tk.Tk()
|
||||
|
||||
self.root.title("Gitea Analyzer")
|
||||
self.root.geometry("1200x800")
|
||||
self.root.attributes("-zoomed", True)
|
||||
|
||||
self.current_user = None
|
||||
|
||||
self.bg = "#eef4ff"
|
||||
self.panel = "#ffffff"
|
||||
self.button = "#6aa6ff"
|
||||
|
||||
self.root.configure(bg=self.bg)
|
||||
|
||||
self.show_splash()
|
||||
|
||||
self.root.mainloop()
|
||||
|
||||
def clear(self):
|
||||
for widget in self.root.winfo_children():
|
||||
widget.destroy()
|
||||
|
||||
def make_button(self, parent, text, command, width=25):
|
||||
return tk.Button(
|
||||
parent,
|
||||
text=text,
|
||||
command=command,
|
||||
width=width,
|
||||
bg=self.button,
|
||||
fg="white",
|
||||
activebackground="#4d8ee8",
|
||||
font=("Arial", 11, "bold"),
|
||||
relief="flat",
|
||||
cursor="hand2",
|
||||
pady=6,
|
||||
)
|
||||
|
||||
def show_splash(self):
|
||||
self.clear()
|
||||
|
||||
frame = tk.Frame(self.root, bg=self.bg)
|
||||
frame.pack(expand=True)
|
||||
|
||||
tk.Label(
|
||||
frame,
|
||||
text="Gitea Repository Analyzer",
|
||||
font=("Arial", 28, "bold"),
|
||||
bg=self.bg,
|
||||
fg="#1d3557",
|
||||
).pack(pady=20)
|
||||
|
||||
tk.Label(
|
||||
frame,
|
||||
text="Анализ репозиториев Gitea",
|
||||
font=("Arial", 14),
|
||||
bg=self.bg,
|
||||
).pack(pady=10)
|
||||
|
||||
tk.Label(
|
||||
frame,
|
||||
text="Загрузка...",
|
||||
font=("Arial", 12),
|
||||
bg=self.bg,
|
||||
).pack(pady=30)
|
||||
|
||||
self.root.after(1500, self.show_login)
|
||||
|
||||
def show_login(self):
|
||||
self.clear()
|
||||
|
||||
frame = tk.Frame(self.root, bg=self.panel, padx=40, pady=40)
|
||||
frame.place(relx=0.5, rely=0.5, anchor="center")
|
||||
|
||||
tk.Label(
|
||||
frame,
|
||||
text="Вход",
|
||||
font=("Arial", 22, "bold"),
|
||||
bg=self.panel,
|
||||
).pack(pady=10)
|
||||
|
||||
tk.Label(frame, text="Логин", bg=self.panel).pack(anchor="w")
|
||||
|
||||
login_entry = tk.Entry(frame, width=35, font=("Arial", 12))
|
||||
login_entry.pack(pady=5)
|
||||
|
||||
tk.Label(frame, text="Пароль", bg=self.panel).pack(anchor="w")
|
||||
|
||||
password_entry = tk.Entry(
|
||||
frame,
|
||||
width=35,
|
||||
font=("Arial", 12),
|
||||
show="*",
|
||||
)
|
||||
password_entry.pack(pady=5)
|
||||
|
||||
def login():
|
||||
login_value = login_entry.get().strip()
|
||||
password_value = password_entry.get().strip()
|
||||
|
||||
if not login_value or not password_value:
|
||||
messagebox.showerror(
|
||||
"Ошибка",
|
||||
"Введите логин и пароль",
|
||||
)
|
||||
return
|
||||
|
||||
if check_user(login_value, password_value):
|
||||
self.current_user = login_value
|
||||
self.show_main_screen()
|
||||
else:
|
||||
messagebox.showerror(
|
||||
"Ошибка",
|
||||
"Неверный логин или пароль",
|
||||
)
|
||||
|
||||
self.make_button(frame, "Войти", login).pack(pady=10)
|
||||
|
||||
self.make_button(
|
||||
frame,
|
||||
"Создать профиль",
|
||||
self.show_register,
|
||||
).pack(pady=5)
|
||||
|
||||
def show_register(self):
|
||||
self.clear()
|
||||
|
||||
frame = tk.Frame(self.root, bg=self.panel, padx=40, pady=40)
|
||||
frame.place(relx=0.5, rely=0.5, anchor="center")
|
||||
|
||||
tk.Label(
|
||||
frame,
|
||||
text="Регистрация",
|
||||
font=("Arial", 22, "bold"),
|
||||
bg=self.panel,
|
||||
).pack(pady=10)
|
||||
|
||||
tk.Label(frame, text="Логин", bg=self.panel).pack(anchor="w")
|
||||
|
||||
login_entry = tk.Entry(frame, width=35, font=("Arial", 12))
|
||||
login_entry.pack(pady=5)
|
||||
|
||||
tk.Label(frame, text="Пароль", bg=self.panel).pack(anchor="w")
|
||||
|
||||
password_entry = tk.Entry(
|
||||
frame,
|
||||
width=35,
|
||||
font=("Arial", 12),
|
||||
show="*",
|
||||
)
|
||||
password_entry.pack(pady=5)
|
||||
|
||||
def register():
|
||||
login_value = login_entry.get().strip()
|
||||
password_value = password_entry.get().strip()
|
||||
|
||||
if not login_value or not password_value:
|
||||
messagebox.showerror(
|
||||
"Ошибка",
|
||||
"Введите логин и пароль",
|
||||
)
|
||||
return
|
||||
|
||||
ok, text = register_user(
|
||||
login_value,
|
||||
password_value,
|
||||
)
|
||||
|
||||
if ok:
|
||||
messagebox.showinfo("Готово", text)
|
||||
self.show_login()
|
||||
else:
|
||||
messagebox.showerror("Ошибка", text)
|
||||
|
||||
self.make_button(
|
||||
frame,
|
||||
"Зарегистрироваться",
|
||||
register,
|
||||
).pack(pady=10)
|
||||
|
||||
self.make_button(
|
||||
frame,
|
||||
"Назад",
|
||||
self.show_login,
|
||||
).pack(pady=5)
|
||||
|
||||
def show_main_screen(self):
|
||||
self.clear()
|
||||
|
||||
top = tk.Frame(self.root, bg="#1d3557", height=60)
|
||||
top.pack(fill="x")
|
||||
|
||||
tk.Label(
|
||||
top,
|
||||
text=f"Gitea Analyzer | {self.current_user}",
|
||||
bg="#1d3557",
|
||||
fg="white",
|
||||
font=("Arial", 16, "bold"),
|
||||
).pack(side="left", padx=20, pady=15)
|
||||
|
||||
content = tk.Frame(self.root, bg=self.bg)
|
||||
content.pack(fill="both", expand=True, padx=15, pady=15)
|
||||
|
||||
left = tk.Frame(content, bg=self.panel, padx=15, pady=15)
|
||||
left.pack(side="left", fill="y")
|
||||
|
||||
right = tk.Frame(content, bg=self.panel, padx=15, pady=15)
|
||||
right.pack(side="right", fill="both", expand=True, padx=(15, 0))
|
||||
|
||||
tk.Label(
|
||||
left,
|
||||
text="Репозитории",
|
||||
bg=self.panel,
|
||||
font=("Arial", 15, "bold"),
|
||||
).pack(anchor="w")
|
||||
|
||||
repo_listbox = tk.Listbox(
|
||||
left,
|
||||
width=45,
|
||||
height=22,
|
||||
font=("Arial", 10),
|
||||
)
|
||||
repo_listbox.pack(pady=10)
|
||||
|
||||
repo_entry = tk.Entry(
|
||||
left,
|
||||
width=45,
|
||||
font=("Arial", 10),
|
||||
)
|
||||
repo_entry.pack(pady=5)
|
||||
|
||||
result_text = tk.Text(
|
||||
right,
|
||||
font=("Consolas", 11),
|
||||
wrap="word",
|
||||
)
|
||||
result_text.pack(fill="both", expand=True)
|
||||
|
||||
def refresh_list():
|
||||
repo_listbox.delete(0, tk.END)
|
||||
|
||||
for repo in get_repositories(self.current_user):
|
||||
repo_listbox.insert(tk.END, repo)
|
||||
|
||||
def get_selected_repo():
|
||||
selection = repo_listbox.curselection()
|
||||
|
||||
if not selection:
|
||||
return None
|
||||
|
||||
return repo_listbox.get(selection[0])
|
||||
|
||||
def save_repo():
|
||||
link = repo_entry.get().strip()
|
||||
|
||||
if not link:
|
||||
messagebox.showerror(
|
||||
"Ошибка",
|
||||
"Введите ссылку",
|
||||
)
|
||||
return
|
||||
|
||||
add_repository(self.current_user, link)
|
||||
|
||||
repo_entry.delete(0, tk.END)
|
||||
|
||||
refresh_list()
|
||||
|
||||
def analyze_repo():
|
||||
link = get_selected_repo()
|
||||
|
||||
if not link:
|
||||
messagebox.showerror(
|
||||
"Ошибка",
|
||||
"Выберите репозиторий",
|
||||
)
|
||||
return
|
||||
|
||||
try:
|
||||
result_text.delete("1.0", tk.END)
|
||||
|
||||
repo_data = get_repo_data(link)
|
||||
commits = get_commits(link)
|
||||
lines = get_code_lines(link)
|
||||
|
||||
info = parse_repo_info(repo_data)
|
||||
authors = parse_authors(commits)
|
||||
|
||||
result_text.insert(tk.END, f"Ссылка: {link}\n\n")
|
||||
result_text.insert(tk.END, info)
|
||||
|
||||
result_text.insert(
|
||||
tk.END,
|
||||
"\nСоавторы:\n",
|
||||
)
|
||||
|
||||
for author in authors:
|
||||
result_text.insert(
|
||||
tk.END,
|
||||
f"- {author}\n",
|
||||
)
|
||||
|
||||
result_text.insert(
|
||||
tk.END,
|
||||
f"\nСтрок Python-кода: {lines}\n",
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
messagebox.showerror(
|
||||
"Ошибка",
|
||||
str(e),
|
||||
)
|
||||
|
||||
self.make_button(
|
||||
left,
|
||||
"Сохранить ссылку",
|
||||
save_repo,
|
||||
).pack(pady=5)
|
||||
|
||||
self.make_button(
|
||||
left,
|
||||
"Обновить информацию",
|
||||
analyze_repo,
|
||||
).pack(pady=5)
|
||||
|
||||
refresh_list()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
GiteaAnalyzerApp()
|
||||
Reference in New Issue
Block a user