Minor message fix and fix of checkFileFormats

parent 0388e9dc
......@@ -49,8 +49,8 @@
"Permissions: ","Права доступа: ","Rajtoj de aliro: "
"Accessed: ","Посл.обр.: ","Alirita: "
"Size: ","Размер: ","Mezuro: "
"Maybe you meant 'filespaces'?","Возможно, вы имели в виду ""filespaces""?","Eble vi volis tajpi ""filespaces""?"
"Maybe you meant 'filespace'?","Возможно, вы имели в виду ""filespace""?","Eble vi volis tajpi ""filespace""?"
"Maybe did you mean 'filespaces'?","Возможно, вы имели в виду ""filespaces""?","Eble vi volis tajpi ""filespaces""?"
"Maybe did you mean 'filespace'?","Возможно, вы имели в виду ""filespace""?","Eble vi volis tajpi ""filespace""?"
"There is no file space.","Нет такого файлового пространства.","Tiela dosiera spaco ne ekzistas."
"File spaces are not configured.","Файловые пространства не настроены.","Dosieraj spacoj ne estas agorditaj."
"The problem in the configuration of the file spaces.","Проблема в конфигурации файловых пространств.","Estas problemo en konfiguracio de dosieraj spacoj."
......@@ -121,3 +121,5 @@
"The categories are combining.","Категории объединяются.","La kategorioj unuiĝas."
": this subcategory already exists.",": такая подкатегория уже существует.",": tiu subkategorio jam ekzistas."
"Exactly the same file already exists in the file space.","Точно такой же файл уже существует в файловом пространстве.","Absolute identa dosiero jam ekzistas en la dosiera spaco."
"Automatic categorization by file format is disabled","Автокатегоризация по форматам файлов отключена.",""
"Nothing to check.","Нечего проверять.",""
/* This file is part of Vitis.
*
* Copyright (C) 2018 Eugene 'Vindex' Stulin
* Copyright (C) 2018-2020 Eugene 'Vindex' Stulin
*
* Vitis is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -24,15 +24,11 @@ import module_help;
import amalthea.fileformats;
void mainFn(string[] args) {
cmdService(args);
}
/*******************************************************************************
* Service management
*/
void cmdService(string[] args) {
void mainFn(string[] args) {
enforce(args.length > 1,
new ValidException("Wrong using of command 'service'."._s));
......@@ -57,7 +53,7 @@ void cmdService(string[] args) {
default:
string err = "Wrong using of command 'service'."._s;
if ("filespace" == args[2])
err ~= "\n" ~ "Maybe you meant 'filespaces'?"._s;
err ~= "\n" ~ "Maybe did you mean 'filespaces'?"._s;
throw new ValidException(err);
}
break;
......@@ -81,7 +77,7 @@ void cmdService(string[] args) {
default:
string err = "Wrong using of command 'service'."._s;
if ("filespace" == args[2])
err ~= "\n" ~ "Maybe you meant 'filespaces'?"._s;
err ~= "\n" ~ "Maybe did you mean 'filespaces'?"._s;
throw new ValidException(err);
}
break;
......@@ -91,7 +87,7 @@ void cmdService(string[] args) {
default:
string err = "Wrong using of command 'service'."._s;
if ("filespaces" == args[2])
err ~= "\n" ~ "Maybe you meant 'filespace'?"._s;
err ~= "\n" ~ "Maybe did you mean 'filespace'?"._s;
throw new ValidException(err);
}
break;
......@@ -101,7 +97,7 @@ void cmdService(string[] args) {
default:
string err = "Wrong using of command 'service'."._s;
if ("filespaces" == args[2])
err ~= "\n" ~ "Maybe you meant 'filespace'?"._s;
err ~= "\n" ~ "Maybe did you mean 'filespace'?"._s;
throw new ValidException(err);
}
break;
......@@ -111,7 +107,7 @@ void cmdService(string[] args) {
default:
string err = "Wrong using of command 'service'."._s;
if ("filespaces" == args[2])
err ~= "\n" ~ "Maybe you meant 'filespace'?"._s;
err ~= "\n" ~ "Maybe did you mean 'filespace'?"._s;
throw new ValidException(err);
}
break;
......@@ -163,7 +159,7 @@ void check(string[] checkOptions) {
checkSavedPages(categories, flagInteractive, flagFix, flagFresh);
break;
case "fileformats":
checkFileFormats(category);
checkFileFormats(category, flagInteractive, flagFix);
break;
default:
throw new ValidException("Wrong using of command 'service'."._s);
......@@ -242,9 +238,8 @@ void checkUnnecessaryLinks(string[] dirs, bool flagInteractive, bool flagFix) {
"-> ",
"Do you want to remove unnecessary link? y/n >: "._s
);
string ans = readln;
ans = std.string.strip(ans).toLower;
if (ans.among("y"._s, "yes"._s, "y", "yes")) {
bool yes = getAnswerToTheQuestion();
if (yes) {
rm(link);
} else {
"simple".tprint("-> ", "Skipped."._s, "\n");
......@@ -308,75 +303,98 @@ void checkSavedPages(string[] dirs,
}
}
bool checkForAutoCategory(string linkpath, string filepath) {
string ext = std.path.extension(linkpath);
if (ext == ".desktop" || ext == ".fragpointer") {
return true;
void checkFileFormats(string category = "",
bool flagInteractive = false,
bool flagFix = false) {
auto automodes = VitisConf.getAutocategorization().split(';').array;
if (!canFind(automodes, "format")) {
tprintln("Automatic categorization by file format is disabled."._s);
tprintln("Nothing to check."._s);
return;
}
return false;
}
void checkFileFormats(string category = "") {
string[string] allLinks;
if (category.empty) {
allLinks = getAllLinks();
allLinks = getAllNoAutoLinks();
} else {
string categoryPath = getCatDirPath(category);
auto tempLinks = getSymlinksInfo(categoryPath);
foreach(k, v; tempLinks) allLinks[k] = v;
}
foreach(linkpath, filepath; allLinks) {
if (checkForAutoCategory(linkpath, filepath)) continue;
auto fileType = amalthea.fileformats.getFileFormat(filepath);
auto formatCatPath = getFormatCategoryPath ~ fileType.format ~ "/";
mkdirRecurse(formatCatPath);
auto linksOfFormatCategory = getSymlinksInfo(formatCatPath);
bool formatIsCorrect = false;
foreach(lpath, fpath; linksOfFormatCategory) {
if (linkpath == lpath) {
formatIsCorrect = true;
break;
string topFormatDir = getFormatCategoryPath();
string topTypeDir = getTypeCategoryPath();
FileFormat currFileFormat;
void checkCorrectnessOfFormatAutocategory(string lp, //linkpath
string fp, //filepath
string autocategorization) {
string catPath;
string topCatPath;
string category;
if (autocategorization == "format") {
category = formatCategory() ~ "/" ~ currFileFormat.format;
topCatPath = topFormatDir;
catPath = topFormatDir ~ currFileFormat.format ~ "/";
} else if (autocategorization == "type") {
if (currFileFormat.group.empty) {
return;
}
category = typeCategory() ~ "/" ~ currFileFormat.group;
topCatPath = topTypeDir;
catPath = topTypeDir ~ currFileFormat.group ~ "/";
}
if (!formatIsCorrect) {
//we remove current link in old format categories
string[string] linksOfFormatRootDir
= getSymlinksInfo(getFormatCategoryPath);
foreach(l, f; linksOfFormatRootDir) {
if (f == filepath) rm(l);
if (exists(catPath)) {
foreach(lpath, fpath; getSymlinksInfo(catPath)) {
if (fp == fpath) {
return; // it's OK
}
}
//we create new link in new format category
auto w = ": this file is assigned new format category";
auto formatCategory = "Format/" ~ fileType.format;
auto msg = format("%s %s (%s).", linkpath, w, formatCategory);
"warning".tprintln(msg);
symlink(filepath, formatCatPath ~ linkpath.baseName);
}
auto typeCatPath = getTypeCategoryPath ~ fileType.group ~ "/";
mkdirRecurse(typeCatPath);
auto linksOfTypeCategory = getSymlinksInfo(typeCatPath);
bool typeIsCorrect = false;
foreach(lpath, fpath; linksOfTypeCategory) {
if (linkpath == lpath) {
typeIsCorrect = true;
break;
}
string msg = "doesn't have correct format category."._s;
msg = msg.replace("format", autocategorization);
msg = format("%s %s", lp, msg._s);
"warning".tprintln(msg);
bool yes = false;
if (flagInteractive && !flagFix) {
yes = getAnswerToTheQuestion("Rectify the situation? y/n >: "._s);
}
if (!yes && !flagFix) {
return;
}
if (!catPath.exists) {
mkdirRecurse(catPath);
}
if (!typeIsCorrect) {
//we remove current link in old type categories
string[string] linksOfTypeRootDir
= getSymlinksInfo(getTypeCategoryPath);
foreach(l, f; linksOfTypeRootDir) {
if (f == filepath) rm(l);
//we remove current link in old format (or type) categories
foreach(lpath, fpath; getSymlinksInfo(topCatPath)) {
if (fpath == fp) {
amalthea.fs.rm(lpath);
}
//we create new link in new type category
auto w = ": this file is assigned new type category";
auto typeCategory = "Type/" ~ fileType.group;
auto msg = format("%s %s (%s).", linkpath, w, typeCategory);
"warning".tprintln(msg);
symlink(filepath, typeCatPath ~ linkpath.baseName);
}
//we create new link in new category
if (!exists(catPath ~ lp.baseName)) {
symlink(fp, catPath ~ lp.baseName);
}
auto w = ": this file is assigned to new category"._s;
msg = format("%s%s (%s).", lp, w, category);
"warning".tprintln(msg);
}
foreach(linkpath, filepath; allLinks) {
currFileFormat = amalthea.fileformats.getFileFormat(filepath);
checkCorrectnessOfFormatAutocategory(linkpath, filepath, "format");
checkCorrectnessOfFormatAutocategory(linkpath, filepath, "type");
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment