Skip to content

Commit

Permalink
Cleanup TODO, Inherit all CLI exceptions from single base class
Browse files Browse the repository at this point in the history
  • Loading branch information
katyukha committed Jul 27, 2023
1 parent 4f8f0ca commit 855bbc2
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 53 deletions.
7 changes: 0 additions & 7 deletions subpackages/cli/source/odood/cli/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,6 @@ class App: OdoodProgram {
override int run(ref string[] args) {
try {
return super.run(args);
} catch (OdoodException e) {
// TODO: Use custom colodred formatting for errors
if (enable_debug)
error("Odood Exception catched:\n%s".format(e));
else
error("%s".format(e.msg));
return 1;
} catch (Exception e) {
// TODO: Use custom colodred formatting for errors
if (enable_debug)
Expand Down
11 changes: 5 additions & 6 deletions subpackages/cli/source/odood/cli/commands/addons.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ private import thepath: Path;
private import commandr: Argument, Option, Flag, ProgramArgs;
private import colored;

private import odood.cli.core: OdoodCommand;
private import odood.cli.core: OdoodCommand, OdoodCLIException;
private import odood.lib.project: Project;
private import odood.utils.odoo.serie: OdooSerie;
private import odood.utils.addons.addon: OdooAddon;
private import odood.exception: OdoodException;


enum AddonDisplayType {
Expand Down Expand Up @@ -362,7 +361,7 @@ class CommandAddonsUpdate: OdoodCommand {
if (!args.flag("all")) {
foreach(addon_name; args.args("addon")) {
auto addon = project.addons.getByString(addon_name);
enforce!OdoodException(
enforce!OdoodCLIException(
!addon.isNull,
"%s does not look like addon name or path to addon".format(
addon_name));
Expand Down Expand Up @@ -440,7 +439,7 @@ class CommandAddonsInstall: OdoodCommand {
OdooAddon[] addons;
foreach(addon_name; args.args("addon")) {
auto addon = project.addons.getByString(addon_name);
enforce!OdoodException(
enforce!OdoodCLIException(
!addon.isNull,
"%s does not look like addon name or path to addon".format(
addon_name));
Expand Down Expand Up @@ -506,7 +505,7 @@ class CommandAddonsUninstall: OdoodCommand {
OdooAddon[] addons;
foreach(addon_name; args.args("addon")) {
auto addon = project.addons.getByString(addon_name);
enforce!OdoodException(
enforce!OdoodCLIException(
!addon.isNull,
"%s does not look like addon name or path to addon".format(
addon_name));
Expand Down Expand Up @@ -589,7 +588,7 @@ class CommandAddonsIsInstalled: OdoodCommand {
auto project = Project.loadProject;

auto addon_n = project.addons.getByString(args.arg("addon"));
enforce!OdoodException(
enforce!OdoodCLIException(
!addon_n.isNull,
"Cannot find addon %s".format(args.arg("addon")));
auto addon = addon_n.get();
Expand Down
1 change: 0 additions & 1 deletion subpackages/cli/source/odood/cli/commands/ci.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ private import commandr: Argument, Option, Flag, ProgramArgs;

private import odood.cli.core: OdoodCommand;
private import odood.lib.project: Project;
private import odood.exception: OdoodException;
private import odood.lib.odoo.utils: fixVersionConflict;


Expand Down
12 changes: 5 additions & 7 deletions subpackages/cli/source/odood/cli/commands/database.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ private import std.typecons;
private import thepath: Path;
private import commandr: Argument, Option, Flag, ProgramArgs;

private import odood.cli.core: OdoodCommand, exitWithCode;
private import odood.cli.core: OdoodCommand, exitWithCode, OdoodCLIException;
private import odood.lib.project: Project;
private import odood.lib.odoo.lodoo: BackupFormat;
private import odood.utils.odoo.serie: OdooSerie;
private import odood.utils: generateRandomString;
private import odood.utils.addons.addon: OdooAddon;

// TODO: Use specific exception tree for CLI part
private import odood.exception: OdoodException;


class CommandDatabaseList: OdoodCommand {
Expand Down Expand Up @@ -72,7 +70,7 @@ class CommandDatabaseCreate: OdoodCommand {
OdooAddon[] to_install;
foreach(addon_name; args.options("install")) {
auto addon = project.addons.getByName(addon_name);
enforce!OdoodException(
enforce!OdoodCLIException(
!addon.isNull,
"Cannot find addon %s".format(addon_name));
to_install ~= addon.get;
Expand All @@ -90,7 +88,7 @@ class CommandDatabaseCreate: OdoodCommand {
"(because --recreate option specified).", dbname);
project.databases.drop(dbname);
} else {
throw new OdoodException(
throw new OdoodCLIException(
"Database %s already exists!".format(dbname));
}
}
Expand Down Expand Up @@ -200,7 +198,7 @@ class CommandDatabaseBackup: OdoodCommand {
public override void execute(ProgramArgs args) {
auto project = Project.loadProject;

enforce!OdoodException(
enforce!OdoodCLIException(
args.flag("all") || args.args("name").length > 0,
"It is required to specify name of database to backup or option -a or --all!");

Expand Down Expand Up @@ -258,7 +256,7 @@ class CommandDatabaseRestore: OdoodCommand {
"(because --recreate option specified).", dbname);
project.databases.drop(dbname);
} else {
throw new OdoodException(
throw new OdoodCLIException(
"Database %s already exists!".format(dbname));
}
}
Expand Down
1 change: 0 additions & 1 deletion subpackages/cli/source/odood/cli/commands/discover.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ private import odood.cli.core: OdoodCommand;
private import odood.lib.project: Project;
private import odood.lib.project.discover: discoverOdooHelper;
private import odood.utils.odoo.serie: OdooSerie;
private import odood.exception: OdoodException;


class CommandDiscoverOdooHelper: OdoodCommand {
Expand Down
5 changes: 2 additions & 3 deletions subpackages/cli/source/odood/cli/commands/init.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ private import std.exception: enforce;
private import thepath: Path;
private import commandr: Option, Flag, ProgramArgs;

private import odood.cli.core: OdoodCommand;
private import odood.cli.core: OdoodCommand, OdoodCLIException;
private import odood.lib.project: Project;
private import odood.lib.odoo.config: initOdooConfig;
private import odood.lib.postgres: createNewPostgresUser;
private import odood.utils.odoo.serie: OdooSerie;
private import odood.exception: OdoodException;


class CommandInit: OdoodCommand {
Expand Down Expand Up @@ -79,7 +78,7 @@ class CommandInit: OdoodCommand {
auto odoo_repo = args.option(
"odoo-repo", "https://github.com/odoo/odoo.git");

enforce!OdoodException(
enforce!OdoodCLIException(
odoo_version.isValid,
"Odoo version %s is not valid".format(args.option("odoo-version")));

Expand Down
8 changes: 3 additions & 5 deletions subpackages/cli/source/odood/cli/commands/script.d
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ private import commandr: Argument, Option, Flag, ProgramArgs;

private import thepath;

private import odood.cli.core: OdoodCommand;
private import odood.cli.core: OdoodCommand, OdoodCLIException;
private import odood.lib.project: Project;
private import odood.exception: OdoodException;


class CommandScriptPy: OdoodCommand {
Expand All @@ -26,7 +25,7 @@ class CommandScriptPy: OdoodCommand {
auto dbname = args.option("db");
Path script = args.arg("script");

enforce!OdoodException(
enforce!OdoodCLIException(
project.databases.exists(args.option("db")),
"Database %s does not exists!".format(args.option("db")));

Expand All @@ -53,8 +52,7 @@ class CommandScriptSQL: OdoodCommand {
auto dbname = args.option("db");
Path script = args.arg("script");

// TODO: check existense of db via SQL
enforce!OdoodException(
enforce!OdoodCLIException(
project.databases.exists(dbname),
"Database %s does not exists!".format(dbname));

Expand Down
1 change: 0 additions & 1 deletion subpackages/cli/source/odood/cli/commands/server.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ private import commandr: Option, Flag, ProgramArgs;
private import odood.cli.core: OdoodCommand;
private import odood.lib.project: Project;
private import odood.utils.odoo.serie: OdooSerie;
private import odood.exception: OdoodException;


class CommandServerRun: OdoodCommand {
Expand Down
1 change: 0 additions & 1 deletion subpackages/cli/source/odood/cli/commands/status.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ private import commandr: Option, Flag, ProgramArgs;
private import odood.cli.core: OdoodCommand;
private import odood.lib.project: Project;
private import odood.utils.odoo.serie: OdooSerie;
private import odood.exception: OdoodException;


immutable string TMPL_CURRENT_PROJECT_STATUS = "
Expand Down
1 change: 0 additions & 1 deletion subpackages/cli/source/odood/cli/commands/test.d
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ private import odood.cli.core: OdoodCommand, exitWithCode;
private import odood.lib.project: Project;
private import odood.lib.odoo.log: OdooLogProcessor, OdooLogRecord;
private import odood.utils.odoo.serie: OdooSerie;
private import odood.exception: OdoodException;


/** Color log level, depending on log level itself
Expand Down
18 changes: 12 additions & 6 deletions subpackages/cli/source/odood/cli/core/exception.d
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
module odood.cli.core.exception;

private import std.exception;


/** Base class for all Odood CLI exceptions
**/
class OdoodCLIException : Exception {
mixin basicExceptionCtors;
}


/** This exception identifies, that in Odood program commandr Command
* is used instead of OdoodCommand.
* Currently, it is not allowed to mix odood commands and commandr commands
* in one app
**/
class OdoodCLICommandNoExecuteException : Exception {

this(string msg, string file = __FILE__, size_t line = __LINE__) {
super(msg, file, line);
}
class OdoodCLICommandNoExecuteException : OdoodCLIException {
mixin basicExceptionCtors;
}


class OdoodCLIExitException : Exception
class OdoodCLIExitException : OdoodCLIException
{
private int _exit_code;

Expand Down
2 changes: 0 additions & 2 deletions subpackages/lib/source/odood/lib/install/odoo.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ private import odood.utils;
* project = Project to download Odoo to.
**/
void installDownloadOdoo(in Project project) {
// TODO: replace with logger calls, or with colored output.
import std.stdio;
auto odoo_archive_path = project.directories.downloads.join(
"odoo.%s.zip".format(project.odoo.branch));
scope(exit) {
Expand Down
5 changes: 3 additions & 2 deletions subpackages/lib/source/odood/lib/odoo/db_manager.d
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ struct OdooDatabaseManager {
**/
bool exists(in string name) const {
// TODO: replace with project's db wrapper to check if database exists
// This could simplify performance by avoiding call to python
// interpreter
// This could improve performance by avoiding call to python
// interpreter. Take into account that database could exist,
// but still could not be visible for Odoo.
return _project.lodoo(_test_mode).databaseExists(name);
}

Expand Down
1 change: 0 additions & 1 deletion subpackages/lib/source/odood/lib/odoo/lodoo.d
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ const struct LOdoo {
Path databaseBackup(
in string dbname,
in BackupFormat backup_format = BackupFormat.zip) {
// TODO: Add ability to specify backup path
import std.datetime.systime: Clock;

string dest_name="db-backup-%s-%s.%s.%s".format(
Expand Down
2 changes: 1 addition & 1 deletion subpackages/lib/source/odood/lib/odoo/utils.d
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ string fixVersionConflictImpl(in string manifest_content, in OdooSerie serie) {

auto new_ver = change_version > head_version ? change_version : head_version;

// TODO: find better way. Check if head nad change versions are valid
// TODO: find better way. Check if head and change versions are valid
assert(new_ver.isValid, "New version is not valid!");

return "%s%s%s.%s%s,\n".format(
Expand Down
4 changes: 0 additions & 4 deletions subpackages/lib/source/odood/lib/project/project.d
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ class Project {
* that contains odood.yml config file
**/
static auto loadProject(in Path path) {

// TODO: convert path to absolute
// do we need this? Will be converted in constructor.
if (path.exists && path.isFile) {
Node config = dyaml.Loader.fromFile(path.toString()).load();
return new Project(config, path);
Expand Down Expand Up @@ -359,7 +356,6 @@ class Project {

// TODO: Add support for cases when odoo installed via git
// In this case it is better to just run git pull
// TODO: Add support for updating to other version of Odoo
enforce!OdoodException(
!this.odoo.path.join(".git").exists,
"Cannot update odoo that is git repo yet!");
Expand Down
4 changes: 0 additions & 4 deletions subpackages/lib/source/odood/lib/venv.d
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,6 @@ const struct VirtualEnv {
.ensureStatus();
}

// TODO: Install 'make' and 'libsqlite3-dev' if needed
// Possibly have to be added when installation of system packages
// will be implemented

// Configure python build
info("Running python's configure script...");
Process(python_build_dir.join("configure"))
Expand Down

0 comments on commit 855bbc2

Please sign in to comment.