mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 12:05:46 +00:00
(WIP) Minor misc. changes
This commit is contained in:
parent
d2af261f67
commit
011626f09b
@ -55,35 +55,42 @@ if __name__ == "__main__":
|
|||||||
"application/gzip",
|
"application/gzip",
|
||||||
"application/x-bzip2",
|
"application/x-bzip2",
|
||||||
"application/x-bzip2",
|
"application/x-bzip2",
|
||||||
"application/x-xz",
|
|
||||||
"application/x-xz"
|
# TODO: Is this right?
|
||||||
|
# Perhaps the output should be application/x-lzma
|
||||||
|
"application/octet-stream",
|
||||||
|
"application/octet-stream"
|
||||||
]
|
]
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
rv = os.system(f"cargo run -- -i ../src/ -o {file}")
|
rv = os.system(f"cargo run -- compress ../src/ {file}")
|
||||||
if rv != 0:
|
if rv != 0:
|
||||||
print(f"Failed while compressing {file}")
|
print(f"Failed while compressing {file}")
|
||||||
|
os._exit(2)
|
||||||
|
|
||||||
for (file, expected_mime) in zip(files, expected_mime_types):
|
for (file, expected_mime) in zip(files, expected_mime_types):
|
||||||
if m.file(file) != expected_mime:
|
if m.file(file) != expected_mime:
|
||||||
print(f"Test failed at file {file}")
|
print(f"Test failed at file {file}.")
|
||||||
|
print(f"Got: {m.file(file)}.")
|
||||||
|
print(f"Expected: {expected_mime}.")
|
||||||
os._exit(2)
|
os._exit(2)
|
||||||
|
|
||||||
for (idx, file) in enumerate(files):
|
for (idx, file) in enumerate(files):
|
||||||
rv = os.system(f"cargo run -- -i {file} -o out{idx}/")
|
rv = os.system(f"cargo run -- {file} -o out{idx}/")
|
||||||
if rv != 0:
|
if rv != 0:
|
||||||
print(f"Failed while decompressing {file}")
|
print(f"Failed while decompressing {file}")
|
||||||
os._exit(2)
|
os._exit(2)
|
||||||
|
|
||||||
os.chdir("..")
|
# os.chdir("..")
|
||||||
os.system("rm -rf testbuilds")
|
# os.system("rm -rf testbuilds")
|
||||||
|
|
||||||
# We'll now verify if ouch is not altering the data it is compressing
|
# # We'll now verify if ouch is not altering the data it is compressing
|
||||||
# and decompressing
|
# # and decompressing
|
||||||
|
|
||||||
sanity_check_format("tar")
|
# sanity_check_format("zip")
|
||||||
sanity_check_format("tar.gz")
|
# sanity_check_format("tar")
|
||||||
sanity_check_format("tar.bz")
|
# sanity_check_format("tar.gz")
|
||||||
sanity_check_format("tar.bz2")
|
# sanity_check_format("tar.bz")
|
||||||
sanity_check_format("tar.lz")
|
# sanity_check_format("tar.bz2")
|
||||||
sanity_check_format("tar.lzma")
|
# sanity_check_format("tar.lz")
|
||||||
|
# sanity_check_format("tar.lzma")
|
@ -2,6 +2,10 @@ use std::{env, ffi::OsString, io, path::PathBuf, vec::Vec};
|
|||||||
|
|
||||||
use oof::{arg_flag, flag};
|
use oof::{arg_flag, flag};
|
||||||
|
|
||||||
|
use crate::debug;
|
||||||
|
|
||||||
|
pub const VERSION: &str = "0.1.5";
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug)]
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
/// Files to be compressed
|
/// Files to be compressed
|
||||||
@ -83,16 +87,18 @@ pub fn parse_args_from(mut args: Vec<OsString>) -> crate::Result<ParsedArgs> {
|
|||||||
// Defaults to decompression when there is no subcommand
|
// Defaults to decompression when there is no subcommand
|
||||||
None => {
|
None => {
|
||||||
flags_info.push(arg_flag!('o', "output"));
|
flags_info.push(arg_flag!('o', "output"));
|
||||||
|
debug!(&flags_info);
|
||||||
|
|
||||||
// Parse flags
|
// Parse flags
|
||||||
let (args, mut flags) = oof::filter_flags(args, &flags_info)?;
|
let (args, mut flags) = oof::filter_flags(args, &flags_info)?;
|
||||||
|
debug!((&args, &flags));
|
||||||
|
|
||||||
let files: Vec<_> = args.into_iter().map(PathBuf::from).collect();
|
let files: Vec<_> = args.into_iter().map(PathBuf::from).collect();
|
||||||
|
// TODO: This line doesn't seem to be working correctly
|
||||||
let output_folder = flags.take_arg("output").map(PathBuf::from);
|
let output_folder = flags.take_arg("output").map(PathBuf::from);
|
||||||
|
|
||||||
// Is the output here fully correct?
|
// Is the output here fully correct?
|
||||||
// With the paths not canonicalized?
|
// With the paths not canonicalized?
|
||||||
|
|
||||||
let command = Command::Decompress {
|
let command = Command::Decompress {
|
||||||
files,
|
files,
|
||||||
output_folder,
|
output_folder,
|
||||||
|
@ -29,6 +29,7 @@ impl TarCompressor {
|
|||||||
for entry in WalkDir::new(&filename) {
|
for entry in WalkDir::new(&filename) {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
|
println!("Compressing {:?}", path);
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,9 @@ impl ZipCompressor {
|
|||||||
if entry_path.is_dir() {
|
if entry_path.is_dir() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.start_file(entry_path.to_string_lossy(), options)?;
|
writer.start_file(entry_path.to_string_lossy(), options)?;
|
||||||
|
println!("Compressing {:?}", entry_path);
|
||||||
let file_bytes = std::fs::read(entry.path())?;
|
let file_bytes = std::fs::read(entry.path())?;
|
||||||
writer.write_all(&*file_bytes)?;
|
writer.write_all(&*file_bytes)?;
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,9 @@ use std::{
|
|||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cli::Command,
|
cli::{VERSION, Command},
|
||||||
compressors::{
|
compressors::{
|
||||||
BzipCompressor, Compressor, Entry, GzipCompressor, LzmaCompressor, TarCompressor,
|
Entry, Compressor, BzipCompressor, GzipCompressor, LzmaCompressor, TarCompressor,
|
||||||
ZipCompressor,
|
ZipCompressor,
|
||||||
},
|
},
|
||||||
decompressors::{
|
decompressors::{
|
||||||
@ -19,7 +19,7 @@ use crate::{
|
|||||||
dialogs::Confirmation,
|
dialogs::Confirmation,
|
||||||
extension::{CompressionFormat, Extension},
|
extension::{CompressionFormat, Extension},
|
||||||
file::File,
|
file::File,
|
||||||
utils,
|
utils
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Evaluator {}
|
pub struct Evaluator {}
|
||||||
@ -31,6 +31,7 @@ impl Evaluator {
|
|||||||
pub fn get_compressor(
|
pub fn get_compressor(
|
||||||
file: &File,
|
file: &File,
|
||||||
) -> crate::Result<(Option<BoxedCompressor>, BoxedCompressor)> {
|
) -> crate::Result<(Option<BoxedCompressor>, BoxedCompressor)> {
|
||||||
|
|
||||||
let extension = match &file.extension {
|
let extension = match &file.extension {
|
||||||
Some(extension) => extension.clone(),
|
Some(extension) => extension.clone(),
|
||||||
None => {
|
None => {
|
||||||
@ -266,9 +267,25 @@ impl Evaluator {
|
|||||||
Self::decompress_file(file, output_folder, flags)?;
|
Self::decompress_file(file, output_folder, flags)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command::ShowHelp => todo!("call help function"),
|
Command::ShowHelp => help_message(),
|
||||||
Command::ShowVersion => todo!("call version function"),
|
Command::ShowVersion => version_message(),
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn version_message() {
|
||||||
|
println!("ouch {}", VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn help_message() {
|
||||||
|
version_message();
|
||||||
|
println!("Vinícius R. M. & João M. Bezerra");
|
||||||
|
println!("ouch is a unified compression & decompression utility");
|
||||||
|
println!();
|
||||||
|
println!(" COMPRESSION USAGE:");
|
||||||
|
println!(" ouch compress <input...> output-file");
|
||||||
|
println!("DECOMPRESSION USAGE:");
|
||||||
|
println!(" ouch <input> [-o/--output output-folder]");
|
||||||
|
}
|
@ -23,6 +23,6 @@ fn main() {
|
|||||||
|
|
||||||
fn run() -> crate::Result<()> {
|
fn run() -> crate::Result<()> {
|
||||||
let ParsedArgs { command, flags } = cli::parse_args()?;
|
let ParsedArgs { command, flags } = cli::parse_args()?;
|
||||||
dbg!(&command);
|
debug!(&command);
|
||||||
Evaluator::evaluate(command, &flags)
|
Evaluator::evaluate(command, &flags)
|
||||||
}
|
}
|
||||||
|
15
src/utils.rs
15
src/utils.rs
@ -9,6 +9,19 @@ use colored::Colorize;
|
|||||||
|
|
||||||
use crate::{dialogs::Confirmation, extension::CompressionFormat, file::File};
|
use crate::{dialogs::Confirmation, extension::CompressionFormat, file::File};
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
macro_rules! debug {
|
||||||
|
($x:expr) => { dbg!($x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
#[cfg(not(debug_assertions))]
|
||||||
|
macro_rules! debug {
|
||||||
|
($x:expr) => { std::convert::identity($x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pub(crate) fn ensure_exists<'a, P>(path: P) -> crate::Result<()>
|
pub(crate) fn ensure_exists<'a, P>(path: P) -> crate::Result<()>
|
||||||
where
|
where
|
||||||
P: AsRef<Path> + 'a,
|
P: AsRef<Path> + 'a,
|
||||||
@ -69,7 +82,7 @@ pub(crate) fn change_dir_and_return_parent(filename: &Path) -> crate::Result<Pat
|
|||||||
return Err(crate::Error::CompressingRootFolder);
|
return Err(crate::Error::CompressingRootFolder);
|
||||||
};
|
};
|
||||||
|
|
||||||
env::set_current_dir(parent).unwrap();
|
env::set_current_dir(parent).ok().ok_or(crate::Error::CompressingRootFolder)?;
|
||||||
|
|
||||||
Ok(previous_location)
|
Ok(previous_location)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user