mirror of
https://github.com/tcsenpai/qrare.git
synced 2025-06-04 18:30:12 +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_codes/
|
||||
__pycache__/
|
||||
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 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
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def parse_args():
|
||||
"""Parse command line arguments."""
|
||||
parser = argparse.ArgumentParser(
|
||||
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")
|
||||
|
||||
# Encode command
|
||||
encode_parser = subparsers.add_parser("encode", help="Encode a binary file to QR codes")
|
||||
encode_parser.add_argument("file", type=str, help="Path to the binary file to encode")
|
||||
encode_parser = subparsers.add_parser(
|
||||
"encode", help="Encode a binary file to QR codes"
|
||||
)
|
||||
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,
|
||||
default="./qrcodes",
|
||||
help="Directory to save QR code images"
|
||||
help="Directory to save QR code images",
|
||||
)
|
||||
encode_parser.add_argument(
|
||||
"-c", "--chunk-size",
|
||||
"-c",
|
||||
"--chunk-size",
|
||||
type=int,
|
||||
default=1024,
|
||||
help="Size of binary chunks in bytes"
|
||||
help="Size of binary chunks in bytes",
|
||||
)
|
||||
encode_parser.add_argument(
|
||||
"-v", "--qr-version",
|
||||
"-v",
|
||||
"--qr-version",
|
||||
type=int,
|
||||
default=40,
|
||||
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(
|
||||
"-z", "--compression-level",
|
||||
"-z",
|
||||
"--compression-level",
|
||||
type=int,
|
||||
default=9,
|
||||
help="Zlib compression level (0-9)"
|
||||
help="Zlib compression level (0-9)",
|
||||
)
|
||||
|
||||
# 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(
|
||||
"images",
|
||||
type=str,
|
||||
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(
|
||||
"-o", "--output-dir",
|
||||
"-o",
|
||||
"--output-dir",
|
||||
type=str,
|
||||
default="./output",
|
||||
help="Directory to save the reconstructed file"
|
||||
help="Directory to save the reconstructed file",
|
||||
)
|
||||
|
||||
# Version command
|
||||
@ -78,6 +89,7 @@ def parse_args():
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def get_image_paths(image_args: List[str]) -> List[Path]:
|
||||
"""
|
||||
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
|
||||
|
||||
|
||||
def main():
|
||||
"""Main entry point for the command-line interface."""
|
||||
args = parse_args()
|
||||
@ -126,7 +139,7 @@ def main():
|
||||
converter = BinaryQRConverter(
|
||||
chunk_size=args.chunk_size,
|
||||
qr_version=args.qr_version,
|
||||
compression_level=args.compression_level
|
||||
compression_level=args.compression_level,
|
||||
)
|
||||
|
||||
try:
|
||||
@ -165,5 +178,6 @@ def main():
|
||||
logger.error("No command specified. Use --help for usage information.")
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
@ -7,7 +7,8 @@ import os
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from converter import BinaryQRConverter
|
||||
from binary_qr_converter.converter import BinaryQRConverter
|
||||
|
||||
|
||||
def main():
|
||||
"""Run an example of encoding and decoding a binary file."""
|
||||
@ -17,7 +18,7 @@ def main():
|
||||
|
||||
# Create a test binary file
|
||||
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
|
||||
|
||||
print(f"Created test file: {test_file_path}")
|
||||
@ -39,22 +40,27 @@ def main():
|
||||
|
||||
# Decode the QR codes back to a 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:
|
||||
print(f"Successfully decoded to: {decoded_file_path}")
|
||||
|
||||
# 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()
|
||||
decoded_data = f2.read()
|
||||
|
||||
if original_data == decoded_data:
|
||||
print("Verification successful: Decoded file matches the original!")
|
||||
else:
|
||||
print("Verification failed: Decoded file does not match the original.")
|
||||
print(
|
||||
"Verification failed: Decoded file does not match the original."
|
||||
)
|
||||
else:
|
||||
print("Decoding failed.")
|
||||
|
||||
|
||||
if __name__ == "__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