Skip to content

Commit d8a9274

Browse files
committed
Inital commit.
0 parents  commit d8a9274

26 files changed

+540
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist/
2+
node_modules/
3+
vcpkg_installed/
4+
build/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "vcpkg"]
2+
path = vcpkg
3+
url = https://github.com/microsoft/vcpkg

CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file")
4+
5+
project(python-filerix VERSION 1.1.1 LANGUAGES CXX)
6+
7+
set(CMAKE_CXX_STANDARD 17)
8+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
10+
include(GNUInstallDirs)
11+
12+
include_directories(${CMAKE_SOURCE_DIR}/include)
13+
14+
find_package(filerix CONFIG REQUIRED)
15+
find_package(pybind11 CONFIG REQUIRED)
16+
17+
pybind11_add_module(python_filerix src/pybind11.cc)
18+
19+
set_target_properties(python_filerix PROPERTIES OUTPUT_NAME "filerix")
20+
21+
target_link_libraries(python_filerix PRIVATE
22+
filerix::filerix
23+
)
24+
25+
install(TARGETS python_filerix
26+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages
27+
)

Makefile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
VCPKG_REPO = https://github.com/microsoft/vcpkg.git
2+
PREFIX ?= /usr/local
3+
4+
all: install
5+
6+
install: build
7+
@echo "Installing node-filerix..."
8+
cmake --install build --prefix=$(PREFIX) || { echo "Installation failed"; exit 1; }
9+
@echo "Installation complete!"
10+
11+
build: check-vcpkg setup-vcpkg-port
12+
@echo "Bootstrapping vcpkg..."
13+
./vcpkg/bootstrap-vcpkg.sh || { echo "Failed to bootstrap vcpkg"; exit 1; }
14+
@echo "Installing dependencies with vcpkg..."
15+
./vcpkg/vcpkg --feature-flags=manifests install --triplet x64-linux-release || { echo "Failed to install dependencies"; exit 1; }
16+
@echo "Generating build files with CMake..."
17+
mkdir -p build && cd build && cmake .. || { echo "Failed to generate CMake build files"; exit 1; }
18+
@echo "Building the project..."
19+
cmake --build build --parallel || { echo "Build failed"; exit 1; }
20+
@echo "Build complete!"
21+
22+
setup-vcpkg-port:
23+
@if [ ! -d "./vcpkg/ports/filerix" ]; then \
24+
echo "Downloading filerix vcpkg port..."; \
25+
git clone --recurse-submodules https://github.com/filesverse/vcpkg-port.git vcpkg-port || { echo "Failed to download filerix vcpkg port"; exit 1; }; \
26+
echo "Copying filerix vcpkg port..."; \
27+
mv ./vcpkg-port ./vcpkg/ports/filerix || { echo "Failed to copy filerix vcpkg port"; exit 1; }; \
28+
fi
29+
30+
check-vcpkg:
31+
@if [ ! -d "./vcpkg" ] || [ -z "$$(ls -A ./vcpkg 2>/dev/null)" ]; then \
32+
echo "vcpkg is missing or empty. Cloning vcpkg..."; \
33+
git clone $(VCPKG_REPO) vcpkg || { echo "Failed to clone vcpkg"; exit 1; }; \
34+
fi
35+
36+
uninstall:
37+
@echo "Removing installed files..."
38+
rm -f $(PREFIX)/lib64/node_modules/filerix/filerix.node
39+
@echo "Uninstallation complete!"
40+
41+
clean:
42+
@echo "Cleaning build directory..."
43+
rm -rf build vcpkg_installed vcpkg-port
44+
@echo "Clean complete!"
45+
46+
.PHONY: all install build uninstall clean

include/FileSystem/DriveUtils.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef FILERIX_DRIVE_UTILS_HPP
2+
#define FILERIX_DRIVE_UTILS_HPP
3+
4+
#include <pybind11/pybind11.h>
5+
#include <pybind11/stl.h>
6+
#include "filerix/FileSystem/DriveUtils.h"
7+
8+
namespace py = pybind11;
9+
10+
inline void init_drive_utils(py::module_ &m)
11+
{
12+
py::module driveUtils = m.def_submodule("driveUtils", "Drive utilities module");
13+
14+
py::class_<DriveUtils::DriveUsage>(driveUtils, "DriveUsage")
15+
.def_readonly("used", &DriveUtils::DriveUsage::used)
16+
.def_readonly("total", &DriveUtils::DriveUsage::total);
17+
18+
py::class_<DriveUtils::DriveInfo>(driveUtils, "DriveInfo")
19+
.def_readonly("device", &DriveUtils::DriveInfo::device)
20+
.def_readonly("status", &DriveUtils::DriveInfo::status)
21+
.def_readonly("unmountable", &DriveUtils::DriveInfo::unmountable)
22+
.def_readonly("mountPoint", &DriveUtils::DriveInfo::mountPoint)
23+
.def_readonly("partition", &DriveUtils::DriveInfo::partition)
24+
.def_readonly("fsType", &DriveUtils::DriveInfo::fsType);
25+
26+
driveUtils.def("getDrives", &DriveUtils::GetDrives, "Retrieve a list of drives");
27+
driveUtils.def("getDriveUsage", &DriveUtils::GetDriveUsage, "Retrieve usage stats for a drive");
28+
driveUtils.def("getDeviceLabelOrUuid", &DriveUtils::GetDeviceLabelOrUUID, "Get device label or UUID");
29+
driveUtils.def("mountDrive", &DriveUtils::MountDrive, "Mount a drive");
30+
driveUtils.def("unmountDrive", &DriveUtils::UnmountDrive, "Unmount a drive");
31+
}
32+
33+
#endif

include/FileSystem/FileUtils.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef FILERIX_FILE_UTILS_HPP
2+
#define FILERIX_FILE_UTILS_HPP
3+
4+
#include <pybind11/pybind11.h>
5+
#include <pybind11/stl.h>
6+
#include "filerix/FileSystem/FileUtils.h"
7+
#include "filerix/FileSystem/FileInfo.h"
8+
9+
namespace py = pybind11;
10+
11+
inline void init_file_utils(py::module_ &m)
12+
{
13+
py::module fileUtils = m.def_submodule("fileUtils", "File utilities module");
14+
15+
py::class_<FileInfo>(fileUtils, "FileInfo")
16+
.def_readonly("name", &FileInfo::name)
17+
.def_readonly("type", &FileInfo::type)
18+
.def_readonly("path", &FileInfo::path)
19+
.def_readonly("size", &FileInfo::size)
20+
.def_readonly("isDirectory", &FileInfo::isDirectory);
21+
22+
py::class_<FileList>(fileUtils, "FileList")
23+
.def_readonly("files", &FileList::files)
24+
.def_readonly("count", &FileList::count);
25+
26+
fileUtils.def("copy", &FileUtils::Copy, "Copy a file from source to destination");
27+
fileUtils.def("cut", &FileUtils::Cut, "Cut a file from source to destination");
28+
fileUtils.def("rename", &FileUtils::Rename, "Rename a file");
29+
fileUtils.def("moveTo", &FileUtils::MoveTo, "Move a file to a new location");
30+
fileUtils.def("compress", &FileUtils::Compress, "Compress a file");
31+
fileUtils.def("decompress", &FileUtils::Decompress, "Decompress a file");
32+
33+
fileUtils.def("getFiles", &FileUtils::GetFiles, "Get list of files in a directory");
34+
fileUtils.def("searchFiles", &FileUtils::SearchFiles, "Search for files in a directory");
35+
}
36+
37+
#endif

include/FileSystem/UserUtils.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef FILERIX_USER_UTILS_HPP
2+
#define FILERIX_USER_UTILS_HPP
3+
4+
#include <pybind11/pybind11.h>
5+
#include "filerix/FileSystem/UserUtils.h"
6+
7+
namespace py = pybind11;
8+
9+
inline void init_user_utils(py::module_ &m)
10+
{
11+
py::module userUtils = m.def_submodule("userUtils", "User utilities module");
12+
13+
userUtils.def("getUserName", []()
14+
{ return std::string(UserUtils::GetUserName()); }, "Retrieve the current username");
15+
16+
userUtils.def("changePermissions", &UserUtils::ChangePermissions,
17+
"Change file permissions for a given path");
18+
}
19+
20+
#endif
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef FILERIX_DRIVE_LISTENER_HPP
2+
#define FILERIX_DRIVE_LISTENER_HPP
3+
4+
#include <pybind11/pybind11.h>
5+
#include <pybind11/functional.h>
6+
#include "filerix/Listeners/DriveListener.h"
7+
8+
namespace py = pybind11;
9+
10+
inline void init_drive_listener(py::module_ &m)
11+
{
12+
py::module driveListener = m.def_submodule("driveListener", "Drive event monitoring module");
13+
14+
py::class_<DriveListener::DriveMonitor>(driveListener, "DriveMonitor")
15+
.def(py::init<>())
16+
.def("start", &DriveListener::DriveMonitor::Start, py::arg("callback"),
17+
"Start monitoring drive events with a callback function")
18+
.def("stop", &DriveListener::DriveMonitor::Stop,
19+
"Stop monitoring drive events");
20+
}
21+
22+
#endif

include/Listeners/FileListener.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef FILERIX_FILE_LISTENER_HPP
2+
#define FILERIX_FILE_LISTENER_HPP
3+
4+
#include <pybind11/pybind11.h>
5+
#include <pybind11/functional.h>
6+
#include "filerix/Listeners/FileListener.h"
7+
8+
namespace py = pybind11;
9+
10+
inline void init_file_listener(py::module_ &m)
11+
{
12+
py::module fileListener = m.def_submodule("fileListener", "File event monitoring module");
13+
14+
py::class_<FileListener::FileMonitor>(fileListener, "FileMonitor")
15+
.def(py::init<const std::string &>(), py::arg("directory"),
16+
"Initialize the file monitor for a specific directory")
17+
.def("start", &FileListener::FileMonitor::Start, py::arg("callback"),
18+
"Start monitoring file events with a callback function")
19+
.def("stop", &FileListener::FileMonitor::Stop,
20+
"Stop monitoring file events");
21+
}
22+
23+
#endif

src/pybind11.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <pybind11/pybind11.h>
2+
#include "FileSystem/DriveUtils.hpp"
3+
#include "FileSystem/FileUtils.hpp"
4+
#include "FileSystem/UserUtils.hpp"
5+
#include "Listeners/DriveListener.hpp"
6+
#include "Listeners/FileListener.hpp"
7+
8+
PYBIND11_MODULE(filerix, m)
9+
{
10+
m.doc() = "Python bindings for Filerix";
11+
init_drive_utils(m);
12+
init_file_utils(m);
13+
init_user_utils(m);
14+
init_drive_listener(m);
15+
init_file_listener(m);
16+
}

0 commit comments

Comments
 (0)