added formatters to flake and formatted
This commit is contained in:
parent
9114ef63c1
commit
398ef79341
4 changed files with 288 additions and 240 deletions
67
flake.nix
67
flake.nix
|
@ -19,11 +19,13 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = flakes: let
|
outputs = flakes:
|
||||||
|
let
|
||||||
version = "1.3.0";
|
version = "1.3.0";
|
||||||
self = flakes.self.packages.x86_64-linux;
|
self = flakes.self.packages.x86_64-linux;
|
||||||
nixpkgs = flakes.nixpkgs.legacyPackages.x86_64-linux.pkgsStatic;
|
nixpkgs = flakes.nixpkgs.legacyPackages.x86_64-linux.pkgsStatic;
|
||||||
nixpkgs-dyn = flakes.nixpkgs.legacyPackages.x86_64-linux;
|
nixpkgs-dyn = flakes.nixpkgs.legacyPackages.x86_64-linux;
|
||||||
|
nixpkgs-fmt = flakes.nixpkgs-fmt.defaultPackage.x86_64-linux;
|
||||||
gourou-src = flakes.gourou-src;
|
gourou-src = flakes.gourou-src;
|
||||||
updfparser-src = flakes.updfparser-src;
|
updfparser-src = flakes.updfparser-src;
|
||||||
base64-src = flakes.base64-src;
|
base64-src = flakes.base64-src;
|
||||||
|
@ -31,7 +33,8 @@
|
||||||
cxx = "${nixpkgs.stdenv.cc}/bin/x86_64-unknown-linux-musl-g++";
|
cxx = "${nixpkgs.stdenv.cc}/bin/x86_64-unknown-linux-musl-g++";
|
||||||
ar = "${nixpkgs.stdenv.cc.bintools.bintools_bin}/bin/x86_64-unknown-linux-musl-ar";
|
ar = "${nixpkgs.stdenv.cc.bintools.bintools_bin}/bin/x86_64-unknown-linux-musl-ar";
|
||||||
obj-flags = "-O2 -static";
|
obj-flags = "-O2 -static";
|
||||||
in rec {
|
in
|
||||||
|
rec {
|
||||||
packages.x86_64-linux.libzip-static = nixpkgs.libzip.overrideAttrs (prev: {
|
packages.x86_64-linux.libzip-static = nixpkgs.libzip.overrideAttrs (prev: {
|
||||||
cmakeFlags = (prev.cmakeFlags or [ ]) ++ [
|
cmakeFlags = (prev.cmakeFlags or [ ]) ++ [
|
||||||
"-DBUILD_SHARED_LIBS=OFF"
|
"-DBUILD_SHARED_LIBS=OFF"
|
||||||
|
@ -47,31 +50,39 @@
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
builder = "${nixpkgs.bash}/bin/bash";
|
builder = "${nixpkgs.bash}/bin/bash";
|
||||||
PATH = "${nixpkgs.coreutils}/bin";
|
PATH = "${nixpkgs.coreutils}/bin";
|
||||||
args = ["-c" ''
|
args = [
|
||||||
|
"-c"
|
||||||
|
''
|
||||||
mkdir -p $out/include/base64
|
mkdir -p $out/include/base64
|
||||||
cp ${base64-src}/Base64.h $out/include/base64/Base64.h
|
cp ${base64-src}/Base64.h $out/include/base64/Base64.h
|
||||||
''];
|
''
|
||||||
|
];
|
||||||
};
|
};
|
||||||
packages.x86_64-linux.updfparser = derivation {
|
packages.x86_64-linux.updfparser = derivation {
|
||||||
name = "updfparser";
|
name = "updfparser";
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
builder = "${nixpkgs.bash}/bin/bash";
|
builder = "${nixpkgs.bash}/bin/bash";
|
||||||
PATH = "${nixpkgs.coreutils}/bin";
|
PATH = "${nixpkgs.coreutils}/bin";
|
||||||
args = [ "-c" ''
|
args = [
|
||||||
|
"-c"
|
||||||
|
''
|
||||||
${cxx} \
|
${cxx} \
|
||||||
-c ${updfparser-src}/src/*.cpp \
|
-c ${updfparser-src}/src/*.cpp \
|
||||||
-I ${updfparser-src}/include \
|
-I ${updfparser-src}/include \
|
||||||
${obj-flags}
|
${obj-flags}
|
||||||
mkdir -p $out/lib
|
mkdir -p $out/lib
|
||||||
${ar} crs $out/lib/libupdfparser.a *.o
|
${ar} crs $out/lib/libupdfparser.a *.o
|
||||||
'' ];
|
''
|
||||||
|
];
|
||||||
};
|
};
|
||||||
packages.x86_64-linux.gourou = derivation {
|
packages.x86_64-linux.gourou = derivation {
|
||||||
name = "gourou";
|
name = "gourou";
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
builder = "${nixpkgs.bash}/bin/bash";
|
builder = "${nixpkgs.bash}/bin/bash";
|
||||||
PATH = "${nixpkgs.coreutils}/bin";
|
PATH = "${nixpkgs.coreutils}/bin";
|
||||||
args = [ "-c" ''
|
args = [
|
||||||
|
"-c"
|
||||||
|
''
|
||||||
${cxx} \
|
${cxx} \
|
||||||
-c \
|
-c \
|
||||||
${gourou-src}/src/*.cpp \
|
${gourou-src}/src/*.cpp \
|
||||||
|
@ -84,14 +95,17 @@
|
||||||
mkdir -p $out/lib $out/debug
|
mkdir -p $out/lib $out/debug
|
||||||
${ar} crs $out/lib/libgourou.a *.o
|
${ar} crs $out/lib/libgourou.a *.o
|
||||||
cp *.o $out/debug
|
cp *.o $out/debug
|
||||||
'' ];
|
''
|
||||||
|
];
|
||||||
};
|
};
|
||||||
packages.x86_64-linux.utils-common = derivation {
|
packages.x86_64-linux.utils-common = derivation {
|
||||||
name = "utils-common";
|
name = "utils-common";
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
builder = "${nixpkgs.bash}/bin/bash";
|
builder = "${nixpkgs.bash}/bin/bash";
|
||||||
PATH = "${nixpkgs.coreutils}/bin";
|
PATH = "${nixpkgs.coreutils}/bin";
|
||||||
args = [ "-c" ''
|
args = [
|
||||||
|
"-c"
|
||||||
|
''
|
||||||
${cxx} \
|
${cxx} \
|
||||||
-c ${gourou-src}/utils/drmprocessorclientimpl.cpp \
|
-c ${gourou-src}/utils/drmprocessorclientimpl.cpp \
|
||||||
${gourou-src}/utils/utils_common.cpp \
|
${gourou-src}/utils/utils_common.cpp \
|
||||||
|
@ -105,14 +119,17 @@
|
||||||
${obj-flags}
|
${obj-flags}
|
||||||
mkdir -p $out/lib
|
mkdir -p $out/lib
|
||||||
${ar} crs $out/lib/libutils-common.a *.o
|
${ar} crs $out/lib/libutils-common.a *.o
|
||||||
'' ];
|
''
|
||||||
|
];
|
||||||
};
|
};
|
||||||
packages.x86_64-linux.knock = derivation {
|
packages.x86_64-linux.knock = derivation {
|
||||||
name = "knock";
|
name = "knock";
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
builder = "${nixpkgs.bash}/bin/bash";
|
builder = "${nixpkgs.bash}/bin/bash";
|
||||||
PATH = "${nixpkgs.coreutils}/bin";
|
PATH = "${nixpkgs.coreutils}/bin";
|
||||||
args = [ "-c" ''
|
args = [
|
||||||
|
"-c"
|
||||||
|
''
|
||||||
mkdir -p $out/bin
|
mkdir -p $out/bin
|
||||||
${cxx} \
|
${cxx} \
|
||||||
-o $out/bin/knock \
|
-o $out/bin/knock \
|
||||||
|
@ -142,16 +159,19 @@
|
||||||
-I ${nixpkgs.curl.dev}/include \
|
-I ${nixpkgs.curl.dev}/include \
|
||||||
-I ${nixpkgs.zlib.dev}/include \
|
-I ${nixpkgs.zlib.dev}/include \
|
||||||
-I ${self.libzip-static}/include
|
-I ${self.libzip-static}/include
|
||||||
'' ];
|
''
|
||||||
|
];
|
||||||
};
|
};
|
||||||
packages.x86_64-linux.default = self.knock;
|
packages.x86_64-linux.default = self.knock;
|
||||||
packages.x86_64-linux.tests = nixpkgs-dyn.stdenv.mkDerivation {
|
packages.x86_64-linux.tests = nixpkgs-dyn.stdenv.mkDerivation {
|
||||||
name = "tests";
|
name = "tests";
|
||||||
src = ./tests;
|
src = ./tests;
|
||||||
buildInputs = [ (nixpkgs-dyn.python3.withPackages(p: [
|
buildInputs = [
|
||||||
|
(nixpkgs-dyn.python3.withPackages (p: [
|
||||||
p.beautifulsoup4
|
p.beautifulsoup4
|
||||||
p.requests
|
p.requests
|
||||||
])) ];
|
]))
|
||||||
|
];
|
||||||
patchPhase = ''
|
patchPhase = ''
|
||||||
substituteInPlace tests.py --replace "./result/bin/knock" "${self.knock}/bin/knock"
|
substituteInPlace tests.py --replace "./result/bin/knock" "${self.knock}/bin/knock"
|
||||||
'';
|
'';
|
||||||
|
@ -161,5 +181,24 @@
|
||||||
chmod +x $out/bin/tests
|
chmod +x $out/bin/tests
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
devShell.x86_64-linux = nixpkgs.mkShell {
|
||||||
|
packages = [
|
||||||
|
# nix formatter
|
||||||
|
nixpkgs-dyn.nixpkgs-fmt
|
||||||
|
# python formatter
|
||||||
|
nixpkgs-dyn.black
|
||||||
|
# cpp formatter
|
||||||
|
nixpkgs-dyn.clang-tools
|
||||||
|
];
|
||||||
|
shellHook = ''
|
||||||
|
fmt () {
|
||||||
|
set -ex
|
||||||
|
nixpkgs-fmt .
|
||||||
|
black ./tests
|
||||||
|
clang-format -i --verbose src/*.cpp
|
||||||
|
set +ex
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -44,6 +44,14 @@ nix run .#tests -- ./tests/workspace
|
||||||
|
|
||||||
Test books can be found [here](https://www.adobe.com/solutions/ebook/digital-editions/sample-ebook-library.html).
|
Test books can be found [here](https://www.adobe.com/solutions/ebook/digital-editions/sample-ebook-library.html).
|
||||||
|
|
||||||
|
### Formatting
|
||||||
|
|
||||||
|
```
|
||||||
|
nix develop
|
||||||
|
fmt
|
||||||
|
exit
|
||||||
|
```
|
||||||
|
|
||||||
## The Name
|
## The Name
|
||||||
|
|
||||||
The name comes from the [D&D 5e spell](https://roll20.net/compendium/dnd5e/Knock#content) for freeing locked items:
|
The name comes from the [D&D 5e spell](https://roll20.net/compendium/dnd5e/Knock#content) for freeing locked items:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include <filesystem>
|
|
||||||
#include "drmprocessorclientimpl.h"
|
#include "drmprocessorclientimpl.h"
|
||||||
#include "libgourou_common.h"
|
|
||||||
#include "libgourou.h"
|
#include "libgourou.h"
|
||||||
|
#include "libgourou_common.h"
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
#ifndef KNOCK_VERSION
|
#ifndef KNOCK_VERSION
|
||||||
#error KNOCK_VERSION must be defined
|
#error KNOCK_VERSION must be defined
|
||||||
|
@ -14,11 +14,11 @@ void verify_presence(std::string file);
|
||||||
int main(int argc, char **argv) try {
|
int main(int argc, char **argv) try {
|
||||||
|
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
std::cout
|
std::cout << "info: knock version " << KNOCK_VERSION
|
||||||
<< "info: knock version " << KNOCK_VERSION << ", libgourou version "
|
<< ", libgourou version " << LIBGOUROU_VERSION << "\n"
|
||||||
<< LIBGOUROU_VERSION << "\n"
|
<< "usage: " << argv[0] << " [ACSM]\n"
|
||||||
<< "usage: " << argv[0] << " [ACSM]" << "\n"
|
<< "result: converts file ACSM to a plain EPUB/PDF if present, "
|
||||||
<< "result: converts file ACSM to a plain EPUB/PDF if present, otherwise prints this"
|
"otherwise prints this"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,8 @@ int main(int argc, char** argv) try {
|
||||||
|
|
||||||
const std::string acsm_file = argv[1];
|
const std::string acsm_file = argv[1];
|
||||||
verify_presence(acsm_file);
|
verify_presence(acsm_file);
|
||||||
const std::string acsm_stem = acsm_file.substr(0, acsm_file.find_last_of("."));
|
const std::string acsm_stem =
|
||||||
|
acsm_file.substr(0, acsm_file.find_last_of("."));
|
||||||
const std::string drm_file = acsm_stem + ".drm";
|
const std::string drm_file = acsm_stem + ".drm";
|
||||||
const std::string out_file = acsm_stem + ".out";
|
const std::string out_file = acsm_stem + ".out";
|
||||||
verify_absence(drm_file);
|
verify_absence(drm_file);
|
||||||
|
@ -40,8 +41,7 @@ int main(int argc, char** argv) try {
|
||||||
gourou::DRMProcessor *processor = gourou::DRMProcessor::createDRMProcessor(
|
gourou::DRMProcessor *processor = gourou::DRMProcessor::createDRMProcessor(
|
||||||
&client,
|
&client,
|
||||||
false, // don't "always generate a new device" (default)
|
false, // don't "always generate a new device" (default)
|
||||||
knock_data
|
knock_data);
|
||||||
);
|
|
||||||
|
|
||||||
std::cout << "anonymously signing in..." << std::endl;
|
std::cout << "anonymously signing in..." << std::endl;
|
||||||
processor->signIn("anonymous", "");
|
processor->signIn("anonymous", "");
|
||||||
|
@ -74,8 +74,8 @@ int main(int argc, char** argv) try {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (std::filesystem::exists(ext_file)) {
|
if (std::filesystem::exists(ext_file)) {
|
||||||
std::cerr
|
std::cerr << "warning: failed to update file extension; " + ext_file +
|
||||||
<< "warning: failed to update file extension; " + ext_file + " already exists"
|
" already exists"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
ext_file = out_file;
|
ext_file = out_file;
|
||||||
} else {
|
} else {
|
||||||
|
@ -108,7 +108,8 @@ std::string get_data_dir() {
|
||||||
|
|
||||||
void verify_absence(std::string file) {
|
void verify_absence(std::string file) {
|
||||||
if (std::filesystem::exists(file)) {
|
if (std::filesystem::exists(file)) {
|
||||||
throw std::runtime_error("file " + file + " must be moved out of the way or deleted");
|
throw std::runtime_error("file " + file +
|
||||||
|
" must be moved out of the way or deleted");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ if not knock.exists():
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 2:
|
||||||
print(
|
print(
|
||||||
"error: missing required argument: directory in which to perform the tests",
|
"error: missing required argument: directory in which to perform the tests",
|
||||||
file=sys.stderr
|
file=sys.stderr,
|
||||||
)
|
)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
@ -31,13 +31,13 @@ if workspace.exists():
|
||||||
shutil.rmtree(workspace)
|
shutil.rmtree(workspace)
|
||||||
workspace.mkdir()
|
workspace.mkdir()
|
||||||
|
|
||||||
html = requests \
|
html = requests.get(
|
||||||
.get("https://www.adobe.com/solutions/ebook/digital-editions/sample-ebook-library.html") \
|
"https://www.adobe.com/solutions/ebook/digital-editions/sample-ebook-library.html"
|
||||||
.text
|
).text
|
||||||
soup = BeautifulSoup(html, 'html.parser')
|
soup = BeautifulSoup(html, "html.parser")
|
||||||
|
|
||||||
links = []
|
links = []
|
||||||
for a_tag in soup.find_all('a'):
|
for a_tag in soup.find_all("a"):
|
||||||
if a_tag.string != "Download eBook":
|
if a_tag.string != "Download eBook":
|
||||||
continue
|
continue
|
||||||
if not urlparse(a_tag.get("href")).path.endswith(".acsm"):
|
if not urlparse(a_tag.get("href")).path.endswith(".acsm"):
|
||||||
|
|
Loading…
Reference in a new issue