Изменение имени проекта
This commit is contained in:
parent
7714bc498e
commit
cc1a81261a
16 changed files with 70 additions and 70 deletions
14
.gitignore
vendored
14
.gitignore
vendored
|
@ -2,13 +2,13 @@
|
||||||
docs.json
|
docs.json
|
||||||
__dummy.html
|
__dummy.html
|
||||||
docs/
|
docs/
|
||||||
/snapd
|
/snag
|
||||||
snapd.so
|
snag.so
|
||||||
snapd.dylib
|
snag.dylib
|
||||||
snapd.dll
|
snag.dll
|
||||||
snapd.a
|
snag.a
|
||||||
snapd.lib
|
snag.lib
|
||||||
snapd-test-*
|
snag-test-*
|
||||||
*.exe
|
*.exe
|
||||||
*.pdb
|
*.pdb
|
||||||
*.o
|
*.o
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
# snapd
|
# snag
|
||||||
|
|
||||||
Snapshot D - система резервного копирования на основе фиксации состояния файлов с помощью Git.
|
Snapshot Git - система резервного копирования на основе фиксации состояния файлов с помощью Git.
|
||||||
|
|
2
dub.json
2
dub.json
|
@ -5,7 +5,7 @@
|
||||||
"copyright": "Copyright © 2025, Alexander Zhirov",
|
"copyright": "Copyright © 2025, Alexander Zhirov",
|
||||||
"description": "A backup system based on tracking file states using Git",
|
"description": "A backup system based on tracking file states using Git",
|
||||||
"license": "GPL-2.0-or-later",
|
"license": "GPL-2.0-or-later",
|
||||||
"name": "snapd",
|
"name": "snag",
|
||||||
"targetPath": "bin",
|
"targetPath": "bin",
|
||||||
"targetType": "executable",
|
"targetType": "executable",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
{
|
{
|
||||||
"git": "/tmp/testgit",
|
"git": "/tmp/testgit",
|
||||||
"project": "/home/alexander/Programming/new/dlang/snapd/source",
|
"project": "/home/alexander/Programming/new/dlang/snag/source",
|
||||||
"email": "user@site.domain",
|
"email": "user@site.domain",
|
||||||
"user": "snapd",
|
"user": "snag",
|
||||||
"presnap": [
|
"presnag": [
|
||||||
"/usr/bin/ls",
|
"/usr/bin/ls",
|
||||||
"/usr/local/bin/script.sh"
|
"/usr/local/bin/script.sh"
|
||||||
],
|
],
|
||||||
"postsnap": [
|
"postsnag": [
|
||||||
"/usr/bin/ls",
|
"/usr/bin/ls",
|
||||||
"/usr/local/bin/script.sh"
|
"/usr/local/bin/script.sh"
|
||||||
]
|
]
|
24
source/app.d
24
source/app.d
|
@ -1,14 +1,14 @@
|
||||||
import snapd;
|
import snag;
|
||||||
import commandr;
|
import commandr;
|
||||||
import std.file;
|
import std.file;
|
||||||
|
|
||||||
import core.stdc.stdlib : EXIT_SUCCESS, EXIT_FAILURE;
|
import core.stdc.stdlib : EXIT_SUCCESS, EXIT_FAILURE;
|
||||||
|
|
||||||
private string programName = "snapd";
|
private string programName = "snag";
|
||||||
|
|
||||||
int main(string[] args)
|
int main(string[] args)
|
||||||
{
|
{
|
||||||
auto argumets = new Program(programName, snapdVersion)
|
auto argumets = new Program(programName, snagVersion)
|
||||||
.add(new Command("init", "Initializing the repository for storing snapshots"))
|
.add(new Command("init", "Initializing the repository for storing snapshots"))
|
||||||
.add(new Command("status", "Checking the status of tracked files"))
|
.add(new Command("status", "Checking the status of tracked files"))
|
||||||
.add(new Command("create", "Create a new backup"))
|
.add(new Command("create", "Create a new backup"))
|
||||||
|
@ -21,31 +21,31 @@ int main(string[] args)
|
||||||
)
|
)
|
||||||
.parse(args);
|
.parse(args);
|
||||||
|
|
||||||
string configFile = argumets.option("config", "snapd.json");
|
string configFile = argumets.option("config", "snag.json");
|
||||||
|
|
||||||
SnapdConfig config;
|
SnagConfig config;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
config = new SnapdConfig(configFile);
|
config = new SnagConfig(configFile);
|
||||||
} catch (SnapdConfigException e) {
|
} catch (SnagConfigException e) {
|
||||||
e.print();
|
e.print();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto snapd = new Snapd(config);
|
auto snag = new Snag(config);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
argumets
|
argumets
|
||||||
.on("init", (init) {
|
.on("init", (init) {
|
||||||
snapd.initialize();
|
snag.initialize();
|
||||||
})
|
})
|
||||||
.on("status", (status) {
|
.on("status", (status) {
|
||||||
snapd.status();
|
snag.status();
|
||||||
})
|
})
|
||||||
.on("create", (create) {
|
.on("create", (create) {
|
||||||
snapd.create();
|
snag.create();
|
||||||
});
|
});
|
||||||
} catch (SnapdException e) {
|
} catch (SnagException e) {
|
||||||
e.print();
|
e.print();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module snapd.config.config;
|
module snag.config.config;
|
||||||
|
|
||||||
import std.json;
|
import std.json;
|
||||||
import std.file;
|
import std.file;
|
||||||
|
@ -6,9 +6,9 @@ import std.path;
|
||||||
import std.regex;
|
import std.regex;
|
||||||
import std.string;
|
import std.string;
|
||||||
|
|
||||||
import snapd.config.exception;
|
import snag.config.exception;
|
||||||
|
|
||||||
class SnapdConfig {
|
class SnagConfig {
|
||||||
private string _git;
|
private string _git;
|
||||||
private string _project;
|
private string _project;
|
||||||
private string _email;
|
private string _email;
|
||||||
|
@ -27,75 +27,75 @@ class SnapdConfig {
|
||||||
jsonText = readText(configFile);
|
jsonText = readText(configFile);
|
||||||
jsonData = parseJSON(jsonText);
|
jsonData = parseJSON(jsonText);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new SnapdConfigException(
|
throw new SnagConfigException(
|
||||||
"An error occurred while reading the configuration file:\n\t"
|
"An error occurred while reading the configuration file:\n\t"
|
||||||
~ e.msg
|
~ e.msg
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("git" !in jsonData)
|
if ("git" !in jsonData)
|
||||||
throw new SnapdConfigException(
|
throw new SnagConfigException(
|
||||||
"The configuration file is missing the \"git\" parameter"
|
"The configuration file is missing the \"git\" parameter"
|
||||||
);
|
);
|
||||||
|
|
||||||
_git = jsonData["git"].str;
|
_git = jsonData["git"].str;
|
||||||
|
|
||||||
if (!_git.length)
|
if (!_git.length)
|
||||||
throw new SnapdConfigException(
|
throw new SnagConfigException(
|
||||||
"The \"git\" parameter must contain the path to the directory"
|
"The \"git\" parameter must contain the path to the directory"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!_git.isAbsolute)
|
if (!_git.isAbsolute)
|
||||||
throw new SnapdConfigException(
|
throw new SnagConfigException(
|
||||||
"The \"git\" parameter must be an absolute path to the directory:\n\t"
|
"The \"git\" parameter must be an absolute path to the directory:\n\t"
|
||||||
~ _git
|
~ _git
|
||||||
);
|
);
|
||||||
|
|
||||||
if ("project" !in jsonData)
|
if ("project" !in jsonData)
|
||||||
throw new SnapdConfigException(
|
throw new SnagConfigException(
|
||||||
"The configuration file is missing the \"project\" parameter"
|
"The configuration file is missing the \"project\" parameter"
|
||||||
);
|
);
|
||||||
|
|
||||||
_project = jsonData["project"].str;
|
_project = jsonData["project"].str;
|
||||||
|
|
||||||
if (!_project.length)
|
if (!_project.length)
|
||||||
throw new SnapdConfigException(
|
throw new SnagConfigException(
|
||||||
"The \"project\" parameter must contain the path to the directory"
|
"The \"project\" parameter must contain the path to the directory"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!_project.isAbsolute)
|
if (!_project.isAbsolute)
|
||||||
throw new SnapdConfigException(
|
throw new SnagConfigException(
|
||||||
"The \"project\" parameter must be an absolute path to the directory:\n\t"
|
"The \"project\" parameter must be an absolute path to the directory:\n\t"
|
||||||
~ _project
|
~ _project
|
||||||
);
|
);
|
||||||
|
|
||||||
if ("email" !in jsonData)
|
if ("email" !in jsonData)
|
||||||
throw new SnapdConfigException(
|
throw new SnagConfigException(
|
||||||
"The configuration file is missing the \"email\" parameter"
|
"The configuration file is missing the \"email\" parameter"
|
||||||
);
|
);
|
||||||
|
|
||||||
_email = jsonData["email"].str;
|
_email = jsonData["email"].str;
|
||||||
|
|
||||||
if (!_email.length)
|
if (!_email.length)
|
||||||
throw new SnapdConfigException(
|
throw new SnagConfigException(
|
||||||
"The \"email\" parameter must contain an email address"
|
"The \"email\" parameter must contain an email address"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!isValidEmail(_email))
|
if (!isValidEmail(_email))
|
||||||
throw new SnapdConfigException(
|
throw new SnagConfigException(
|
||||||
"Invalid email address provided in the \"email\" parameter:\n\t"
|
"Invalid email address provided in the \"email\" parameter:\n\t"
|
||||||
~ _email
|
~ _email
|
||||||
);
|
);
|
||||||
|
|
||||||
if ("user" !in jsonData)
|
if ("user" !in jsonData)
|
||||||
throw new SnapdConfigException(
|
throw new SnagConfigException(
|
||||||
"The configuration file is missing the \"user\" parameter"
|
"The configuration file is missing the \"user\" parameter"
|
||||||
);
|
);
|
||||||
|
|
||||||
_user = jsonData["user"].str;
|
_user = jsonData["user"].str;
|
||||||
|
|
||||||
if (!_user.length)
|
if (!_user.length)
|
||||||
throw new SnapdConfigException(
|
throw new SnagConfigException(
|
||||||
"The \"user\" parameter must contain an user name"
|
"The \"user\" parameter must contain an user name"
|
||||||
);
|
);
|
||||||
}
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
module snapd.config.exception;
|
module snag.config.exception;
|
||||||
|
|
||||||
import std.exception;
|
import std.exception;
|
||||||
import std.stdio : writeln;
|
import std.stdio : writeln;
|
||||||
|
|
||||||
class SnapdConfigException : Exception {
|
class SnagConfigException : Exception {
|
||||||
this(string msg, string file = __FILE__, size_t line = __LINE__) {
|
this(string msg, string file = __FILE__, size_t line = __LINE__) {
|
||||||
super(msg, file, line);
|
super(msg, file, line);
|
||||||
}
|
}
|
4
source/snag/config/package.d
Normal file
4
source/snag/config/package.d
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
module snag.config;
|
||||||
|
|
||||||
|
public import snag.config.exception;
|
||||||
|
public import snag.config.config;
|
|
@ -1,6 +1,6 @@
|
||||||
module snapd.core.core;
|
module snag.core.core;
|
||||||
|
|
||||||
import snapd.config;
|
import snag.config;
|
||||||
import std.format;
|
import std.format;
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
import std.array;
|
import std.array;
|
||||||
|
@ -9,7 +9,7 @@ import std.process;
|
||||||
import std.algorithm;
|
import std.algorithm;
|
||||||
import std.string;
|
import std.string;
|
||||||
|
|
||||||
class SnapdException : Exception {
|
class SnagException : Exception {
|
||||||
this(string msg, string file = __FILE__, size_t line = __LINE__) {
|
this(string msg, string file = __FILE__, size_t line = __LINE__) {
|
||||||
super(msg, file, line);
|
super(msg, file, line);
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,11 @@ class SnapdException : Exception {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Snapd {
|
class Snag {
|
||||||
private string[] _baseCommand;
|
private string[] _baseCommand;
|
||||||
private SnapdConfig _config;
|
private SnagConfig _config;
|
||||||
|
|
||||||
this(SnapdConfig config) {
|
this(SnagConfig config) {
|
||||||
_baseCommand = format(
|
_baseCommand = format(
|
||||||
"git --git-dir=%s --work-tree=%s",
|
"git --git-dir=%s --work-tree=%s",
|
||||||
config.git, config.project
|
config.git, config.project
|
||||||
|
@ -34,7 +34,7 @@ class Snapd {
|
||||||
void initialize() {
|
void initialize() {
|
||||||
auto result = execute(_baseCommand ~ "init");
|
auto result = execute(_baseCommand ~ "init");
|
||||||
if (result.status)
|
if (result.status)
|
||||||
throw new SnapdException(
|
throw new SnagException(
|
||||||
"A Git repository initialization error occurred:\n"
|
"A Git repository initialization error occurred:\n"
|
||||||
~ result.output
|
~ result.output
|
||||||
);
|
);
|
||||||
|
@ -43,7 +43,7 @@ class Snapd {
|
||||||
_baseCommand ~ ["config", "user.email", _config.email]
|
_baseCommand ~ ["config", "user.email", _config.email]
|
||||||
);
|
);
|
||||||
if (result.status)
|
if (result.status)
|
||||||
throw new SnapdException(
|
throw new SnagException(
|
||||||
"A Git repository initialization error occurred:\n"
|
"A Git repository initialization error occurred:\n"
|
||||||
~ result.output
|
~ result.output
|
||||||
);
|
);
|
||||||
|
@ -52,7 +52,7 @@ class Snapd {
|
||||||
_baseCommand ~ ["config", "user.name", _config.user]
|
_baseCommand ~ ["config", "user.name", _config.user]
|
||||||
);
|
);
|
||||||
if (result.status)
|
if (result.status)
|
||||||
throw new SnapdException(
|
throw new SnagException(
|
||||||
"A Git repository initialization error occurred:\n"
|
"A Git repository initialization error occurred:\n"
|
||||||
~ result.output
|
~ result.output
|
||||||
);
|
);
|
||||||
|
@ -68,7 +68,7 @@ class Snapd {
|
||||||
_baseCommand ~ ["status", "--porcelain"]
|
_baseCommand ~ ["status", "--porcelain"]
|
||||||
);
|
);
|
||||||
if (result.status)
|
if (result.status)
|
||||||
throw new SnapdException(
|
throw new SnagException(
|
||||||
"An error occurred while checking the file tracking status:\n"
|
"An error occurred while checking the file tracking status:\n"
|
||||||
~ result.output
|
~ result.output
|
||||||
);
|
);
|
||||||
|
@ -90,7 +90,7 @@ class Snapd {
|
||||||
_baseCommand ~ ["add", "."]
|
_baseCommand ~ ["add", "."]
|
||||||
);
|
);
|
||||||
if (result.status)
|
if (result.status)
|
||||||
throw new SnapdException(
|
throw new SnagException(
|
||||||
"Failed to prepare files for archiving:\n"
|
"Failed to prepare files for archiving:\n"
|
||||||
~ result.output
|
~ result.output
|
||||||
);
|
);
|
||||||
|
@ -99,7 +99,7 @@ class Snapd {
|
||||||
_baseCommand ~ ["commit", "-m", "test"]
|
_baseCommand ~ ["commit", "-m", "test"]
|
||||||
);
|
);
|
||||||
if (result.status)
|
if (result.status)
|
||||||
throw new SnapdException(
|
throw new SnagException(
|
||||||
"Failed to create a backup:\n"
|
"Failed to create a backup:\n"
|
||||||
~ result.output
|
~ result.output
|
||||||
);
|
);
|
3
source/snag/core/package.d
Normal file
3
source/snag/core/package.d
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
module snag.core;
|
||||||
|
|
||||||
|
public import snag.core.core;
|
5
source/snag/package.d
Normal file
5
source/snag/package.d
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
module snag;
|
||||||
|
|
||||||
|
public import snag.version_;
|
||||||
|
public import snag.config;
|
||||||
|
public import snag.core;
|
3
source/snag/version_.d
Normal file
3
source/snag/version_.d
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
module snag.version_;
|
||||||
|
|
||||||
|
enum snagVersion = "0.0.4";
|
|
@ -1,4 +0,0 @@
|
||||||
module snapd.config;
|
|
||||||
|
|
||||||
public import snapd.config.exception;
|
|
||||||
public import snapd.config.config;
|
|
|
@ -1,3 +0,0 @@
|
||||||
module snapd.core;
|
|
||||||
|
|
||||||
public import snapd.core.core;
|
|
|
@ -1,5 +0,0 @@
|
||||||
module snapd;
|
|
||||||
|
|
||||||
public import snapd.version_;
|
|
||||||
public import snapd.config;
|
|
||||||
public import snapd.core;
|
|
|
@ -1,3 +0,0 @@
|
||||||
module snapd.version_;
|
|
||||||
|
|
||||||
enum snapdVersion = "0.0.3";
|
|
Loading…
Add table
Add a link
Reference in a new issue