44import shutil
55import platform
66from PySide6 .QtWidgets import (
7- QApplication , QWidget , QVBoxLayout , QHBoxLayout , QLabel , QLineEdit , QPushButton , QFileDialog , QTextEdit , QCheckBox
7+ QApplication , QWidget , QVBoxLayout , QHBoxLayout , QLabel , QLineEdit , QPushButton , QFileDialog , QTextEdit , QCheckBox , QComboBox , QSpinBox
88)
99from PySide6 .QtCore import Qt , QThread , Signal
1010
@@ -26,12 +26,14 @@ class CloneThread(QThread):
2626 progress = Signal (str )
2727 finished = Signal (str )
2828
29- def __init__ (self , url , docker_name , save_path , build_docker ):
29+ def __init__ (self , url , docker_name , save_path , build_docker , size_cap = None , throttle = None ):
3030 super ().__init__ ()
3131 self .url = url
3232 self .docker_name = docker_name
3333 self .save_path = save_path
3434 self .build_docker = build_docker
35+ self .size_cap = size_cap
36+ self .throttle = throttle
3537
3638 def run (self ):
3739 log = []
@@ -62,9 +64,14 @@ def log_msg(msg):
6264 os .makedirs (temp_project_folder , exist_ok = True )
6365 # Clone website using wget
6466 log_msg (f'Cloning { self .url } to { temp_project_folder } ' )
67+ # Build wget command with options
6568 wget_cmd = [
6669 'wget' , '-e' , 'robots=off' , '--mirror' , '--convert-links' , '--adjust-extension' , '--page-requisites' , '--no-parent' , self .url , '-P' , temp_project_folder
6770 ]
71+ if self .size_cap :
72+ wget_cmd += ['--quota' , str (self .size_cap )]
73+ if self .throttle :
74+ wget_cmd += ['--limit-rate' , str (self .throttle )]
6875 try :
6976 result = subprocess .run (wget_cmd , capture_output = True , text = True )
7077 log_msg (result .stdout )
@@ -149,6 +156,40 @@ def __init__(self):
149156 self .build_checkbox = QCheckBox ('Build Docker image after clone (requires Docker)' )
150157 layout .addWidget (self .build_checkbox )
151158
159+ # Download size cap controls
160+ self .size_cap_checkbox = QCheckBox ('Limit download size' )
161+ layout .addWidget (self .size_cap_checkbox )
162+ size_hbox = QHBoxLayout ()
163+ self .size_cap_value = QSpinBox ()
164+ self .size_cap_value .setRange (1 , 1000000 )
165+ self .size_cap_value .setValue (100 )
166+ size_hbox .addWidget (self .size_cap_value )
167+ self .size_cap_unit = QComboBox ()
168+ self .size_cap_unit .addItems (['MB' , 'GB' , 'TB' ])
169+ size_hbox .addWidget (self .size_cap_unit )
170+ layout .addLayout (size_hbox )
171+ self .size_cap_checkbox .stateChanged .connect (lambda : self .size_cap_value .setEnabled (self .size_cap_checkbox .isChecked ()))
172+ self .size_cap_checkbox .stateChanged .connect (lambda : self .size_cap_unit .setEnabled (self .size_cap_checkbox .isChecked ()))
173+ self .size_cap_value .setEnabled (False )
174+ self .size_cap_unit .setEnabled (False )
175+
176+ # Download speed throttle controls
177+ self .throttle_checkbox = QCheckBox ('Throttle download speed' )
178+ layout .addWidget (self .throttle_checkbox )
179+ throttle_hbox = QHBoxLayout ()
180+ self .throttle_value = QSpinBox ()
181+ self .throttle_value .setRange (1 , 1000000 )
182+ self .throttle_value .setValue (1024 )
183+ throttle_hbox .addWidget (self .throttle_value )
184+ self .throttle_unit = QComboBox ()
185+ self .throttle_unit .addItems (['KB/s' , 'MB/s' ])
186+ throttle_hbox .addWidget (self .throttle_unit )
187+ layout .addLayout (throttle_hbox )
188+ self .throttle_checkbox .stateChanged .connect (lambda : self .throttle_value .setEnabled (self .throttle_checkbox .isChecked ()))
189+ self .throttle_checkbox .stateChanged .connect (lambda : self .throttle_unit .setEnabled (self .throttle_checkbox .isChecked ()))
190+ self .throttle_value .setEnabled (False )
191+ self .throttle_unit .setEnabled (False )
192+
152193 self .start_btn = QPushButton ('Clone Website & Prepare Docker Output' )
153194 self .start_btn .clicked .connect (self .start_clone )
154195 self .start_btn .setEnabled (False )
@@ -185,12 +226,24 @@ def start_clone(self):
185226 docker_name = self .docker_name_input .text ().strip ()
186227 save_path = self .save_path_display .text ().strip ()
187228 build_docker = self .build_checkbox .isChecked ()
229+ # New options
230+ size_cap = None
231+ if self .size_cap_checkbox .isChecked ():
232+ value = self .size_cap_value .value ()
233+ unit = self .size_cap_unit .currentText ()
234+ multiplier = {'MB' : 1024 * 1024 , 'GB' : 1024 * 1024 * 1024 , 'TB' : 1024 * 1024 * 1024 * 1024 }[unit ]
235+ size_cap = value * multiplier
236+ throttle = None
237+ if self .throttle_checkbox .isChecked ():
238+ value = self .throttle_value .value ()
239+ unit = self .throttle_unit .currentText ()
240+ throttle = value * (1024 if unit == 'KB/s' else 1024 * 1024 )
188241 # Prevent Docker build if Docker name is empty and build is checked
189242 if build_docker and not docker_name :
190243 self .console .append ('Docker image name is required to build the image.' )
191244 return
192245 self .console .clear ()
193- self .clone_thread = CloneThread (url , docker_name , save_path , build_docker )
246+ self .clone_thread = CloneThread (url , docker_name , save_path , build_docker , size_cap = size_cap , throttle = throttle )
194247 self .clone_thread .progress .connect (self .update_console )
195248 self .clone_thread .finished .connect (self .clone_finished )
196249 self .clone_thread .start ()
0 commit comments