use std::fs::{self, DirEntry};
use std::io;
use std::path::Path;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub enum ManifestFormat {
JSON,
YAML,
TEXT,
}
#[derive(Debug, Serialize, Deserialize)]
pub enum ReleaseType {
Dev,
Release,
}
pub const DEFAULT_RELEASE_TYPE: ReleaseType = ReleaseType::Dev;
#[derive(Debug, Serialize, Deserialize)]
pub enum Architecture {
Amd64,
I386,
Armhf,
Spark,
Any,
}
pub const DEFAULT_ARCH: Architecture = Architecture::Any;
#[derive(Debug, Serialize, Deserialize)]
pub enum License {
Gpl2,
Gpl3,
Mit,
Bsd2,
Bsd3,
Proprietary,
Unknown,
}
pub const DEFAULT_LICENSE: License = License::Gpl2;
#[derive(Debug, Serialize, Deserialize)]
pub struct AbstractManifest {
pub path: String,
pub format: ManifestFormat,
pub package_name: String,
pub package_id: String,
pub package_version: String,
pub depends_on: Vec<AbstractModule>,
pub flatpak_manifest: Option<crate::manifests::flatpak::FlatpakManifest>,
pub debian_manifest: Option<crate::manifests::debian::DebianManifest>,
pub snap_manifest: Option<crate::manifests::snap::SnapcraftManifest>,
}
impl Default for AbstractManifest {
fn default() -> Self {
AbstractManifest {
package_name: String::from(""),
package_id: "".to_string(),
package_version: "".to_string(),
path: "".to_string(),
format: ManifestFormat::TEXT,
depends_on: vec![],
flatpak_manifest: None,
debian_manifest: None,
snap_manifest: None,
}
}
}
pub enum OS {
Bsd,
Mac,
Ios,
Linux,
Android,
Symbian,
}
pub struct OSVersion {
pub os: OS,
pub is_distribution: bool,
}
const JESSIE: OSVersion = OSVersion {
os: OS::Linux,
is_distribution: true,
};
#[derive(Debug, Serialize, Deserialize)]
pub enum PackagingSystem {
Flatpak,
Snap,
Debian,
Arch,
Homebrew,
Unknown,
}
pub const DEFAULT_PACKAGING_SYSTEM: PackagingSystem = PackagingSystem::Unknown;
impl Default for PackagingSystem {
fn default() -> Self {
DEFAULT_PACKAGING_SYSTEM
}
}
#[derive(Debug, Serialize, Deserialize)]
pub enum BuildSystem {
Make,
Cmake,
Autotools,
Meson,
Cargo,
Maven,
Xcode,
Npm,
Bash,
Pip2,
Pip3,
Manual,
Swift,
Apt,
Gem,
Unknown,
}
impl BuildSystem {
pub fn get_build_system(path: &str) -> BuildSystem {
if path.ends_with("meson_options.txt") {
return BuildSystem::Meson;
}
if path.ends_with("control") {
return BuildSystem::Apt;
}
if path.ends_with("package.json") {
return BuildSystem::Npm;
}
if path.ends_with("Gemfile") {
return BuildSystem::Gem;
}
if path.ends_with("requirements.txt") {
return BuildSystem::Pip3;
}
if path.ends_with(".spec") {
}
if path.ends_with("Makefile") {
return BuildSystem::Make;
}
return crate::manifests::manifest::DEFAULT_BUILD_SYSTEM;
}
pub fn get_manifest(self: &BuildSystem) -> AbstractManifest {
return AbstractManifest::default();
}
}
pub const DEFAULT_BUILD_SYSTEM: BuildSystem = BuildSystem::Unknown;
impl Default for BuildSystem {
fn default() -> Self {
DEFAULT_BUILD_SYSTEM
}
}
#[derive(Debug, Serialize, Deserialize)]
pub enum SourceType {
Bzr,
Deb,
Git,
Local,
Mercurial,
Rpm,
Subversion,
Svn,
Tar,
Tarball,
Zip,
Sevenzip,
Unknown,
}
pub const DEFAULT_SOURCE_TYPE: SourceType = SourceType::Unknown;
impl Default for SourceType {
fn default() -> Self {
DEFAULT_SOURCE_TYPE
}
}
#[derive(Debug, Serialize, Deserialize)]
pub enum ModuleType {
CLIApp,
GUIApp,
Lib,
Driver,
Daemon,
Kernel,
Plugin,
Runtime,
Emulator,
Compiler,
Bootloader,
Firmware,
Media,
Unknown,
}
pub const DEFAULT_MODULE_TYPE: ModuleType = ModuleType::Lib;
impl Default for ModuleType {
fn default() -> Self {
DEFAULT_MODULE_TYPE
}
}
#[derive(Default, Debug, Serialize, Deserialize)]
pub struct AbstractModule {
pub module_type: ModuleType,
pub name: String,
pub version: String,
pub url: String,
pub url_type: SourceType,
pub build_system: BuildSystem,
pub packaging_system: PackagingSystem,
pub install_instructions: String,
pub install_path: String,
pub tag: String,
pub commit: String,
pub sha256: String,
pub config_options: String,
pub cleanup_files: Vec<String>,
pub depends_on: Vec<AbstractModule>,
pub is_primary: bool,
}
#[derive(Default, Debug, Serialize, Deserialize)]
pub struct AbstractExecutable {
pub name: String,
pub path: String,
pub is_desktop: bool,
pub is_daemon: bool,
pub is_primary: bool,
pub icon_path: String,
}
#[derive(Default, Debug, Serialize, Deserialize)]
pub struct AbstractPermission {
pub name: String,
pub description: String,
pub api_type: APIType,
}
#[derive(Debug, Serialize, Deserialize)]
pub enum APIType {
Dbus,
Files,
Socket,
Camera,
Mic,
Gps,
Unknown,
}
pub const DEFAULT_API_TYPE: APIType = APIType::Unknown;
impl Default for APIType {
fn default() -> Self {
DEFAULT_API_TYPE
}
}
pub enum Priority {
Required,
Important,
Standard,
Optional,
Extra,
}
const DEFAULT_PRIORITY: Priority = Priority::Optional;
fn get_manifests_for_path(path: std::fs::DirEntry) -> Vec<AbstractManifest> {
let mut manifests_in_project: Vec<AbstractManifest> = vec![];
let file_type = path.file_type().unwrap();
let entry_path: String = path.path().to_str().unwrap_or("").to_string();
if file_type.is_dir() {
return manifests_in_project;
} else if file_type.is_file() {
return manifests_in_project;
} else if file_type.is_symlink() {
return manifests_in_project;
} else {
assert!(false, "Unknown file type");
}
return manifests_in_project;
}
pub fn get_manifests(project_path: String) -> Vec<AbstractManifest> {
let mut manifests_in_project = vec![];
let mut manifests = fs::read_dir(project_path)
.unwrap()
.map(|res| res.map(get_manifests_for_path))
.collect::<Result<Vec<_>, io::Error>>()
.unwrap();
return manifests_in_project;
}