pre pre pre pre pre pre pre pre alpha
This commit is contained in:
commit
da284b3ae3
91
__main__.py
Executable file
91
__main__.py
Executable file
@ -0,0 +1,91 @@
|
||||
#! /bin/python3
|
||||
|
||||
import socket
|
||||
import os
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
||||
import apt_pkg
|
||||
|
||||
import apt
|
||||
import apt.progress.base
|
||||
|
||||
def get_change(current, total):
|
||||
if current == total:
|
||||
return 100.0
|
||||
try:
|
||||
return float("{:.1f}".format(((current * 100) / total)))
|
||||
except ZeroDivisionError:
|
||||
return 0.0
|
||||
|
||||
class UpdateProgressSocket(apt.progress.base.AcquireProgress):
|
||||
# Init
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
# Start
|
||||
def start(self):
|
||||
self.current_bytes = 0
|
||||
self.total_bytes = 0
|
||||
print("Starting APT Cache Update.")
|
||||
return super().start()
|
||||
|
||||
# Stop
|
||||
def stop(self):
|
||||
print("\nAPT Cache Update Complete!")
|
||||
return super().stop()
|
||||
|
||||
# Progrss pulse
|
||||
def pulse(self, owner):
|
||||
# Calculate current progress percentage
|
||||
progress_percent = get_change(self.current_bytes, self.total_bytes)
|
||||
|
||||
# apt_update_progress ipc sock
|
||||
socket_path = "/tmp/pika_apt_update.sock"
|
||||
|
||||
# Create a Unix domain socket
|
||||
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client:
|
||||
client.connect(socket_path)
|
||||
# Send percentage to socket as UTF-8
|
||||
client.sendall(str(progress_percent).encode('utf-8'))
|
||||
|
||||
#response = client.recv(1024)
|
||||
#print(f"Received: {response.decode('utf-8')}")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def fail(self, item):
|
||||
print("Failure at: %s %s" % (item.uri, item.shortdesc))
|
||||
|
||||
def fetch(self, item):
|
||||
print("Fetch: %s %s" % (item.uri, item.shortdesc))
|
||||
|
||||
def ims_hit(self, item):
|
||||
print("Download: %s %s" % (item.uri, item.shortdesc))
|
||||
|
||||
def media_change(self, medium, drive):
|
||||
print(f"Please insert medium {medium} in drive {drive}")
|
||||
sys.stdin.readline()
|
||||
# return False
|
||||
|
||||
def update_cache():
|
||||
# First of all, open the cache
|
||||
cache = apt.Cache()
|
||||
# Now, lets update the package list
|
||||
cache.update(UpdateProgressSocket())
|
||||
# We need to re-open the cache because it needs to read the package list
|
||||
cache.open(None)
|
||||
# We need to re-open the cache because it needs to read the package list
|
||||
for pkg in cache:
|
||||
if pkg.is_upgradable:
|
||||
print(f"{pkg.name} ({pkg.installed.version} -> {pkg.candidate.version})")
|
||||
|
||||
def process(data):
|
||||
# Echo the input data
|
||||
return data
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
update_cache()
|
82
src/apt_update/main.rs
Normal file
82
src/apt_update/main.rs
Normal file
@ -0,0 +1,82 @@
|
||||
use rust_apt::new_cache;
|
||||
use rust_apt::cache::*;
|
||||
use tokio::net::{UnixListener, UnixStream};
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use rust_apt::raw::progress::{AcquireProgress, AptAcquireProgress};
|
||||
use serde::{Serialize, Deserialize};
|
||||
#[derive(Serialize)]
|
||||
struct AptSendablePackage {
|
||||
name: String,
|
||||
arch: String,
|
||||
installed_version: String,
|
||||
candidate_version: String
|
||||
}
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let update_cache = new_cache!().unwrap();
|
||||
let mut update_progress: Box<dyn AcquireProgress> = Box::new(AptAcquireProgress::new());
|
||||
if let Err(error) = update_cache.update(&mut update_progress) {
|
||||
for msg in error.what().split(';') {
|
||||
if msg.starts_with("E:") {
|
||||
println!("Error: {}", &msg[2..]);
|
||||
}
|
||||
if msg.starts_with("W:") {
|
||||
println!("Warning: {}", &msg[2..]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create upgradable list cache
|
||||
let upgradable_cache = new_cache!().unwrap();
|
||||
|
||||
// Create pack sort from upgradable_cache
|
||||
let upgradable_sort = PackageSort::default().upgradable().names();
|
||||
|
||||
for pkg in upgradable_cache.packages(&upgradable_sort).unwrap().into_iter() {
|
||||
let package_struct = AptSendablePackage {
|
||||
name: pkg.name().to_string(),
|
||||
arch: pkg.arch().to_string(),
|
||||
installed_version: pkg.installed().unwrap().version().to_string(),
|
||||
candidate_version: pkg.candidate().unwrap().version().to_string()
|
||||
};
|
||||
|
||||
// Path to the Unix socket file
|
||||
let socket_path = "/tmp/rust-ipc.sock";
|
||||
|
||||
// Connect to the Unix socket
|
||||
let mut stream = UnixStream::connect(socket_path).await.expect("Could not connect to server");
|
||||
|
||||
let message = serde_json::to_string(&package_struct).unwrap();
|
||||
// Send the message to the server
|
||||
stream.write_all(message.as_bytes()).await.expect("Failed to write to stream");
|
||||
|
||||
// Buffer to store the server's response
|
||||
let mut buffer = [0; 2024];
|
||||
|
||||
// Read the response from the server
|
||||
match stream.read(&mut buffer).await {
|
||||
Ok(size) => {
|
||||
// Print the received response
|
||||
println!("Response from Server on GTK4: {}", String::from_utf8_lossy(&buffer[..size]));
|
||||
}
|
||||
Err(e) => {
|
||||
// Print error message if reading fails
|
||||
eprintln!("Failed to read Server on GTK4 with Error: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let cache = new_cache!().unwrap();
|
||||
let pkg = cache.get("neovim").unwrap();
|
||||
let mut progress = AptAcquireProgress::new_box();
|
||||
|
||||
progress.status
|
||||
|
||||
pkg.mark_install(true, true);
|
||||
pkg.protect();
|
||||
cache.resolve(true).unwrap();
|
||||
|
||||
cache.get_archives(&mut progress).unwrap();
|
||||
|
||||
progress.pulse()
|
||||
}
|
55
src/debug_server/main.rs
Normal file
55
src/debug_server/main.rs
Normal file
@ -0,0 +1,55 @@
|
||||
use tokio::net::{UnixListener, UnixStream};
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::task;
|
||||
use std::path::Path;
|
||||
use std::fs;
|
||||
|
||||
// Entry point of the server binary
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// Path to the Unix socket file
|
||||
let pika_apt_update_socket_path = "/tmp/pika_apt_update.sock";
|
||||
|
||||
// Remove the socket file if it already exists
|
||||
if Path::new(pika_apt_update_socket_path).exists() {
|
||||
fs::remove_file(pika_apt_update_socket_path).expect("Could not remove existing socket file");
|
||||
}
|
||||
|
||||
// Bind the Unix listener to the socket path
|
||||
let pika_apt_update_listener = UnixListener::bind(pika_apt_update_socket_path).expect("Could not bind");
|
||||
|
||||
println!("Server listening on {}", pika_apt_update_socket_path);
|
||||
|
||||
// Loop to accept incoming connections
|
||||
loop {
|
||||
// Accept an incoming connection
|
||||
match pika_apt_update_listener.accept().await {
|
||||
Ok((stream, _)) => {
|
||||
// Handle the connection in a separate task
|
||||
task::spawn(handle_client(stream));
|
||||
}
|
||||
Err(e) => {
|
||||
// Print error message if a connection fails
|
||||
eprintln!("pika_apt_update: Connection failed: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Function to handle a single client connection
|
||||
async fn handle_client(mut stream: UnixStream) {
|
||||
// Buffer to store incoming data
|
||||
let mut buffer = [0; 1024];
|
||||
|
||||
// Read data from the stream
|
||||
match stream.read(&mut buffer).await {
|
||||
Ok(size) => {
|
||||
// Print the received message
|
||||
println!("pika_apt_update: Received: {}", String::from_utf8_lossy(&buffer[..size]));
|
||||
}
|
||||
Err(e) => {
|
||||
// Print error message if reading fails
|
||||
eprintln!("Failed to read from stream: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
52
src/gui/main.rs
Normal file
52
src/gui/main.rs
Normal file
@ -0,0 +1,52 @@
|
||||
|
||||
mod config;
|
||||
mod build_ui;
|
||||
mod apt_update_page;
|
||||
|
||||
use std::env;
|
||||
use adw::prelude::*;
|
||||
use adw::*;
|
||||
use gdk::Display;
|
||||
use gtk::*;
|
||||
use std::boxed::Box;
|
||||
use build_ui::build_ui;
|
||||
use crate::config::{APP_ID};
|
||||
|
||||
// Init translations for current crate.
|
||||
#[macro_use]
|
||||
extern crate rust_i18n;
|
||||
i18n!("locales", fallback = "en_US");
|
||||
|
||||
/// main function
|
||||
fn main() {
|
||||
let current_locale = match env::var_os("LANG") {
|
||||
Some(v) => v.into_string().unwrap(),
|
||||
None => panic!("$LANG is not set"),
|
||||
};
|
||||
rust_i18n::set_locale(current_locale.strip_suffix(".UTF-8").unwrap());
|
||||
let application = adw::Application::new(
|
||||
Some(APP_ID),
|
||||
Default::default(),
|
||||
);
|
||||
application.connect_startup(|app| {
|
||||
// The CSS "magic" happens here.
|
||||
let provider = CssProvider::new();
|
||||
provider.load_from_string(include_str!("style.css"));
|
||||
// We give the CssProvided to the default screen so the CSS rules we added
|
||||
// can be applied to our window.
|
||||
gtk::style_context_add_provider_for_display(
|
||||
&Display::default().expect("Could not connect to a display."),
|
||||
&provider,
|
||||
STYLE_PROVIDER_PRIORITY_APPLICATION,
|
||||
);
|
||||
app.connect_activate(build_ui);
|
||||
});
|
||||
|
||||
//if get_current_username().unwrap() == "pikaos" {
|
||||
// application.run();
|
||||
//} else {
|
||||
// println!("Error: This program can only be run via pikaos user");
|
||||
// std::process::exit(1)
|
||||
//}
|
||||
application.run();
|
||||
}
|
Loading…
Reference in New Issue
Block a user