Updated to print service power shell
This commit is contained in:
@@ -1061,6 +1061,153 @@ For support, contact your system administrator.
|
||||
'error': str(e)
|
||||
}), 500
|
||||
|
||||
@bp.route('/create_service_package', methods=['POST'])
|
||||
def create_service_package():
|
||||
"""Create and serve ZIP package of Windows Print Service"""
|
||||
import os
|
||||
import zipfile
|
||||
from flask import current_app, jsonify
|
||||
|
||||
try:
|
||||
# Path to the windows_print_service directory
|
||||
service_dir = os.path.join(os.path.dirname(os.path.dirname(current_app.root_path)), 'windows_print_service')
|
||||
print(f"Looking for service files in: {service_dir}")
|
||||
|
||||
if not os.path.exists(service_dir):
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': f'Windows service directory not found: {service_dir}'
|
||||
}), 500
|
||||
|
||||
# Create static directory if it doesn't exist
|
||||
static_dir = os.path.join(current_app.root_path, 'static')
|
||||
os.makedirs(static_dir, exist_ok=True)
|
||||
|
||||
zip_filename = 'quality_recticel_print_service.zip'
|
||||
zip_path = os.path.join(static_dir, zip_filename)
|
||||
|
||||
# Create ZIP file with Windows service package
|
||||
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
||||
files_added = 0
|
||||
|
||||
# Add all service files to ZIP (prioritize native PowerShell solution)
|
||||
for root, dirs, files in os.walk(service_dir):
|
||||
for file in files:
|
||||
# Include all relevant files, with focus on native PowerShell solution
|
||||
if file.endswith(('.ps1', '.bat', '.md', '.json', '.js', '.html', '.css', '.png', '.txt')):
|
||||
file_path = os.path.join(root, file)
|
||||
# Create relative path for archive
|
||||
arcname = os.path.relpath(file_path, service_dir)
|
||||
|
||||
# Skip Python files in favor of PowerShell native solution
|
||||
if file.endswith('.py') and not file.startswith('print_service'):
|
||||
print(f"Skipping Python file (using native solution): {file_path}")
|
||||
continue
|
||||
|
||||
print(f"Adding service file: {file_path} as {arcname}")
|
||||
zipf.write(file_path, arcname)
|
||||
files_added += 1
|
||||
|
||||
# Add installation instructions for native PowerShell solution
|
||||
installation_readme = """# Quality Recticel Windows Print Service - Native Edition
|
||||
|
||||
## INSTALLATION INSTRUCTIONS (Native PowerShell - Zero Dependencies!)
|
||||
|
||||
### Prerequisites:
|
||||
- Windows 10/11 or Windows Server 2016+
|
||||
- Administrator privileges
|
||||
- Google Chrome browser
|
||||
- PowerShell (included with Windows)
|
||||
|
||||
### Quick Installation (Under 3 Minutes):
|
||||
|
||||
1. **Extract Files**: Extract this ZIP to any temporary location
|
||||
✅ No permanent installation directory needed - files are copied during installation
|
||||
|
||||
2. **Install Native Service**: Right-click on 'install_native_service.bat' and select "Run as administrator"
|
||||
✅ Pure PowerShell implementation - no Python or external dependencies required
|
||||
|
||||
3. **Install Chrome Extension**:
|
||||
- Open Chrome → chrome://extensions/
|
||||
- Enable "Developer mode"
|
||||
- Click "Load unpacked" → Select the 'chrome_extension' folder
|
||||
|
||||
4. **Verify Installation**: Visit http://localhost:8765/health in your browser
|
||||
Expected response: {"status": "healthy", "platform": "Windows PowerShell"}
|
||||
|
||||
### What Gets Installed:
|
||||
- ✅ Native Windows Print Service (PowerShell-based, zero dependencies)
|
||||
- ✅ Auto-start service configuration
|
||||
- ✅ Service recovery options (automatic restart)
|
||||
- ✅ Comprehensive logging system
|
||||
|
||||
### Files Included:
|
||||
- 🔧 install_native_service.bat - Native PowerShell installer (RUN AS ADMIN)
|
||||
- 🖥️ print_service.ps1 - Main PowerShell service (native Windows)
|
||||
- 🗑️ uninstall_service.bat - Complete removal script
|
||||
- 🌐 chrome_extension/ - Complete Chrome extension
|
||||
- 📚 Documentation files (QUICK_SETUP_NATIVE.md, INSTALLATION_GUIDE.md, README.md)
|
||||
|
||||
### Native Advantages:
|
||||
- 🚀 No Python dependencies - pure PowerShell
|
||||
- ⚡ Faster startup and lower memory usage
|
||||
- 🛡️ Enterprise-ready with Microsoft components only
|
||||
- 📦 Tiny footprint - minimal system impact
|
||||
|
||||
### Support:
|
||||
- 📖 Read QUICK_SETUP_NATIVE.md for 3-minute setup guide
|
||||
- 📋 Read INSTALLATION_GUIDE.md for complete documentation
|
||||
- 🛠️ Read README.md for technical details
|
||||
|
||||
### Service URLs:
|
||||
- Health Check: http://localhost:8765/health
|
||||
- Printer List: http://localhost:8765/printers
|
||||
- API Documentation: See README.md
|
||||
|
||||
### Troubleshooting:
|
||||
1. Service not starting? Run install_service.bat as Administrator
|
||||
2. Can't connect? Check Windows Firewall (port 8765)
|
||||
3. Chrome extension not working? Reload extension in chrome://extensions/
|
||||
|
||||
Installation takes ~5 minutes • Zero maintenance required
|
||||
"""
|
||||
zipf.writestr('INSTALLATION_README.txt', installation_readme)
|
||||
files_added += 1
|
||||
|
||||
print(f"Total service files added to ZIP: {files_added}")
|
||||
|
||||
# Verify ZIP was created
|
||||
if os.path.exists(zip_path):
|
||||
zip_size = os.path.getsize(zip_path)
|
||||
print(f"Service ZIP file created: {zip_path}, size: {zip_size} bytes")
|
||||
|
||||
if zip_size > 0:
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'download_url': f'/static/{zip_filename}',
|
||||
'files_included': files_added,
|
||||
'zip_size': zip_size
|
||||
})
|
||||
else:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': 'ZIP file was created but is empty'
|
||||
}), 500
|
||||
else:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': 'Failed to create service ZIP file'
|
||||
}), 500
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error creating service package: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': str(e)
|
||||
}), 500
|
||||
|
||||
@bp.route('/test_extension_files')
|
||||
def test_extension_files():
|
||||
"""Test route to check extension files"""
|
||||
|
||||
Reference in New Issue
Block a user