mirror of
https://github.com/tcsenpai/qrare.git
synced 2025-06-07 03:35:26 +00:00
update packaged version
This commit is contained in:
parent
24db27aa21
commit
6ac178ff35
33
.gitignore
vendored
33
.gitignore
vendored
@ -1,4 +1,35 @@
|
|||||||
|
# QR code output files
|
||||||
qr_code_*.png
|
qr_code_*.png
|
||||||
qr_codes/
|
qr_codes/
|
||||||
__pycache__/
|
|
||||||
output_test_file.txt
|
output_test_file.txt
|
||||||
|
|
||||||
|
# Python package build artifacts
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
*.egg-info/
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
.eggs/
|
||||||
|
|
||||||
|
# Virtual environments
|
||||||
|
venv/
|
||||||
|
env/
|
||||||
|
ENV/
|
||||||
|
.venv/
|
||||||
|
.env/
|
||||||
|
|
||||||
|
# Development and testing
|
||||||
|
.pytest_cache/
|
||||||
|
.coverage
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
|
||||||
|
# IDE files
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
mise.toml
|
3
MANIFEST.in
Normal file
3
MANIFEST.in
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
include README.md
|
||||||
|
include LICENSE
|
||||||
|
include requirements.txt
|
7
binary_qr_converter/__init__.py
Normal file
7
binary_qr_converter/__init__.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
"""
|
||||||
|
Binary QR Converter - A utility to convert binary files to QR codes and back.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from binary_qr_converter.converter import BinaryQRConverter
|
||||||
|
|
||||||
|
__version__ = '0.1.0'
|
@ -9,68 +9,79 @@ import sys
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from converter import BinaryQRConverter
|
from binary_qr_converter.converter import BinaryQRConverter
|
||||||
|
|
||||||
__version__ = '0.1.0'
|
__version__ = "0.1.0"
|
||||||
|
|
||||||
# Configure logging
|
# Configure logging
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO,
|
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
||||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
||||||
)
|
)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
"""Parse command line arguments."""
|
"""Parse command line arguments."""
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="Convert binary files to QR codes and back",
|
description="Convert binary files to QR codes and back",
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||||
)
|
)
|
||||||
|
|
||||||
subparsers = parser.add_subparsers(dest="command", help="Command to execute")
|
subparsers = parser.add_subparsers(dest="command", help="Command to execute")
|
||||||
|
|
||||||
# Encode command
|
# Encode command
|
||||||
encode_parser = subparsers.add_parser("encode", help="Encode a binary file to QR codes")
|
encode_parser = subparsers.add_parser(
|
||||||
encode_parser.add_argument("file", type=str, help="Path to the binary file to encode")
|
"encode", help="Encode a binary file to QR codes"
|
||||||
|
)
|
||||||
encode_parser.add_argument(
|
encode_parser.add_argument(
|
||||||
"-o", "--output-dir",
|
"file", type=str, help="Path to the binary file to encode"
|
||||||
|
)
|
||||||
|
encode_parser.add_argument(
|
||||||
|
"-o",
|
||||||
|
"--output-dir",
|
||||||
type=str,
|
type=str,
|
||||||
default="./qrcodes",
|
default="./qrcodes",
|
||||||
help="Directory to save QR code images"
|
help="Directory to save QR code images",
|
||||||
)
|
)
|
||||||
encode_parser.add_argument(
|
encode_parser.add_argument(
|
||||||
"-c", "--chunk-size",
|
"-c",
|
||||||
|
"--chunk-size",
|
||||||
type=int,
|
type=int,
|
||||||
default=1024,
|
default=1024,
|
||||||
help="Size of binary chunks in bytes"
|
help="Size of binary chunks in bytes",
|
||||||
)
|
)
|
||||||
encode_parser.add_argument(
|
encode_parser.add_argument(
|
||||||
"-v", "--qr-version",
|
"-v",
|
||||||
|
"--qr-version",
|
||||||
type=int,
|
type=int,
|
||||||
default=40,
|
default=40,
|
||||||
choices=range(1, 41),
|
choices=range(1, 41),
|
||||||
help="QR code version (1-40, higher means more capacity)"
|
help="QR code version (1-40, higher means more capacity)",
|
||||||
)
|
)
|
||||||
encode_parser.add_argument(
|
encode_parser.add_argument(
|
||||||
"-z", "--compression-level",
|
"-z",
|
||||||
|
"--compression-level",
|
||||||
type=int,
|
type=int,
|
||||||
default=9,
|
default=9,
|
||||||
help="Zlib compression level (0-9)"
|
help="Zlib compression level (0-9)",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Decode command
|
# Decode command
|
||||||
decode_parser = subparsers.add_parser("decode", help="Decode QR codes back to a binary file")
|
decode_parser = subparsers.add_parser(
|
||||||
|
"decode", help="Decode QR codes back to a binary file"
|
||||||
|
)
|
||||||
decode_parser.add_argument(
|
decode_parser.add_argument(
|
||||||
"images",
|
"images",
|
||||||
type=str,
|
type=str,
|
||||||
nargs="+",
|
nargs="+",
|
||||||
help="Paths to QR code images or directory containing QR code images"
|
help="Paths to QR code images or directory containing QR code images",
|
||||||
)
|
)
|
||||||
decode_parser.add_argument(
|
decode_parser.add_argument(
|
||||||
"-o", "--output-dir",
|
"-o",
|
||||||
|
"--output-dir",
|
||||||
type=str,
|
type=str,
|
||||||
default="./output",
|
default="./output",
|
||||||
help="Directory to save the reconstructed file"
|
help="Directory to save the reconstructed file",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Version command
|
# Version command
|
||||||
@ -78,6 +89,7 @@ def parse_args():
|
|||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def get_image_paths(image_args: List[str]) -> List[Path]:
|
def get_image_paths(image_args: List[str]) -> List[Path]:
|
||||||
"""
|
"""
|
||||||
Get a list of image paths from command line arguments.
|
Get a list of image paths from command line arguments.
|
||||||
@ -107,6 +119,7 @@ def get_image_paths(image_args: List[str]) -> List[Path]:
|
|||||||
|
|
||||||
return image_paths
|
return image_paths
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main entry point for the command-line interface."""
|
"""Main entry point for the command-line interface."""
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
@ -126,7 +139,7 @@ def main():
|
|||||||
converter = BinaryQRConverter(
|
converter = BinaryQRConverter(
|
||||||
chunk_size=args.chunk_size,
|
chunk_size=args.chunk_size,
|
||||||
qr_version=args.qr_version,
|
qr_version=args.qr_version,
|
||||||
compression_level=args.compression_level
|
compression_level=args.compression_level,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -165,5 +178,6 @@ def main():
|
|||||||
logger.error("No command specified. Use --help for usage information.")
|
logger.error("No command specified. Use --help for usage information.")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(main())
|
sys.exit(main())
|
@ -7,7 +7,8 @@ import os
|
|||||||
import tempfile
|
import tempfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from converter import BinaryQRConverter
|
from binary_qr_converter.converter import BinaryQRConverter
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Run an example of encoding and decoding a binary file."""
|
"""Run an example of encoding and decoding a binary file."""
|
||||||
@ -17,7 +18,7 @@ def main():
|
|||||||
|
|
||||||
# Create a test binary file
|
# Create a test binary file
|
||||||
test_file_path = temp_dir_path / "test_file.bin"
|
test_file_path = temp_dir_path / "test_file.bin"
|
||||||
with open(test_file_path, 'wb') as f:
|
with open(test_file_path, "wb") as f:
|
||||||
f.write(os.urandom(1000000)) # 1MB of random data
|
f.write(os.urandom(1000000)) # 1MB of random data
|
||||||
|
|
||||||
print(f"Created test file: {test_file_path}")
|
print(f"Created test file: {test_file_path}")
|
||||||
@ -39,22 +40,27 @@ def main():
|
|||||||
|
|
||||||
# Decode the QR codes back to a file
|
# Decode the QR codes back to a file
|
||||||
print("\nDecoding QR codes back to file...")
|
print("\nDecoding QR codes back to file...")
|
||||||
decoded_file_path = converter.decode_qr_images(qr_image_paths, decode_output_dir)
|
decoded_file_path = converter.decode_qr_images(
|
||||||
|
qr_image_paths, decode_output_dir
|
||||||
|
)
|
||||||
|
|
||||||
if decoded_file_path:
|
if decoded_file_path:
|
||||||
print(f"Successfully decoded to: {decoded_file_path}")
|
print(f"Successfully decoded to: {decoded_file_path}")
|
||||||
|
|
||||||
# Verify the decoded file matches the original
|
# Verify the decoded file matches the original
|
||||||
with open(test_file_path, 'rb') as f1, open(decoded_file_path, 'rb') as f2:
|
with open(test_file_path, "rb") as f1, open(decoded_file_path, "rb") as f2:
|
||||||
original_data = f1.read()
|
original_data = f1.read()
|
||||||
decoded_data = f2.read()
|
decoded_data = f2.read()
|
||||||
|
|
||||||
if original_data == decoded_data:
|
if original_data == decoded_data:
|
||||||
print("Verification successful: Decoded file matches the original!")
|
print("Verification successful: Decoded file matches the original!")
|
||||||
else:
|
else:
|
||||||
print("Verification failed: Decoded file does not match the original.")
|
print(
|
||||||
|
"Verification failed: Decoded file does not match the original."
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
print("Decoding failed.")
|
print("Decoding failed.")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
32
setup.py
Normal file
32
setup.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
|
with open("README.md", "r", encoding="utf-8") as fh:
|
||||||
|
long_description = fh.read()
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name="binary-qr-converter",
|
||||||
|
version="0.1.0",
|
||||||
|
author="Your Name",
|
||||||
|
author_email="your.email@example.com",
|
||||||
|
description="Convert binary files to QR codes and back",
|
||||||
|
long_description=long_description,
|
||||||
|
long_description_content_type="text/markdown",
|
||||||
|
url="https://github.com/yourusername/binary-qr-converter",
|
||||||
|
packages=find_packages(),
|
||||||
|
classifiers=[
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"License :: OSI Approved :: MIT License",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
],
|
||||||
|
python_requires=">=3.6",
|
||||||
|
install_requires=[
|
||||||
|
"qrcode>=7.0",
|
||||||
|
"pillow>=8.0.0",
|
||||||
|
"pyzbar>=0.1.8",
|
||||||
|
],
|
||||||
|
entry_points={
|
||||||
|
"console_scripts": [
|
||||||
|
"binary-qr=binary_qr_converter.binary_qr:main",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user