-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_installation.py
More file actions
184 lines (151 loc) · 5.18 KB
/
verify_installation.py
File metadata and controls
184 lines (151 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env python3
"""
系统验证脚本
System Verification Script
验证项目是否正确设置并可以正常运行
"""
import sys
import os
from pathlib import Path
def print_header():
"""打印欢迎信息"""
print("\n" + "="*70)
print("🔒 Intelligent Watermark Protection System - Verification")
print("="*70 + "\n")
def check_python_version():
"""检查Python版本"""
print("[1/5] Checking Python version...")
version = sys.version_info
if version.major >= 3 and version.minor >= 8:
print(f" ✅ Python {version.major}.{version.minor}.{version.micro} (OK)\n")
return True
else:
print(f" ❌ Python {version.major}.{version.minor} (需要3.8+)\n")
return False
def check_dependencies():
"""检查依赖库"""
print("[2/5] Checking dependencies...")
required = {
'PIL': 'Pillow',
'cv2': 'opencv-python',
'numpy': 'numpy',
'scipy': 'scipy'
}
all_ok = True
for module, package in required.items():
try:
__import__(module)
print(f" ✅ {package}")
except ImportError:
print(f" ❌ {package} - Install with: pip install -r requirements.txt")
all_ok = False
print()
return all_ok
def check_project_structure():
"""检查项目结构"""
print("[3/5] Checking project structure...")
required_files = [
'README.md',
'requirements.txt',
'protect_image.py',
'quick_start.py',
'tests.py',
'watermark_protection/__init__.py',
'watermark_protection/main.py',
'watermark_protection/visible_watermark.py',
'watermark_protection/adversarial_protection.py',
'watermark_protection/invisible_watermark.py',
]
all_ok = True
for file in required_files:
if Path(file).exists():
print(f" ✅ {file}")
else:
print(f" ❌ {file} - NOT FOUND")
all_ok = False
print()
return all_ok
def test_imports():
"""测试导入"""
print("[4/5] Testing imports...")
try:
from watermark_protection import WatermarkProtectionSystem
print(" ✅ WatermarkProtectionSystem")
from watermark_protection import StructuredWatermarkGenerator
print(" ✅ StructuredWatermarkGenerator")
from watermark_protection import AdversarialPerturbationInjector
print(" ✅ AdversarialPerturbationInjector")
from watermark_protection import InvisibleWatermarkEncoder, InvisibleWatermarkDecoder
print(" ✅ InvisibleWatermarkEncoder/Decoder")
print()
return True
except Exception as e:
print(f" ❌ Import error: {e}\n")
return False
def check_permissions():
"""检查权限"""
print("[5/5] Checking permissions...")
# 检查是否可以创建目录
try:
test_dir = Path('.test_dir')
test_dir.mkdir(exist_ok=True)
test_dir.rmdir()
print(" ✅ Can create directories")
except Exception as e:
print(f" ❌ Cannot create directories: {e}")
return False
# 检查是否可以写文件
try:
test_file = Path('.test_file')
test_file.write_text('test')
test_file.unlink()
print(" ✅ Can write files")
except Exception as e:
print(f" ❌ Cannot write files: {e}")
return False
print()
return True
def print_summary(results):
"""打印总结"""
print("="*70)
print("Verification Summary")
print("="*70)
checks = [
('Python Version', results[0]),
('Dependencies', results[1]),
('Project Structure', results[2]),
('Module Imports', results[3]),
('File Permissions', results[4])
]
all_passed = all(results)
for check_name, passed in checks:
status = "✅ PASS" if passed else "❌ FAIL"
print(f"{check_name:<25} {status}")
print("="*70)
if all_passed:
print("\n✅ All checks passed! System is ready to use.\n")
print("Next steps:")
print(" 1. Run demo: python quick_start.py")
print(" 2. Protect image: python protect_image.py protect --image photo.jpg --logo logo.png")
print(" 3. Read documentation: README.md\n")
return 0
else:
print("\n❌ Some checks failed. Please fix the issues above.\n")
print("Common fixes:")
print(" • Install dependencies: pip install -r requirements.txt")
print(" • Check Python version: python --version (need 3.8+)")
print(" • Check file permissions and disk space\n")
return 1
def main():
"""主程序"""
print_header()
results = [
check_python_version(),
check_dependencies(),
check_project_structure(),
test_imports(),
check_permissions()
]
return print_summary(results)
if __name__ == '__main__':
sys.exit(main())