Skip to content

Commit

Permalink
Rethink structure and change roadmap
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsan committed May 16, 2023
1 parent 60df64e commit f5df157
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 4,570 deletions.
88 changes: 21 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,79 +18,33 @@ From their docs:
This is a Rust implementation of the same concept.

## Migration from `py-organize`

- copy your `config.yaml` and rename it to `organize.yaml`
- rework `anchors` in your new `organize.yaml` config file
from:

```yaml
desktop_folder: &desktop
- '~/Desktop/'
applications: &apps
- exe
- msi
- apk
```
to
```yaml
aliases:
- name: desktop
kind: folder
items:
- '~/Desktop/'
- name: apps
kind: ext
items:
- exe
- msi
- apk
```
- then rework the `aliases` correspondingly from:

```yaml
# Rule for desktop/downloads to move applications into @Apps
- folders:
- *downloads
- *desktop
- *inbox
subfolders: false
filters:
- extension:
- *apps
actions:
- move: '~/backup/INBOX/@Apps/'
```

```yaml
# Rule for desktop/downloads to move applications into @Apps
- locations:
- ref|downloads
- ref|desktop
- ref|inbox
subfolders: false
filters:
- extension:
- ref|apps
actions:
- move: '~/backup/INBOX/@Apps/'
```

## Goals

For now the first goal for this Rust version of `organize` is to have feature parity (commands) with its Python equivalent.
Though, breaking changes may occur going forward, for the beginning it should work as a drop-in replacement.
For now the first goal for this Rust version of `organize` is to have feature parity with its Python equivalent.

A big factor for the Rust port for me is that I like Rust. I want to reimplement `organize` in language that has better error handling, and makes it easier to maintain software. It's fast and at the same time makes development less error prone.
**BUT**: I want to take another approach on tackling the problem. It is also relatively complicated to map all the stuff
within a `config` file, because we are bound to the syntax of `yaml`/`json`/`toml`/`ron`.

I'm the first user of the Rust implementation, and will be going to use it with my private files. Thus an important goal for me is stability.
*Maybe this is exactly the problem to solve!*

Basically you want to have a configuration file, which replaces a mini scripting language.
With predefined `filters` and `actions` that are applied to the items that the filter spits out.

Basically almost everything in the configuration files are parameters for functions/methods.

This makes everything more complicated.

## Non goals
1. What if we implement rusty `organize` in a way, that we can call `organize filter extension --ext "exe, msi, apk" --path {}`
and it spits out all the paths that match this `precoded` filter?
This way we can already utilize it easily within shell scripts.

The Python implementation supports filters and actions that can be passed in via the config file and are written themselves in `Python`. For me it's not a reasonable effort to support `Python` features in that regards.
1. On the second implementation stage, we can embed a scripting engine like [rhai](https://crates.io/crates/rhai), where we expose some functionality of rusty `organize` as `functions` and register them with the `rhai` engine.

1. Instead of pressing everything in a complicated configuration file syntax, we can utilize a scripting language and boil it down to its minimum syntax.

That being said, a big factor for the Rust reiteration for me is that I like Rust. I want to reimplement `organize`'s approach in language that has better error handling, and makes it easier to maintain software. That is fast and at the same time makes development less error prone.

I'm the first user of the Rust implementation, and will be going to use it with my private files. Thus an important goal for me is stability.

## License

Expand Down
5 changes: 1 addition & 4 deletions crates/organize-rs_core/src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ pub mod actions;
pub mod aliases;
pub mod filters;

// Generated from py-organize
pub mod py_organize;

use serde::{Deserialize, Serialize};
use std::path::PathBuf;
// use std::path::PathBuf;

use crate::rules::{actions::OrganizeAction, filters::OrganizeFilter};

Expand Down
24 changes: 10 additions & 14 deletions crates/organize-rs_core/src/rules/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};

/// Colours for `MacOS` tags
#[cfg(target_os = "osx")]
#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
#[derive(Debug, Clone, Copy, Deserialize, Serialize, ValueEnum)]
pub enum MacOsTagColours {
None,
Gray,
Expand Down Expand Up @@ -296,7 +296,7 @@ pub enum OrganizeAction {
/// to be a target directory and the file / dir will be
/// copied into `destination`and keep its name.
#[clap(long)]
destination: String,
dest: String,
/// What should happen in case dest already exists.
/// One of skip, overwrite, trash, rename_new and rename_existing.
///
Expand Down Expand Up @@ -358,7 +358,7 @@ pub enum OrganizeAction {
#[serde(rename = "echo")]
Echo {
#[clap(long)]
message: String,
msg: String,
},
/// Add macOS tags.
///
Expand Down Expand Up @@ -434,7 +434,7 @@ pub enum OrganizeAction {
/// to be a target directory and the file / dir will be
/// moved into `destination`and keep its name.
#[clap(long)]
destination: String,
dest: String,
/// What should happen in case dest already exists.
/// One of skip, overwrite, trash, rename_new and rename_existing.
///
Expand Down Expand Up @@ -495,7 +495,7 @@ pub enum OrganizeAction {
/// Only the local filesystem is supported.
// TODO: Can contain placeholders?
#[clap(long)]
destination: String,
dest: String,
},
/// Move a file or dir into the trash.
///
Expand Down Expand Up @@ -546,7 +546,7 @@ pub enum OrganizeAction {
Write {
/// The text that should be written. Supports templates.
#[clap(long)]
text: String,
txt: String,
/// The file `text` should be written into. Supports templates.
///
// Defaults to `organize-out.txt`
Expand Down Expand Up @@ -577,10 +577,6 @@ pub enum OrganizeAction {
#[clap(long)]
filesystem: Option<String>,
},
#[cfg(feature = "research_organize")]
#[serde(rename = "python")]
Python,
#[cfg(feature = "research_organize")]
#[serde(rename = "shell")]
Shell,
}
Expand Down Expand Up @@ -633,15 +629,15 @@ impl OrganizeAction {
}

pub fn as_echo(&self) -> Option<&String> {
if let Self::Echo { message } = self {
if let Self::Echo { msg: message } = self {
Some(message)
} else {
None
}
}

pub fn try_into_echo(self) -> Result<String, Self> {
if let Self::Echo { message } = self {
if let Self::Echo { msg: message } = self {
Ok(message)
} else {
Err(self)
Expand Down Expand Up @@ -700,15 +696,15 @@ impl OrganizeAction {
}

pub fn as_symlink(&self) -> Option<&String> {
if let Self::Symlink { destination } = self {
if let Self::Symlink { dest: destination } = self {
Some(destination)
} else {
None
}
}

pub fn try_into_symlink(self) -> Result<String, Self> {
if let Self::Symlink { destination } = self {
if let Self::Symlink { dest: destination } = self {
Ok(destination)
} else {
Err(self)
Expand Down
21 changes: 9 additions & 12 deletions crates/organize-rs_core/src/rules/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ pub enum OrganizeFilter {
#[serde(rename = "extension")]
Extension {
#[clap(long)]
extensions: Vec<String>,
ext: Vec<String>,
},
/// Matches file content with the given regular expression
///
Expand All @@ -545,7 +545,7 @@ pub enum OrganizeFilter {
#[serde(rename = "filecontent")]
Filecontent {
#[clap(long)]
expression: String,
regex: String,
},
// TODO: Check for available hash algorithms from organize-py
// TODO: shake_256, sha3_256, sha1, sha3_224, sha384, sha512, blake2b,
Expand Down Expand Up @@ -669,9 +669,6 @@ pub enum OrganizeFilter {
#[clap(long)]
case_sensitive: bool,
},
#[cfg(feature = "research_organize")]
#[serde(rename = "python")]
Python,
/// Matches filenames with the given regular expression
///
/// Any named groups `((?P<groupname>.*))` in your regular
Expand All @@ -698,7 +695,7 @@ pub enum OrganizeFilter {
#[serde(rename = "regex")]
Regex {
#[clap(long)]
expression: String,
expr: String,
},
/// Matches files and folders by size
///
Expand Down Expand Up @@ -923,15 +920,15 @@ impl OrganizeFilter {
}

pub fn as_regex(&self) -> Option<&String> {
if let Self::Regex { expression } = self {
if let Self::Regex { expr: expression } = self {
Some(expression)
} else {
None
}
}

pub fn try_into_regex(self) -> Result<String, Self> {
if let Self::Regex { expression } = self {
if let Self::Regex { expr: expression } = self {
Ok(expression)
} else {
Err(self)
Expand Down Expand Up @@ -963,31 +960,31 @@ impl OrganizeFilter {
}

pub fn as_extension(&self) -> Option<&Vec<String>> {
if let Self::Extension { extensions } = self {
if let Self::Extension { ext: extensions } = self {
Some(extensions)
} else {
None
}
}

pub fn try_into_extension(self) -> Result<Vec<String>, Self> {
if let Self::Extension { extensions } = self {
if let Self::Extension { ext: extensions } = self {
Ok(extensions)
} else {
Err(self)
}
}

pub fn as_filecontent(&self) -> Option<&String> {
if let Self::Filecontent { expression } = self {
if let Self::Filecontent { regex: expression } = self {
Some(expression)
} else {
None
}
}

pub fn try_into_filecontent(self) -> Result<String, Self> {
if let Self::Filecontent { expression } = self {
if let Self::Filecontent { regex: expression } = self {
Ok(expression)
} else {
Err(self)
Expand Down
Loading

0 comments on commit f5df157

Please sign in to comment.