-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
rattler_menuinst
crate (#840)
--------- Co-authored-by: Bas Zalmstra <bas@prefix.dev> Co-authored-by: Julian Hofer <julianhofer@gnome.org> Co-authored-by: Ruben Arts <ruben.arts@hotmail.com>
- Loading branch information
1 parent
f81bed6
commit 02d0292
Showing
55 changed files
with
8,571 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use anyhow::{Context, Result}; | ||
use clap::Parser; | ||
use rattler_conda_types::{menuinst::MenuMode, PackageName, Platform, PrefixRecord}; | ||
use std::{fs, path::PathBuf}; | ||
|
||
#[derive(Debug, Parser)] | ||
pub struct InstallOpt { | ||
/// Target prefix to look for the package (defaults to `.prefix`) | ||
#[clap(long, short, default_value = ".prefix")] | ||
target_prefix: PathBuf, | ||
|
||
/// Name of the package for which to install menu items | ||
package_name: PackageName, | ||
} | ||
|
||
pub async fn install_menu(opts: InstallOpt) -> Result<()> { | ||
// Find the prefix record in the target_prefix and call `install_menu` on it | ||
let records: Vec<PrefixRecord> = PrefixRecord::collect_from_prefix(&opts.target_prefix)?; | ||
|
||
let record = records | ||
.iter() | ||
.find(|r| r.repodata_record.package_record.name == opts.package_name) | ||
.with_context(|| { | ||
format!( | ||
"Package {} not found in prefix {:?}", | ||
opts.package_name.as_normalized(), | ||
opts.target_prefix | ||
) | ||
})?; | ||
let prefix = fs::canonicalize(&opts.target_prefix)?; | ||
rattler_menuinst::install_menuitems_for_record( | ||
&prefix, | ||
record, | ||
Platform::current(), | ||
MenuMode::User, | ||
)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub async fn remove_menu(opts: InstallOpt) -> Result<()> { | ||
// Find the prefix record in the target_prefix and call `remove_menu` on it | ||
let records: Vec<PrefixRecord> = PrefixRecord::collect_from_prefix(&opts.target_prefix)?; | ||
|
||
let record = records | ||
.iter() | ||
.find(|r| r.repodata_record.package_record.name == opts.package_name) | ||
.with_context(|| { | ||
format!( | ||
"Package {} not found in prefix {:?}", | ||
opts.package_name.as_normalized(), | ||
opts.target_prefix | ||
) | ||
})?; | ||
|
||
rattler_menuinst::remove_menu_items(&record.installed_system_menus)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod create; | ||
pub mod menu; | ||
pub mod virtual_packages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
//! Define types that can be serialized into a `PrefixRecord` to track | ||
//! menu entries installed into the system. | ||
use serde::{Deserialize, Serialize}; | ||
use std::path::PathBuf; | ||
|
||
/// Menu mode that was used to install the menu entries | ||
#[derive(Default, Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] | ||
pub enum MenuMode { | ||
/// System-wide installation | ||
System, | ||
|
||
/// User installation | ||
#[default] | ||
User, | ||
} | ||
|
||
/// Tracker for menu entries installed into the system | ||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
#[serde(tag = "type", rename_all = "snake_case")] | ||
pub enum Tracker { | ||
/// Linux tracker | ||
Linux(LinuxTracker), | ||
/// Windows tracker | ||
Windows(WindowsTracker), | ||
/// macOS tracker | ||
MacOs(MacOsTracker), | ||
} | ||
|
||
/// Registered MIME file on the system | ||
#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
pub struct LinuxRegisteredMimeFile { | ||
/// The application that was registered | ||
pub application: String, | ||
/// Path to use when calling `update-mime-database` | ||
pub database_path: PathBuf, | ||
/// The location of the config file that was edited | ||
pub config_file: PathBuf, | ||
/// The MIME types that were associated to the application | ||
pub mime_types: Vec<String>, | ||
} | ||
|
||
/// Tracker for Linux installations | ||
#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
pub struct LinuxTracker { | ||
/// The menu mode that was used to install the menu entries | ||
pub install_mode: MenuMode, | ||
|
||
/// List of desktop files that were installed | ||
pub paths: Vec<PathBuf>, | ||
|
||
/// MIME types that were installed | ||
#[serde(default, skip_serializing_if = "Option::is_none")] | ||
pub mime_types: Option<LinuxRegisteredMimeFile>, | ||
|
||
/// MIME type glob files that were registered on the system | ||
#[serde(default, skip_serializing_if = "Vec::is_empty")] | ||
pub registered_mime_files: Vec<PathBuf>, | ||
} | ||
|
||
/// File extension that was installed | ||
#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
pub struct WindowsFileExtension { | ||
/// The file extension that was installed | ||
pub extension: String, | ||
/// The identifier of the file extension | ||
pub identifier: String, | ||
} | ||
|
||
/// URL protocol that was installed | ||
#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
pub struct WindowsUrlProtocol { | ||
/// The URL protocol that was installed | ||
pub protocol: String, | ||
/// The identifier of the URL protocol | ||
pub identifier: String, | ||
} | ||
|
||
/// Terminal profile that was installed | ||
#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
pub struct WindowsTerminalProfile { | ||
/// The name of the terminal profile | ||
pub configuration_file: PathBuf, | ||
/// The identifier of the terminal profile | ||
pub identifier: String, | ||
} | ||
|
||
/// Tracker for Windows installations | ||
#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
pub struct WindowsTracker { | ||
/// The menu mode that was used to install the menu entries | ||
pub menu_mode: MenuMode, | ||
|
||
/// List of shortcuts that were installed | ||
#[serde(default, skip_serializing_if = "Vec::is_empty")] | ||
pub shortcuts: Vec<PathBuf>, | ||
|
||
/// List of file extensions that were installed | ||
#[serde(default, skip_serializing_if = "Vec::is_empty")] | ||
pub file_extensions: Vec<WindowsFileExtension>, | ||
|
||
/// List of URL protocols that were installed | ||
#[serde(default, skip_serializing_if = "Vec::is_empty")] | ||
pub url_protocols: Vec<WindowsUrlProtocol>, | ||
|
||
/// List of terminal profiles that were installed | ||
#[serde(default, skip_serializing_if = "Vec::is_empty")] | ||
pub terminal_profiles: Vec<WindowsTerminalProfile>, | ||
} | ||
|
||
impl WindowsTracker { | ||
/// Create a new Windows tracker | ||
pub fn new(menu_mode: MenuMode) -> Self { | ||
Self { | ||
menu_mode, | ||
shortcuts: Vec::new(), | ||
file_extensions: Vec::new(), | ||
url_protocols: Vec::new(), | ||
terminal_profiles: Vec::new(), | ||
} | ||
} | ||
} | ||
|
||
/// Tracker for macOS installations | ||
#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
pub struct MacOsTracker { | ||
/// The app folder that was installed, e.g. ~/Applications/foobar.app | ||
pub app_folder: PathBuf, | ||
/// Argument that was used to call `lsregister` and that we need to | ||
/// call to unregister the app | ||
#[serde(default, skip_serializing_if = "Option::is_none")] | ||
pub lsregister: Option<PathBuf>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[package] | ||
name = "rattler_menuinst" | ||
version = "0.1.0" | ||
edition.workspace = true | ||
authors = ["Wolf Vollprecht <w.vollprecht@gmail.com>"] | ||
description = "Install menu entries for a Conda package" | ||
categories.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
license.workspace = true | ||
readme.workspace = true | ||
|
||
[dependencies] | ||
dirs = { workspace = true } | ||
serde = { workspace = true, features = ["derive"] } | ||
serde_json = { workspace = true } | ||
tracing = { workspace = true } | ||
rattler_conda_types = { path = "../rattler_conda_types", default-features = false } | ||
rattler_shell = { path = "../rattler_shell", default-features = false } | ||
thiserror = { workspace = true } | ||
unicode-normalization = { workspace = true } | ||
regex = { workspace = true } | ||
tempfile = { workspace = true } | ||
fs-err = { workspace = true } | ||
which = { workspace = true } | ||
chrono = { workspace = true, features = ["clock"] } | ||
once_cell = {workspace = true} | ||
|
||
[target.'cfg(target_os = "macos")'.dependencies] | ||
plist = { workspace = true } | ||
sha2 = { workspace = true } | ||
|
||
[target.'cfg(target_os = "linux")'.dependencies] | ||
quick-xml = "0.37.2" | ||
configparser = { version = "3.1.0" } | ||
shlex = { workspace = true } | ||
|
||
[target.'cfg(target_os = "windows")'.dependencies] | ||
known-folders = "1.2.0" | ||
windows = { version = "0.60.0", features = [ | ||
"Win32_System_Com_StructuredStorage", | ||
"Win32_UI_Shell_PropertiesSystem", | ||
"Win32_Storage_EnhancedStorage", | ||
"Win32_System_Variant", | ||
]} | ||
windows-registry = "0.5.0" | ||
|
||
[dev-dependencies] | ||
insta = { workspace = true, features = ["json"] } | ||
configparser = { version = "3.1.0", features = ["indexmap"] } |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.