Initial commit

This commit is contained in:
Isaac Shoebottom 2025-03-19 16:56:58 -03:00
commit 779ac7d3a2
8 changed files with 315 additions and 0 deletions

17
.gitignore vendored Normal file
View File

@ -0,0 +1,17 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
# RustRover
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

147
Cargo.lock generated Normal file
View File

@ -0,0 +1,147 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "equivalent"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
name = "hashbrown"
version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
[[package]]
name = "indexmap"
version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3954d50fe15b02142bf25d3b8bdadb634ec3948f103d04ffe3031bc8fe9d7058"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "local-updater"
version = "0.1.0"
dependencies = [
"serde",
"serde_derive",
"toml",
]
[[package]]
name = "memchr"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "proc-macro2"
version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
[[package]]
name = "serde"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_spanned"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1"
dependencies = [
"serde",
]
[[package]]
name = "syn"
version = "2.0.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "toml"
version = "0.8.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.22.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474"
dependencies = [
"indexmap",
"serde",
"serde_spanned",
"toml_datetime",
"winnow",
]
[[package]]
name = "unicode-ident"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]]
name = "winnow"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e97b544156e9bebe1a0ffbc03484fc1ffe3100cbce3ffb17eac35f7cdd7ab36"
dependencies = [
"memchr",
]

9
Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "local-updater"
version = "0.1.0"
edition = "2024"
[dependencies]
serde = "1.0.219"
serde_derive = "1.0.219"
toml = "0.8.20"

22
example.toml Normal file
View File

@ -0,0 +1,22 @@
[metadata]
name = "example"
version = "0.1.0"
description = "Example package"
homepage = "https://example.com"
url = "https://example.com/example-0.1.0-linux-amd64.tar.gz"
license = "MIT"
# Uses XDG Base Directory Specification
# Except bin, which just goes in $HOME/.local/bin
[install]
bin = ["example"]
config = ["config.toml"]
share = ["data"]
[update.check]
type_ = "github"
checkver = "https://example.com/checkver"
regex = "v([0-9]+\\.[0-9]+\\.[0-9]+)"
[update.template]
url = "https://example.com/$version-$os-$arch.tar.gz"

23
manifest.py Normal file
View File

@ -0,0 +1,23 @@
import tomlkit as tomllib
import os
import sys
def load_from_state(name):
# Get xdg data home
xdg_data_home = os.environ.get('XDG_DATA_HOME', os.path.join(os.environ['HOME'], '.local', 'share'))
# Get the path to the state file
state_file = os.path.join(xdg_data_home, 'local-updater', name + '.toml')
# Load the state file
return load(state_file)
def load(filename):
with open(filename, 'r') as f:
return tomllib.loads(f.read())
def main(filename):
tmp = load(filename[0])
print(tmp)
if __name__ == '__main__':
main(sys.argv[1:])

17
pyproject.toml Normal file
View File

@ -0,0 +1,17 @@
[project]
name = "local-updater"
version = "0.1.0"
description = ""
authors = [
{name = "Isaac Shoebottom",email = "ir.shoebottom@gmail.com"}
]
readme = "README.md"
requires-python = ">=3.9"
dependencies = [
"tomlkit (>=0.13.2,<0.14.0)"
]
[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"

80
src/main.rs Normal file
View File

@ -0,0 +1,80 @@
use serde_derive::Deserialize;
use toml;
// Example TOML file
/*
[metadata]
name = "example"
version = "0.1.0"
description = "Example package"
homepage = "https://example.com"
url = "https://example.com/example-0.1.0-linux-amd64.tar.gz"
license = "MIT"
# Uses XDG Base Directory Specification
# Except bin, which just goes in $HOME/.local/bin
[install]
bin = ["example"]
config = ["config.toml"]
share = ["data"]
[update.check]
type = "github"
checkver = "https://example.com/checkver"
regex = "v([0-9]+\\.[0-9]+\\.[0-9]+)"
[update.template]
url = "https://example.com/$version-$os-$arch.tar.gz"
*/
#[derive(Debug, Deserialize)]
struct Manifest {
metadata: Metadata,
install: Install,
update: Update,
}
#[derive(Debug, Deserialize)]
struct Metadata {
name: String,
version: String,
description: String,
homepage: String,
url: String,
license: String,
}
#[derive(Debug, Deserialize)]
struct Install {
bin: Vec<String>,
config: Vec<String>,
share: Vec<String>,
}
#[derive(Debug, Deserialize)]
struct Update {
check: Check,
template: Template,
}
#[derive(Debug, Deserialize)]
struct Check {
type_: String,
checkver: String,
regex: String,
}
#[derive(Debug, Deserialize)]
struct Template {
url: String,
}
// Load TOML file from first argument
// Then parse it into a Manifest struct
// Then print the struct
fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() != 2 {
eprintln!("Usage: {} <file>", args[0]);
std::process::exit(1);
}
let file = std::fs::read_to_string(&args[1]).unwrap();
let manifest: Manifest = toml::from_str(&file).unwrap();
println!("{:#?}", manifest);
}

0
update.py Normal file
View File