Added function to read .PKGINFO into struct

main
Jef Roosens 2022-01-13 19:20:14 +01:00
parent b5224e8a63
commit 5616e7a4e2
Signed by untrusted user: Jef Roosens
GPG Key ID: 955C0660072F691F
4 changed files with 101 additions and 10 deletions

View File

@ -2,7 +2,7 @@ module archive
import os
pub fn get_pkg_info(pkg_path string) ?string {
pub fn pkg_info_string(pkg_path string) ?string {
if !os.is_file(pkg_path) {
return error("'$pkg_path' doesn't exist or isn't a file.")
}

View File

@ -54,7 +54,7 @@ fn reader_to_file(mut reader io.BufferedReader, length int, path string) ? {
}
}
fn main() {
fn main2() {
// Configure logger
log_level_str := os.getenv_opt('LOG_LEVEL') or { 'WARN' }
log_level := log.level_from_tag(log_level_str) or {
@ -102,11 +102,11 @@ fn main() {
}, port)
}
// fn main() {
// // archive.list_filenames()
// info := archive.get_pkg_info('test/jjr-joplin-desktop-2.6.10-4-x86_64.pkg.tar.zst') or {
// eprintln(err.msg)
// return
// }
// println(info)
// }
fn main() {
// archive.list_filenames()
info := repo.get_pkg_info('test/jjr-joplin-desktop-2.6.10-4-x86_64.pkg.tar.zst') or {
eprintln(err.msg)
return
}
println(info)
}

90
src/repo/pkg.v 100644
View File

@ -0,0 +1,90 @@
module repo
import archive
import time
struct PkgInfo {
mut:
// Single values
name string
base string
version string
description string
size i64
csize i64
url string
arch string
build_date i64
packager string
md5sum string
sha256sum string
pgpsig string
pgpsigsize i64
// Array values
groups []string
licenses []string
replaces []string
depends []string
conflicts []string
provides []string
optdepends []string
makedepends []string
checkdepends []string
}
pub fn get_pkg_info(pkg_path string) ?PkgInfo {
pkg_info_str := archive.pkg_info_string(pkg_path) ?
mut pkg_info := PkgInfo{}
mut i := 0
mut j := 0
// Iterate over the entire string
for line in pkg_info_str.split_into_lines() {
// Skip any comment lines
if line.starts_with('#') {
continue
}
parts := line.split_nth('=', 2)
if parts.len < 2 {
return error('Invalid line detected.')
}
value := parts[1].trim_space()
key := parts[0].trim_space()
match key {
// Single values
'pkgname' { pkg_info.name = value }
'pkgbase' { pkg_info.base = value }
'pkgver' { pkg_info.version = value }
'pkgdesc' { pkg_info.description = value }
'csize' { pkg_info.csize = value.int() }
'size' { pkg_info.size = value.int() }
'url' { pkg_info.url = value }
'arch' { pkg_info.arch = value }
'builddate' { pkg_info.build_date = value.int() }
'packager' { pkg_info.packager = value }
'md5sum' { pkg_info.md5sum = value }
'sha256sum' { pkg_info.sha256sum = value }
'pgpsig' { pkg_info.pgpsig = value }
'pgpsigsize' { pkg_info.pgpsigsize = value.int() }
// Array values
'group' { pkg_info.groups << value }
'license' { pkg_info.licenses << value }
'replaces' { pkg_info.replaces << value }
'depend' { pkg_info.depends << value }
'conflict' { pkg_info.conflicts << value }
'provides' { pkg_info.provides << value }
'optdepend' { pkg_info.optdepends << value }
'makedepend' { pkg_info.makedepends << value }
'checkdepend' { pkg_info.checkdepends << value }
else { return error("Invalid key '$key'.") }
}
}
return pkg_info
}

View File

@ -1,6 +1,7 @@
module repo
import os
import archive
const pkgs_subpath = 'pkgs'