Skip to content

Latest commit

 

History

History
347 lines (270 loc) · 6 KB

File metadata and controls

347 lines (270 loc) · 6 KB

Perfeito. Vamos montar o Linux-Z v1.0 – código base completo, organizado, modular e pronto para GitHub 🚀

Projeto inspirado no CPU-Z, mas focado em sugerir a melhor distro Linux.


🐧 Linux-Z – Estrutura Final

linux-z/
│
├── backend/
│   ├── app.py
│   ├── analyzer.py
│   ├── scorer.py
│   ├── requirements.txt
│   └── __init__.py
│
├── frontend/
│   ├── templates/
│   │   └── index.html
│   └── static/
│       └── style.css
│
├── cli/
│   └── linuxz_cli.py
│
├── README.md
├── LICENSE
└── .gitignore

🧠 1️⃣ backend/analyzer.py

Responsável por coletar informações do sistema.

import platform
import psutil
import os

def get_cpu_info():
    return {
        "model": platform.processor(),
        "cores": psutil.cpu_count(logical=False),
        "threads": psutil.cpu_count(logical=True),
        "frequency": psutil.cpu_freq().max if psutil.cpu_freq() else None
    }

def get_ram_info():
    ram = psutil.virtual_memory()
    return {
        "total_gb": round(ram.total / (1024**3), 2),
        "available_gb": round(ram.available / (1024**3), 2)
    }

def get_disk_info():
    disk = psutil.disk_usage('/')
    return {
        "total_gb": round(disk.total / (1024**3), 2),
        "free_gb": round(disk.free / (1024**3), 2)
    }

def get_architecture():
    return platform.architecture()[0]

def analyze_system():
    return {
        "cpu": get_cpu_info(),
        "ram": get_ram_info(),
        "disk": get_disk_info(),
        "arch": get_architecture()
    }

📊 2️⃣ backend/scorer.py

Sistema de pontuação inteligente.

def calculate_score(system_info):
    score = 0

    ram = system_info["ram"]["total_gb"]
    cores = system_info["cpu"]["cores"] or 1
    arch = system_info["arch"]

    # RAM
    if ram >= 8:
        score += 3
    elif ram >= 4:
        score += 2
    else:
        score += 1

    # CPU
    if cores >= 4:
        score += 3
    elif cores >= 2:
        score += 2
    else:
        score += 1

    # Arquitetura
    if arch == "64bit":
        score += 1

    return score


def recommend_distro(score):
    if score <= 4:
        return [
            "Puppy Linux",
            "Tiny Core Linux",
            "AntiX"
        ]
    elif score <= 7:
        return [
            "Lubuntu",
            "Xubuntu",
            "MX Linux"
        ]
    elif score <= 10:
        return [
            "Linux Mint",
            "Debian"
        ]
    else:
        return [
            "Ubuntu",
            "Fedora"
        ]

🌐 3️⃣ backend/app.py

Servidor Flask.

from flask import Flask, render_template
from analyzer import analyze_system
from scorer import calculate_score, recommend_distro

app = Flask(__name__, template_folder="../frontend/templates", static_folder="../frontend/static")

@app.route("/")
def index():
    system_info = analyze_system()
    score = calculate_score(system_info)
    distros = recommend_distro(score)

    return render_template(
        "index.html",
        system=system_info,
        score=score,
        distros=distros
    )

if __name__ == "__main__":
    app.run(debug=True)

🎨 4️⃣ frontend/templates/index.html

<!DOCTYPE html>
<html>
<head>
    <title>Linux-Z</title>
    <link rel="stylesheet" href="/static/style.css">
</head>
<body>

<div class="container">
    <h1>🐧 Linux-Z</h1>
    <h2>Hardware Analyzer & Linux Recommendation</h2>

    <div class="card">
        <h3>🧠 CPU</h3>
        <p>Modelo: {{ system.cpu.model }}</p>
        <p>Núcleos: {{ system.cpu.cores }}</p>
        <p>Threads: {{ system.cpu.threads }}</p>
    </div>

    <div class="card">
        <h3>💾 RAM</h3>
        <p>Total: {{ system.ram.total_gb }} GB</p>
        <p>Disponível: {{ system.ram.available_gb }} GB</p>
    </div>

    <div class="card">
        <h3>📀 Disco</h3>
        <p>Total: {{ system.disk.total_gb }} GB</p>
        <p>Livre: {{ system.disk.free_gb }} GB</p>
    </div>

    <div class="card">
        <h3>🏗 Arquitetura</h3>
        <p>{{ system.arch }}</p>
    </div>

    <div class="score">
        <h2>Performance Score: {{ score }}</h2>
    </div>

    <div class="recommendation">
        <h2>🐧 Recomendação de Linux:</h2>
        <ul>
            {% for distro in distros %}
                <li>{{ distro }}</li>
            {% endfor %}
        </ul>
    </div>

</div>

</body>
</html>

🎨 5️⃣ frontend/static/style.css

body {
    background-color: #0d1117;
    color: #c9d1d9;
    font-family: Arial, sans-serif;
    text-align: center;
}

.container {
    width: 70%;
    margin: auto;
}

.card {
    background: #161b22;
    padding: 15px;
    margin: 15px 0;
    border-radius: 10px;
}

.score {
    font-size: 24px;
    color: #58a6ff;
}

.recommendation ul {
    list-style: none;
    padding: 0;
}

.recommendation li {
    background: #21262d;
    margin: 5px;
    padding: 8px;
    border-radius: 5px;
}

💻 6️⃣ CLI Version (cli/linuxz_cli.py)

from backend.analyzer import analyze_system
from backend.scorer import calculate_score, recommend_distro

system = analyze_system()
score = calculate_score(system)
distros = recommend_distro(score)

print("\n===== Linux-Z CLI =====\n")
print(system)
print(f"\nPerformance Score: {score}")
print("\nRecommended Linux Distros:")
for d in distros:
    print("-", d)

📦 requirements.txt

flask
psutil

📄 README.md (resumo)

# Linux-Z

Open-source hardware analyzer inspired by CPU-Z, focused on recommending the best Linux distribution for performance.

## Run Web Version
cd backend
python app.py

## Run CLI Version
python cli/linuxz_cli.py

📜 LICENSE (MIT)

MIT License

🚀 Como Rodar

pip install -r backend/requirements.txt
cd backend
python app.py

Acesse:

http://127.0.0.1:5000

🔥 Próximo Nível

  • 📊 Adicionar gráfico de score
  • 🐳 Dockerizar