Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
add: caching system
Browse files Browse the repository at this point in the history
  • Loading branch information
saenai255 committed Sep 5, 2022
1 parent 9a6a054 commit 1074520
Show file tree
Hide file tree
Showing 18 changed files with 906 additions and 433 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
ci:
# Skip hooks requiring `just` to be installed
skip: [codespell, fmt, clippy]

repos:
# General
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

## Added

- Configuration handler in [#58](https://github.com/pacstall/libpacstall/pull/58) by [\@wizard-28](https://github.com/wizard-28)
15 changes: 11 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
name = "libpacstall"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "libpacstall"
authors = [
"Sourajyoti Basak <[email protected]>",
"David Brochero <[email protected]>",
"Paul Cosma <[email protected]>"
]
description = "Backend API library for Pacstall"
repository = "https://github.com/pacstall/libpacstall"
license = "GPL-3.0-or-later"
keywords = ["aur", "pacstall", "package-manager", "linux", "apt"]
categories = ["caching", "config", "parsing", "os::linux-apis"]

[dependencies]
figment = { version = "0.10.6", features = ["env", "test", "toml" ] }
Expand All @@ -14,6 +20,7 @@ serde = { version = "1.0.144", features = ["derive"] }
chrono = { version = "0.4.22", features = ["serde"] }
serde_derive = "1.0.144"
serde_json = "1.0.85"
thiserror = "1.0"

[dev-dependencies]
rstest = "0.15.0"
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
<h1 align="center">LibPacstall</h1>
<p align="center"><b>Backend API library for Pacstall</b></p>

<p align="center">
<!-- Programming info -->
<a href="https://codecov.io/gh/pacstall/libpacstall">
<img alt="Codecov" src="https://img.shields.io/codecov/c/gh/pacstall/libpacstall?logo=codecov&logoColor=white&style=for-the-badge">
</a>
<a href="https://www.codacy.com/gh/pacstall/libpacstall/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=pacstall/libpacstall&amp;utm_campaign=Badge_Grade">
<img alt="Codacy branch grade" src="https://img.shields.io/codacy/grade/e2155a8b2f0e4804b9c6a4b1441c3b3a?label=code%20quality&logo=codacy&logoColor=white&style=for-the-badge" />
</a>
<br />
<!-- Project Information -->
<a href="https://www.rust-lang.org"><img alt="Made with Rust" src="https://img.shields.io/badge/rust-%23000000.svg?style=for-the-badge&logo=rust&logoColor=white"/></a>
<a href="https://codecov.io/gh/pacstall/libpacstall"><img alt="Codecov" src="https://img.shields.io/badge/codecov-%23ff0077.svg?style=for-the-badge&logo=codecov&logoColor=white"/></a>
<br/>
<!-- Social -->
<a href="https://discord.gg/yzrjXJV6K8"><img alt="join discord" src="https://img.shields.io/discord/839818021207801878?color=5865F2&label=Discord&logo=discord&logoColor=FFFFFF&style=for-the-badge" /></a>
<a href="https://reddit.com/r/pacstall"><img src="https://img.shields.io/reddit/subreddit-subscribers/pacstall?label=Reddit&color=FF4301&style=for-the-badge&logo=reddit&logoColor=FFFFFF" loading="lazy" /></a>
<a href="https://discord.gg/yzrjXJV6K8"><img alt="join discord" src="https://img.shields.io/badge/Discord-%237289DA.svg?style=for-the-badge&logo=discord&logoColor=white"/></a>
<a href="https://reddit.com/r/pacstall"><img src="https://img.shields.io/badge/Reddit-FF4500?style=for-the-badge&logo=reddit&logoColor=white"/></a>
<a href="https://social.linux.pizza/web/@pacstall">
<img alt="Mastodon Follow" src="https://img.shields.io/mastodon/follow/107278715447740005?color=3088d4&domain=https%3A%2F%2Fsocial.linux.pizza&label=Mastodon&logo=mastodon&logoColor=white&style=for-the-badge" loading="lazy" />
<img alt="Mastodon Follow" src="https://img.shields.io/badge/-MASTODON-%232B90D9?style=for-the-badge&logo=mastodon&logoColor=white"/>
</a>
<a href="https://matrix.to/#/#pacstall:matrix.org"><img alt="join matrix" src="https://img.shields.io/matrix/pacstall:matrix.org?color=888888&label=Matrix&logo=Matrix&style=for-the-badge" /></a>
<br />
<a href="https://matrix.to/#/#pacstall:matrix.org"><img alt="join matrix" src="https://img.shields.io/badge/matrix-000000?style=for-the-badge&logo=Matrix&logoColor=white"/></a>
<br/>
</p>

## What is this
<p align="center">The backend API library for <a href="https://github.com/pacstall/pacstall">Pacstall</a></p>

## 🔱 Info

The backend API library for [Pacstall](https://github.com/pacstall/pacstall) written in Rust

## 🌊 Features

LibPacstall is a backend API library for
[Pacstall](https://github.com/pacstall/pacstall).
+ Deserialize the Pacstall configuration from the TOML and environment variables

## Stats
## 📈 Stats

<p align="center"><img alt="Repobeats analytics image" src="https://repobeats.axiom.co/api/embed/2238a489ea987735d3dff77778b2f15b93d17fd3.svg" /></p>

## License
## 📜 License

<p align="center"><img alt="GPL-3.0-or-later" height="100" src="https://www.gnu.org/graphics/gplv3-or-later.svg" /></p>

Expand Down
35 changes: 2 additions & 33 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ use figment::value::{Dict, Map};
use figment::{Error, Figment, Metadata, Profile, Provider};
use serde::{Deserialize, Serialize};

use crate::model::{default_repository, Repository};

/// Pacstall's configuration.
///
/// Gives access to the [configuration](Config) extracted, and the [Figment]
Expand Down Expand Up @@ -191,39 +193,6 @@ impl Default for Settings {
}
}

/// The extracted `repositories` array of tables.
///
/// Defaults to the official repository.
#[derive(Deserialize, Debug, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct Repository {
/// The name of the repository.
pub name: String,
/// URL of the repository.
///
/// Note that the URL **isn't verified** during extraction!
pub url: String,
/// Preference of the repository.
///
/// Specifies which repository to look into first during certain operations
/// like installing a package. If the package isn't present in the first
/// preferred repository, then the second preferred repository is looked
/// into.
pub preference: u32,
}

fn default_repository() -> Vec<Repository> { vec![Repository::default()] }

impl Default for Repository {
fn default() -> Self {
Self {
name: "official".into(),
url: "https://github.com/pacstall/pacstall-programs".into(),
preference: 1,
}
}
}

#[cfg(test)]
mod tests {
use std::fs::{self, File};
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
)]
#![allow(clippy::must_use_candidate)]
pub mod config;
pub mod model;
pub mod store;
5 changes: 0 additions & 5 deletions src/model.rs

This file was deleted.

7 changes: 7 additions & 0 deletions src/model/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Provides structs to handle Pacstall's data models.

mod pacbuild;
mod repository;

pub use crate::model::pacbuild::*;
pub use crate::model::repository::{default_repository, Repository};
78 changes: 69 additions & 9 deletions src/model/pacbuild.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use chrono::NaiveDateTime as DateTime;
use serde_derive::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
/// Representation of the PACBUILD file.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct PacBuild {
pub name: PackageId,
pub last_updated: DateTime,
Expand All @@ -20,32 +21,91 @@ pub struct PacBuild {
pub kind: Kind,
}

/// Represents a `SemVer` version.
/// # Examples
/// ```
/// use libpacstall::model::Version;
///
/// let ver: Version = "1.0.0".into();
/// ```
pub type Version = String;

/// Represents a `PacBuild` or Apt package name.
/// # Examples
/// ```
/// use libpacstall::model::PackageId;
///
/// let identifier: PackageId = "discord-deb".into();
/// ```
pub type PackageId = String;
/// Represents an URL
/// # Examples
/// ```
/// use libpacstall::model::URL;
///
/// let url: URL = "https://example.com".into();
/// ```
pub type URL = String;
/// Represents a file checksum
/// # Examples
/// ```
/// use libpacstall::model::Hash;
///
/// let hash: Hash = "b5c9710f33204498efb64cf8257cd9b19e9d3e6b".into();
/// ```
pub type Hash = String;

#[derive(Debug, Clone, Serialize, Deserialize)]
/// Represents the install state of a package.
/// # Examples
/// ```
/// use chrono::NaiveDate;
/// use libpacstall::model::InstallState;
///
/// let installed_directly = InstallState::Direct(
/// NaiveDate::from_ymd(2016, 7, 8).and_hms(9, 10, 11),
/// "0.9.2".into(),
/// );
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum InstallState {
/// Package is installed directly, meaning the user wanted it.
Direct(DateTime, Version),

/// Package is installed as a dependency.
Indirect(DateTime, Version),

/// Package is not installed.
None,
}

impl InstallState {
pub fn is_installed(&self) -> bool {
match self {
Self::None => false,
_ => true,
}
}
/// Returns `true` if the package is installed otherwise `false`.
pub fn is_installed(&self) -> bool { !matches!(self, Self::None) }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
/// Represents the type of the package. Usually deduced by the [PacBuild#name]
/// suffix.
///
/// # Examples
/// ```
/// use libpacstall::model::Kind;
///
/// let git_release = Kind::GitRelease;
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum Kind {
/// [PacBuild] will install an `AppImage`.
AppImage(Hash),

/// [PacBuild] will install a prebuilt, usually `tar.gz`, package.
Binary(Hash),

/// [PacBuild] will install an existing `.deb` file.
DebFile(Hash),

/// [PacBuild] will install the source of a given Git branch.
GitBranch,

/// [PacBuild] will install the source of a given Git release.
GitRelease,
}
36 changes: 29 additions & 7 deletions src/model/repository.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
use chrono::NaiveDateTime as DateTime;
use serde_derive::{Deserialize, Serialize};

use crate::model::pacbuild::PacBuild;

#[derive(Debug, Clone, Serialize, Deserialize)]
/// Representation of a Pacstall repository.
///
/// Defaults to the official repository.
#[derive(Deserialize, Debug, Eq, PartialEq, Serialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct Repository {
/// The name of the repository.
pub name: String,
pub last_updated: DateTime,
/// URL of the repository.
///
/// Note that the URL **isn't verified** during extraction!
pub url: String,
pub pacbuilds: Vec<PacBuild>,
pub priority: u8,
/// Preference of the repository.
///
/// Specifies which repository to look into first during certain operations
/// like installing a package. If the package isn't present in the first
/// preferred repository, then the second preferred repository is looked
/// into.
pub preference: u32,
}

#[allow(clippy::module_name_repetitions)]
pub fn default_repository() -> Vec<Repository> { vec![Repository::default()] }

impl Default for Repository {
fn default() -> Self {
Self {
name: "official".into(),
url: "https://github.com/pacstall/pacstall-programs".into(),
preference: 1,
}
}
}
9 changes: 0 additions & 9 deletions src/store.rs

This file was deleted.

Loading

0 comments on commit 1074520

Please sign in to comment.